Merge pull request #38 from IT2810-H26/dev #21
This file contains hidden or 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: | |
| push: | |
| branches: [dev, main] | |
| pull_request: | |
| branches: [dev, main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| # la main bli ferdig, også hvis vi må rulle tilbake | |
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| quality: | |
| name: Quality checks | |
| runs-on: [self-hosted, linux, x64, t31-ci] | |
| timeout-minutes: 30 | |
| env: | |
| CI: 'true' | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: .node-version | |
| - name: Use the pinned npm version | |
| run: npm install --global npm@11.11.1 | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Check code, contracts, migration metadata, tests and builds | |
| run: npm run check | |
| - name: Test release switching and rollback | |
| run: bash scripts/test-deploy-project1.sh | |
| - name: Install test browsers | |
| run: npm run test:e2e:install | |
| - name: Run browser checks | |
| run: npm run test:e2e -- --workers=2 | |
| - name: Preserve browser failure evidence | |
| if: failure() | |
| # denne node20-versjonen finnes på git.ntnu.no og støtter enterprise | |
| uses: actions/upload-artifact@v3.2.1-node20 | |
| with: | |
| name: browser-results-${{ github.run_id }}-${{ github.run_attempt }} | |
| path: test-results/ | |
| retention-days: 7 | |
| - name: Save the tested production build | |
| if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' | |
| uses: actions/upload-artifact@v3.2.1-node20 | |
| with: | |
| name: project1-${{ github.sha }}-${{ github.run_attempt }} | |
| path: web/dist/ | |
| if-no-files-found: error | |
| retention-days: 7 | |
| deploy: | |
| name: Deploy Project 1 | |
| needs: quality | |
| if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' | |
| runs-on: [self-hosted, linux, x64, t31-deploy] | |
| timeout-minutes: 10 | |
| environment: | |
| name: production | |
| url: http://it2810-31.idi.ntnu.no/project1/ | |
| concurrency: | |
| group: project1-production | |
| cancel-in-progress: false | |
| steps: | |
| - name: Check that this commit is still the tip of main | |
| id: latest | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data } = await github.rest.repos.getCommit({ | |
| ...context.repo, | |
| ref: 'main', | |
| }); | |
| core.setOutput('current', data.sha === context.sha); | |
| if (data.sha !== context.sha) { | |
| core.notice('A newer commit is on main; skip this outdated deployment.'); | |
| } | |
| - name: Check out the deployment script from the tested commit | |
| if: steps.latest.outputs.current == 'true' | |
| uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - name: Download the tested production build | |
| if: steps.latest.outputs.current == 'true' | |
| uses: actions/download-artifact@v3-node20 | |
| with: | |
| name: project1-${{ github.sha }}-${{ github.run_attempt }} | |
| path: web/dist/ | |
| - name: Publish to Apache and verify the release | |
| if: steps.latest.outputs.current == 'true' | |
| env: | |
| RELEASE_ID: ${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt }} | |
| run: bash scripts/deploy-project1.sh web/dist "$RELEASE_ID" |