|
| 1 | +name: Retest PR |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +env: |
| 8 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true |
| 9 | + |
| 10 | +jobs: |
| 11 | + retest: |
| 12 | + if: github.event.issue.pull_request && contains(github.event.comment.body, 'retest') |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + actions: write |
| 16 | + issues: write |
| 17 | + pull-requests: read |
| 18 | + steps: |
| 19 | + - name: Check authorization and trigger phrase |
| 20 | + uses: actions/github-script@v7 |
| 21 | + with: |
| 22 | + script: | |
| 23 | + const assoc = context.payload.comment.author_association; |
| 24 | + if (!['OWNER', 'MEMBER', 'COLLABORATOR'].includes(assoc)) { |
| 25 | + core.setFailed('Not authorized (association: ' + assoc + ')'); |
| 26 | + return; |
| 27 | + } |
| 28 | + const body = context.payload.comment.body; |
| 29 | + if (!body.includes('/retest') && |
| 30 | + !body.includes('[CI: retest]') && |
| 31 | + !body.includes('[ci: retest]')) { |
| 32 | + core.setFailed('No recognized retest trigger found.'); |
| 33 | + } |
| 34 | +
|
| 35 | + - name: Get PR head SHA |
| 36 | + id: pr |
| 37 | + uses: actions/github-script@v7 |
| 38 | + with: |
| 39 | + script: | |
| 40 | + const pr = (await github.rest.pulls.get({ |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo, |
| 43 | + pull_number: context.issue.number, |
| 44 | + })).data; |
| 45 | + core.setOutput('sha', pr.head.sha); |
| 46 | +
|
| 47 | + - name: Re-run CI |
| 48 | + uses: actions/github-script@v7 |
| 49 | + with: |
| 50 | + script: | |
| 51 | + const runs = await github.rest.actions.listWorkflowRuns({ |
| 52 | + owner: context.repo.owner, |
| 53 | + repo: context.repo.repo, |
| 54 | + workflow_id: 'ci.yml', |
| 55 | + head_sha: '${{ steps.pr.outputs.sha }}', |
| 56 | + per_page: 1, |
| 57 | + }); |
| 58 | + if (runs.data.workflow_runs.length === 0) { |
| 59 | + core.setFailed('No CI run found for this PR head SHA.'); |
| 60 | + return; |
| 61 | + } |
| 62 | + const run = runs.data.workflow_runs[0]; |
| 63 | + if (run.status === 'completed') { |
| 64 | + await github.rest.actions.reRunWorkflow({ |
| 65 | + owner: context.repo.owner, |
| 66 | + repo: context.repo.repo, |
| 67 | + run_id: run.id, |
| 68 | + }); |
| 69 | + } else { |
| 70 | + core.info('CI is already running (status: ' + run.status + '). Nothing to re-run.'); |
| 71 | + } |
0 commit comments