Refactor CI workflow to use common action #30
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
| # Regular workflow | |
| name: 'CI' | |
| on: | |
| push: | |
| branches-ignore: | |
| - gh-pages | |
| paths-ignore: | |
| - '*.md' | |
| - '.github/workflows/release-ci.yml' | |
| - '.github/workflows/codeql-analysis.yml' | |
| - '.github/workflows/dependabot.yml' | |
| pull_request: | |
| branches-ignore: | |
| - gh-pages | |
| paths-ignore: | |
| - '*.md' | |
| - '.github/workflows/release-ci.yml' | |
| - '.github/workflows/codeql-analysis.yml' | |
| - '.github/workflows/dependabot.yml' | |
| workflow_dispatch: {} | |
| # Avoid overlapping runs and cancel in-progress runs on newer commits | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| # Reduce default permissions for security | |
| permissions: | |
| contents: write | |
| jobs: | |
| # Build (produce production artifacts) | |
| build: | |
| runs-on: ubuntu-22.04 | |
| needs: [] | |
| strategy: | |
| matrix: | |
| node-version: [22.x] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: ./.github/actions/common-setup | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Build | |
| run: npm run build | |
| working-directory: react | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: react-build | |
| path: ./react/build/ | |
| # Lint & Audit | |
| audit_lint: | |
| runs-on: ubuntu-22.04 | |
| needs: [build] | |
| strategy: | |
| matrix: | |
| node-version: [22.x] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: ./.github/actions/common-setup | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Audit | |
| run: npm run audit | |
| working-directory: react | |
| - name: ESLint | |
| run: npm run lint | |
| working-directory: react | |
| # Unit tests + coverage | |
| unit_tests: | |
| runs-on: ubuntu-22.04 | |
| needs: [build] | |
| strategy: | |
| matrix: | |
| node-version: [22.x] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: ./.github/actions/common-setup | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Run unit tests with coverage | |
| run: npm run test:CI | |
| working-directory: react | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| file: ./react/reports/coverage/coverage-final.json | |
| - name: Upload coverage reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: reports-coverage | |
| path: ./react/reports/coverage/ | |
| # Duplication analysis | |
| duplication: | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-22.04 | |
| needs: [build] | |
| strategy: | |
| matrix: | |
| node-version: [22.x] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: ./.github/actions/common-setup | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Run duplication analysis | |
| run: npm run duplication | |
| working-directory: react | |
| - name: Upload duplication HTML report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: reports-duplication | |
| path: ./react/reports/duplication/html/ | |
| # Playwright E2E | |
| e2e: | |
| runs-on: ubuntu-22.04 | |
| needs: [unit_tests] | |
| strategy: | |
| matrix: | |
| node-version: [22.x] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: react-build | |
| path: ./react/build | |
| - uses: ./.github/actions/common-setup | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Install Playwright | |
| run: npx playwright install --with-deps | |
| working-directory: react | |
| - name: Run Playwright tests | |
| run: npx playwright test | |
| working-directory: react | |
| - name: Upload playwright reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: reports-playwright | |
| path: ./react/reports/playwright/ | |
| # Mutation testing | |
| stryker: | |
| if: "github.ref == 'refs/heads/main'" | |
| runs-on: ubuntu-22.04 | |
| needs: [unit_tests] | |
| strategy: | |
| matrix: | |
| node-version: [22.x] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: ./.github/actions/common-setup | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Run Stryker tests | |
| run: npx stryker run | |
| working-directory: react | |
| - name: Upload mutation reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: reports-mutation | |
| path: ./react/reports/mutation/ | |
| # Deploy reports to GitHub Pages under /reports/ | |
| deploy_reports: | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-22.04 | |
| needs: [stryker, e2e, unit_tests, duplication] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Switch to gh-pages branch | |
| run: | | |
| git fetch origin gh-pages | |
| git checkout gh-pages || git checkout --orphan gh-pages | |
| - name: Download coverage reports | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: reports-coverage | |
| path: reports/coverage | |
| - name: Download mutation reports | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: reports-mutation | |
| path: reports/mutation | |
| - name: Download playwright reports | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: reports-playwright | |
| path: reports/playwright | |
| - name: Download duplication report | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: reports-duplication | |
| path: reports/duplication | |
| - name: Commit and push reports | |
| run: | | |
| git config --global user.name "${GITHUB_ACTOR}" | |
| git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
| git add reports/ | |
| git commit -m "Update reports" || echo "No changes to commit" | |
| git push origin gh-pages | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |