|
| 1 | +name: PR matrix (on demand) |
| 2 | + |
| 3 | +# Manually triggered by commenting one of these slash commands on an |
| 4 | +# open PR: |
| 5 | +# /run-all-jdks |
| 6 | +# /jdk-matrix |
| 7 | +# /test-all |
| 8 | +# Runs the forward-compat matrix (JDK 21, 25) — JDK 17 already runs |
| 9 | +# automatically on every PR open/sync via pull-request.yml. |
| 10 | +# |
| 11 | +# Important security note: workflows triggered by `issue_comment` always |
| 12 | +# run from the *default branch's* version of the workflow file, not from |
| 13 | +# the PR. So adding/changing this file on a feature branch has no effect |
| 14 | +# until it lands on main. |
| 15 | +on: |
| 16 | + issue_comment: |
| 17 | + types: [created] |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + pull-requests: write # to react to the trigger comment |
| 22 | + |
| 23 | +# Multiple "run all versions" comments on the same PR cancel earlier runs. |
| 24 | +concurrency: |
| 25 | + group: pr-on-demand-${{ github.event.issue.number }} |
| 26 | + cancel-in-progress: true |
| 27 | + |
| 28 | +jobs: |
| 29 | + guard: |
| 30 | + name: Guard |
| 31 | + runs-on: ubuntu-latest |
| 32 | + # Only fire on PR comments (not generic issue comments) that contain |
| 33 | + # one of the three accepted slash commands. `contains` is substring |
| 34 | + # match — false positives are possible but unlikely in practice given |
| 35 | + # the leading slash and hyphen-rich shape of these tokens. |
| 36 | + if: | |
| 37 | + github.event.issue.pull_request != null && ( |
| 38 | + contains(github.event.comment.body, '/run-all-jdks') || |
| 39 | + contains(github.event.comment.body, '/jdk-matrix') || |
| 40 | + contains(github.event.comment.body, '/test-all') |
| 41 | + ) |
| 42 | + outputs: |
| 43 | + head_sha: ${{ steps.pr.outputs.head_sha }} |
| 44 | + steps: |
| 45 | + # Reject comments from anyone without write access. Otherwise an |
| 46 | + # external user commenting on a fork PR could burn our CI minutes |
| 47 | + # and potentially exfiltrate secrets via a malicious build. |
| 48 | + - name: Verify commenter has write permission |
| 49 | + uses: actions/github-script@v7 |
| 50 | + with: |
| 51 | + script: | |
| 52 | + const { data: perm } = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 53 | + owner: context.repo.owner, |
| 54 | + repo: context.repo.repo, |
| 55 | + username: context.payload.comment.user.login, |
| 56 | + }); |
| 57 | + const allowed = ['write', 'maintain', 'admin'].includes(perm.permission); |
| 58 | + if (!allowed) { |
| 59 | + core.setFailed( |
| 60 | + `@${context.payload.comment.user.login} (${perm.permission}) ` + |
| 61 | + `cannot trigger CI; write access required.` |
| 62 | + ); |
| 63 | + } |
| 64 | +
|
| 65 | + # Visible feedback to the commenter that we picked up the trigger. |
| 66 | + - name: React 👀 to the trigger comment |
| 67 | + uses: actions/github-script@v7 |
| 68 | + with: |
| 69 | + script: | |
| 70 | + await github.rest.reactions.createForIssueComment({ |
| 71 | + owner: context.repo.owner, |
| 72 | + repo: context.repo.repo, |
| 73 | + comment_id: context.payload.comment.id, |
| 74 | + content: 'eyes', |
| 75 | + }); |
| 76 | +
|
| 77 | + # The issue_comment event payload doesn't include the PR's head SHA, |
| 78 | + # so look it up via the pulls API. We also confirm the PR is open; |
| 79 | + # firing on closed PRs is almost always a mistake. |
| 80 | + - name: Resolve PR head SHA |
| 81 | + id: pr |
| 82 | + uses: actions/github-script@v7 |
| 83 | + with: |
| 84 | + script: | |
| 85 | + const { data: pr } = await github.rest.pulls.get({ |
| 86 | + owner: context.repo.owner, |
| 87 | + repo: context.repo.repo, |
| 88 | + pull_number: context.payload.issue.number, |
| 89 | + }); |
| 90 | + if (pr.state !== 'open') { |
| 91 | + core.setFailed(`PR #${pr.number} is ${pr.state}; refusing to run.`); |
| 92 | + return; |
| 93 | + } |
| 94 | + core.setOutput('head_sha', pr.head.sha); |
| 95 | +
|
| 96 | + verify: |
| 97 | + name: Verify (JDK ${{ matrix.java }}) |
| 98 | + needs: guard |
| 99 | + runs-on: ubuntu-latest |
| 100 | + strategy: |
| 101 | + # If JDK 21 fails, we still want to know whether 25 passes. |
| 102 | + fail-fast: false |
| 103 | + matrix: |
| 104 | + java: ['21', '25'] |
| 105 | + |
| 106 | + steps: |
| 107 | + # Check out exactly the PR's HEAD commit, not the merge ref. |
| 108 | + - name: Checkout PR head |
| 109 | + uses: actions/checkout@v4 |
| 110 | + with: |
| 111 | + ref: ${{ needs.guard.outputs.head_sha }} |
| 112 | + |
| 113 | + # Compile=17, test=matrix JDK; same shape as main.yml. |
| 114 | + - name: Set up JDKs (compile=17, test=${{ matrix.java }}) |
| 115 | + uses: actions/setup-java@v4 |
| 116 | + with: |
| 117 | + distribution: temurin |
| 118 | + java-version: | |
| 119 | + 17 |
| 120 | + ${{ matrix.java }} |
| 121 | +
|
| 122 | + - name: Set up Gradle |
| 123 | + uses: gradle/actions/setup-gradle@v4 |
| 124 | + |
| 125 | + - name: Test on JDK ${{ matrix.java }} |
| 126 | + run: ./gradlew test -PtestJdk=${{ matrix.java }} --stacktrace |
| 127 | + |
| 128 | + - name: Upload test reports on failure |
| 129 | + if: failure() |
| 130 | + uses: actions/upload-artifact@v4 |
| 131 | + with: |
| 132 | + name: test-reports-jdk${{ matrix.java }} |
| 133 | + path: | |
| 134 | + build/reports/tests/ |
| 135 | + build/test-results/ |
| 136 | + retention-days: 14 |
| 137 | + |
| 138 | + # Post a single comment summarizing the on-demand matrix result so it's |
| 139 | + # visible on the PR without diving into the Actions tab. |
| 140 | + report: |
| 141 | + name: Report |
| 142 | + needs: verify |
| 143 | + if: always() && needs.guard.result == 'success' |
| 144 | + runs-on: ubuntu-latest |
| 145 | + steps: |
| 146 | + - name: Comment outcome |
| 147 | + uses: actions/github-script@v7 |
| 148 | + with: |
| 149 | + script: | |
| 150 | + const ok = '${{ needs.verify.result }}' === 'success'; |
| 151 | + const emoji = ok ? '✅' : '❌'; |
| 152 | + const status = ok ? 'passed' : 'failed'; |
| 153 | + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; |
| 154 | + await github.rest.issues.createComment({ |
| 155 | + owner: context.repo.owner, |
| 156 | + repo: context.repo.repo, |
| 157 | + issue_number: context.payload.issue.number, |
| 158 | + body: `${emoji} On-demand JDK matrix \`{21, 25}\` ${status}. [View run](${runUrl}).`, |
| 159 | + }); |
0 commit comments