Mutation Tests #13
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
| # Mutation workflow | |
| name: 'Mutation Tests' | |
| on: | |
| schedule: | |
| - cron: '0 0 * * 0' | |
| # 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: | |
| # Check for code changes since last successful run | |
| check_changes: | |
| runs-on: ubuntu-22.04 | |
| outputs: | |
| code_changed: ${{ steps.set_changed.outputs.code_changed }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get last successful workflow run commit SHA | |
| id: last_success | |
| run: | | |
| echo "sha=$(gh run list --workflow mutation.yml --branch main --status success --limit 1 --json headSha -q '.[0].headSha')" >> $GITHUB_OUTPUT | |
| - name: Check for code changes | |
| id: set_changed | |
| run: | | |
| if [ -z "${{ steps.last_success.outputs.sha }}" ]; then | |
| echo "No previous successful run found. Assuming code changed." | |
| echo "code_changed=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| git fetch origin main | |
| CHANGED_FILES=$(git diff --name-only ${{ steps.last_success.outputs.sha }} HEAD -- react/src) | |
| if [ -z "$CHANGED_FILES" ]; then | |
| echo "No code changes since last successful run." | |
| echo "code_changed=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Code changes detected." | |
| echo "code_changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| # Mutation testing | |
| stryker: | |
| if: github.ref == 'refs/heads/main' && needs.check_changes.outputs.code_changed == 'true' | |
| runs-on: ubuntu-22.04 | |
| needs: [check_changes] | |
| 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] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: gh-pages | |
| - name: Download mutation reports | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: reports-mutation | |
| path: reports/mutation | |
| - name: Commit and push reports | |
| run: | | |
| git config --global user.name "${GITHUB_ACTOR}" | |
| git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
| touch .nojekyll | |
| git add .nojekyll reports/ | |
| git commit -m "Update reports" || echo "No changes to commit" | |
| git status | |
| git push origin gh-pages | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |