CI #3628
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
pull_request: | |
branches: | |
- master | |
push: | |
branches: | |
- master | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
build-desktop: | |
name: Build desktop application and docs | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
java: [17] | |
steps: | |
# Set up Java development environment. | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ matrix.java }} | |
distribution: 'microsoft' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
# Read the application version to use it in the name of the JAR. | |
- name: Read version from gradle.properties | |
id: read_version | |
uses: christian-draeger/[email protected] | |
with: | |
path: 'gradle.properties' | |
properties: 'version' | |
# Compile the code, run unit tests, upload code coverage results. | |
- name: Compile Java code | |
run: ./gradlew compileJava | |
- name: Run unit tests | |
run: ./gradlew check | |
- name: Codecov | |
uses: codecov/[email protected] | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
# Build docs (PDF and HTML for the in-app help) | |
# The Python dependencies are fetched by Gradle. | |
- name: Build all docs | |
run: ./gradlew allDocs | |
# Build JAR file. | |
- name: Build JAR | |
run: ./gradlew jar | |
# Upload artifacts (manuals and JARs) | |
- name: Upload English Manual PDF | |
uses: actions/[email protected] | |
with: | |
name: English manual (PDF) | |
path: ./build/docs/en/pdf/EduMIPS64.pdf | |
- name: Upload Italian Manual PDF | |
uses: actions/[email protected] | |
with: | |
name: Italian manual (PDF) | |
path: ./build/docs/it/pdf/EduMIPS64.pdf | |
# | |
# Disabled due to not working properly | |
# | |
# - name: Upload Simplified Chinese Manual PDF | |
# uses: actions/[email protected] | |
# with: | |
# name: Chinese manual (PDF) | |
# path: ./build/docs/zh/pdf/EduMIPS64.pdf | |
- name: Upload JAR | |
uses: actions/[email protected] | |
with: | |
name: JAR | |
path: ./build/libs/edumips64-${{ steps.read_version.outputs.version }}.jar | |
build-msi: | |
name: Build Windows MSI | |
runs-on: windows-latest | |
needs: build-desktop | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Wix | |
uses: actions/checkout@v4 | |
with: | |
repository: fbarresi/wix | |
path: wix | |
- name: Download JAR | |
uses: actions/[email protected] | |
with: | |
name: JAR | |
path: build/libs | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: 'microsoft' | |
- name: Build MSI | |
run: ./gradlew MSI | |
- name: Upload MSI | |
uses: actions/[email protected] | |
with: | |
name: MSI | |
path: EduMIPS64-*.msi | |
build-web: | |
name: Build web application | |
runs-on: ubuntu-latest | |
steps: | |
# Set up JDK (necessary for the core that is cross-compiled to JS) | |
# and Node.JS (for the) web app itself. | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: 'microsoft' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build JS Worker (Java → JS) | |
run: ./gradlew war | |
- name: Set up Node.JS | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
- name: Install JS dependencies | |
run: npm install | |
# Build JS application and upload artifacts for subsequent steps. | |
- name: Build JS application | |
run: npm run build | |
- uses: actions/upload-artifact@v4 | |
name: Upload web application artifacts | |
with: | |
name: web | |
path: build/gwt/war/edumips64 | |
deploy-web: | |
name: Deploy web application | |
permissions: write-all | |
runs-on: ubuntu-latest | |
needs: build-web | |
steps: | |
# This step behaves differently in PRs and on push to master / cron. | |
# Set up environment variables according to the triggering event. | |
- name: Set PR environment variables | |
if: ${{ github.event_name == 'pull_request' }} | |
run: | | |
echo "DEPLOYMENT_ENV=${{github.event.pull_request.number}}" >> $GITHUB_ENV | |
echo "PUSH_DIR=pr/" >> $GITHUB_ENV | |
echo "COMMIT_MESSAGE=Deploy code for PR ${{ github.event.pull_request.number }}" >> $GITHUB_ENV | |
echo "DEPLOYMENT_ENV_URL=https://edumips64ci.z16.web.core.windows.net/${{github.event.pull_request.number}}/" >> $GITHUB_ENV | |
- name: Set master push environment variables | |
if: ${{ github.event_name != 'pull_request' }} | |
run: | | |
echo "DEPLOYMENT_ENV=prod" >> $GITHUB_ENV | |
echo "PUSH_DIR=build/gwt/war/edumips64" >> $GITHUB_ENV | |
echo "COMMIT_MESSAGE=Update Web Frontend @ ${{ github.sha }}" >> $GITHUB_ENV | |
echo "DEPLOYMENT_ENV_URL=https://web.edumips.org" >> $GITHUB_ENV | |
# Download web application built in 'build-web' | |
- uses: actions/[email protected] | |
name: Download web application artifacts | |
with: | |
name: web | |
path: build/gwt/war/edumips64 | |
# Mark the deployment as started (allows the PR to display "Deployment started" messages.) | |
- name: Start deployment | |
uses: bobheadxi/[email protected] | |
id: deployment | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: ${{ env.DEPLOYMENT_ENV }} | |
ref: ${{ github.head_ref }} | |
# Deploy the code on Github Pages. | |
# Copy files to a directory to allow pushing to a subdir in the web.edumips.org repo. | |
- name: Copy files to run directory | |
run: mkdir -p pr/${{ github.event.pull_request.number }} && cp -r build/gwt/war/edumips64/* pr/${{ github.event.pull_request.number }} | |
if: ${{ github.event_name == 'pull_request' }} | |
# Upload to Azure blob if this is a PR. | |
- name: Login to Azure | |
uses: azure/login@v2 | |
if: ${{ github.event_name == 'pull_request' }} | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Upload to Azure blob storage (${{ env.DEPLOYMENT_ENV_URL }}) | |
uses: azure/CLI@v2 | |
if: ${{ github.event_name == 'pull_request' }} | |
with: | |
inlineScript: | | |
az storage blob upload-batch --account-name edumips64ci --auth-mode key -d '$web/${{ github.event.pull_request.number }}' -s pr/${{ github.event.pull_request.number }} --overwrite | |
- name: Deploy master web application to web.edumips.org | |
if: ${{ success() && github.event_name != 'pull_request' }} | |
uses: crazy-max/ghaction-github-pages@v4 | |
with: | |
target_branch: master | |
build_dir: ${{ env.PUSH_DIR }} | |
repo: EduMIPS64/web.edumips.org | |
keep_history: true | |
commit_message: ${{ env.COMMIT_MESSAGE }} | |
fqdn: web.edumips.org | |
env: | |
GH_PAT: ${{ secrets.PAT_WEBUI }} | |
# Mark the deployment as succeeded or failed. | |
- name: Update deployment status | |
uses: bobheadxi/[email protected] | |
if: always() && github.head_ref | |
with: | |
step: finish | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
env_url: ${{ env.DEPLOYMENT_ENV_URL }} | |
env: ${{ env.DEPLOYMENT_ENV }} | |
# Test the deployed web application. | |
# This is only ran on pull request because runs triggered by push and schedule | |
# will deploy to web.edumips.org. Given that the deployment has some latency, | |
# the test will most likely run against the previously-deployed version, | |
# potentially giving a false sense of security if a developer sees the test being | |
# run immediately after the deployment. | |
# | |
# There is a separate job that periodically monitors web.edumips.org, which will | |
# catch regressions. | |
test-web: | |
name: Test web application | |
runs-on: ubuntu-latest | |
needs: deploy-web | |
if: ${{ github.event_name == 'pull_request' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Node.JS | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
- name: Install JS dependencies | |
run: npm install | |
- name: Install Playwright dependencies | |
run: npx playwright install | |
# Run tests against the deployed code. | |
- name: Run web tests against deployed code | |
uses: nick-fields/retry@v3 | |
env: | |
PLAYWRIGHT_TARGET_URL: https://edumips64ci.z16.web.core.windows.net/${{github.event.pull_request.number}}/ | |
with: | |
max_attempts: 10 | |
timeout_minutes: 2 | |
retry_on: error | |
command: npm run test | |
build-snap: | |
name: Build Snapcraft package | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: snapcore/action-build@v1 | |
id: snapcraft | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: snap | |
path: ${{ steps.snapcraft.outputs.snap }} | |
test-snap: | |
name: Test Snapcraft package | |
runs-on: ubuntu-latest | |
needs: build-snap | |
steps: | |
- uses: actions/[email protected] | |
name: Download snap package | |
with: | |
name: snap | |
path: . | |
- name: Unpack and install snap | |
run: | | |
unsquashfs edumips64*.snap | |
sudo snap try squashfs-root/ | |
echo "exit" | edumips64.edumips64-cli | |