|
| 1 | +name: PIT Mutation Testing |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 4 * * 1' # Weekly Monday 4am UTC |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + issues: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + mutation-test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + timeout-minutes: 120 |
| 15 | + |
| 16 | + name: PIT Mutation Testing |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Java |
| 22 | + uses: actions/setup-java@v4 |
| 23 | + with: |
| 24 | + java-version: '17' |
| 25 | + distribution: 'temurin' |
| 26 | + |
| 27 | + - name: Create plugin dirs |
| 28 | + run: | |
| 29 | + mkdir -p ~/vstar_plugins |
| 30 | + mkdir -p ~/vstar_plugin_libs |
| 31 | +
|
| 32 | + - name: Run PIT mutation testing |
| 33 | + id: pit-run |
| 34 | + run: ant -noinput -buildfile build.xml pit |
| 35 | + |
| 36 | + - name: Extract mutation score |
| 37 | + if: always() |
| 38 | + id: pit-score |
| 39 | + run: | |
| 40 | + XML=$(find mutation_coverage -name 'mutations.xml' -print -quit 2>/dev/null) |
| 41 | + if [ -z "$XML" ]; then |
| 42 | + echo "score=N/A" >> "$GITHUB_OUTPUT" |
| 43 | + echo "total=0" >> "$GITHUB_OUTPUT" |
| 44 | + echo "killed=0" >> "$GITHUB_OUTPUT" |
| 45 | + echo "survived=0" >> "$GITHUB_OUTPUT" |
| 46 | + echo "no_coverage=0" >> "$GITHUB_OUTPUT" |
| 47 | + else |
| 48 | + TOTAL=$(grep -c '<mutation ' "$XML" || true) |
| 49 | + KILLED=$(grep -c "status='KILLED'" "$XML" || true) |
| 50 | + SURVIVED=$(grep -c "status='SURVIVED'" "$XML" || true) |
| 51 | + NO_COV=$(grep -c "status='NO_COVERAGE'" "$XML" || true) |
| 52 | + if [ "$TOTAL" -gt 0 ] 2>/dev/null; then |
| 53 | + SCORE=$((KILLED * 100 / TOTAL)) |
| 54 | + else |
| 55 | + SCORE=0 |
| 56 | + fi |
| 57 | + echo "score=${SCORE}%" >> "$GITHUB_OUTPUT" |
| 58 | + echo "total=$TOTAL" >> "$GITHUB_OUTPUT" |
| 59 | + echo "killed=$KILLED" >> "$GITHUB_OUTPUT" |
| 60 | + echo "survived=$SURVIVED" >> "$GITHUB_OUTPUT" |
| 61 | + echo "no_coverage=$NO_COV" >> "$GITHUB_OUTPUT" |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Post mutation summary |
| 65 | + if: always() && steps.pit-score.outputs.score != 'N/A' |
| 66 | + run: | |
| 67 | + cat >> "$GITHUB_STEP_SUMMARY" <<EOF |
| 68 | + ## PIT Mutation Testing Results |
| 69 | +
|
| 70 | + | Metric | Value | |
| 71 | + |--------|-------| |
| 72 | + | **Mutation Score** | **${{ steps.pit-score.outputs.score }}** | |
| 73 | + | Total Mutants | ${{ steps.pit-score.outputs.total }} | |
| 74 | + | Killed | ${{ steps.pit-score.outputs.killed }} | |
| 75 | + | Survived | ${{ steps.pit-score.outputs.survived }} | |
| 76 | + | No Coverage | ${{ steps.pit-score.outputs.no_coverage }} | |
| 77 | + EOF |
| 78 | +
|
| 79 | + - name: Upload mutation report |
| 80 | + if: always() |
| 81 | + uses: actions/upload-artifact@v4 |
| 82 | + with: |
| 83 | + name: pit-mutation-report |
| 84 | + path: mutation_coverage/ |
| 85 | + |
| 86 | + - name: Open issue on failure |
| 87 | + if: always() && steps.pit-run.outcome == 'failure' |
| 88 | + uses: actions/github-script@v7 |
| 89 | + with: |
| 90 | + script: | |
| 91 | + const label = 'pit-mutation-testing'; |
| 92 | + const title = 'PIT Mutation Testing: Scheduled Run Failed'; |
| 93 | + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; |
| 94 | + const date = new Date().toISOString().slice(0, 10); |
| 95 | +
|
| 96 | + try { |
| 97 | + await github.rest.issues.getLabel({ |
| 98 | + owner: context.repo.owner, |
| 99 | + repo: context.repo.repo, |
| 100 | + name: label, |
| 101 | + }); |
| 102 | + } catch { |
| 103 | + await github.rest.issues.createLabel({ |
| 104 | + owner: context.repo.owner, |
| 105 | + repo: context.repo.repo, |
| 106 | + name: label, |
| 107 | + color: 'e11d48', |
| 108 | + description: 'Automated PIT mutation testing reports', |
| 109 | + }); |
| 110 | + } |
| 111 | +
|
| 112 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 113 | + owner: context.repo.owner, |
| 114 | + repo: context.repo.repo, |
| 115 | + labels: label, |
| 116 | + state: 'open', |
| 117 | + }); |
| 118 | +
|
| 119 | + if (issues.length > 0) { |
| 120 | + await github.rest.issues.createComment({ |
| 121 | + owner: context.repo.owner, |
| 122 | + repo: context.repo.repo, |
| 123 | + issue_number: issues[0].number, |
| 124 | + body: `Failed again on ${date}.\n\n**Run:** ${runUrl}`, |
| 125 | + }); |
| 126 | + } else { |
| 127 | + await github.rest.issues.create({ |
| 128 | + owner: context.repo.owner, |
| 129 | + repo: context.repo.repo, |
| 130 | + title: title, |
| 131 | + body: [ |
| 132 | + `The scheduled PIT mutation testing run failed on ${date}.`, |
| 133 | + '', |
| 134 | + `**Run:** ${runUrl}`, |
| 135 | + '', |
| 136 | + 'Please investigate the failure. This issue will be closed automatically', |
| 137 | + 'when the next scheduled run succeeds.', |
| 138 | + ].join('\n'), |
| 139 | + labels: [label], |
| 140 | + }); |
| 141 | + } |
| 142 | +
|
| 143 | + - name: Close failure issue on success |
| 144 | + if: always() && steps.pit-run.outcome == 'success' |
| 145 | + uses: actions/github-script@v7 |
| 146 | + with: |
| 147 | + script: | |
| 148 | + const label = 'pit-mutation-testing'; |
| 149 | + const score = '${{ steps.pit-score.outputs.score }}'; |
| 150 | + const date = new Date().toISOString().slice(0, 10); |
| 151 | +
|
| 152 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 153 | + owner: context.repo.owner, |
| 154 | + repo: context.repo.repo, |
| 155 | + labels: label, |
| 156 | + state: 'open', |
| 157 | + }); |
| 158 | +
|
| 159 | + for (const issue of issues) { |
| 160 | + await github.rest.issues.createComment({ |
| 161 | + owner: context.repo.owner, |
| 162 | + repo: context.repo.repo, |
| 163 | + issue_number: issue.number, |
| 164 | + body: `Resolved. Run on ${date} completed successfully with a mutation score of **${score}**.`, |
| 165 | + }); |
| 166 | + await github.rest.issues.update({ |
| 167 | + owner: context.repo.owner, |
| 168 | + repo: context.repo.repo, |
| 169 | + issue_number: issue.number, |
| 170 | + state: 'closed', |
| 171 | + state_reason: 'completed', |
| 172 | + }); |
| 173 | + } |
0 commit comments