name: Retest PR on: issue_comment: types: [created] env: FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true jobs: retest: if: github.event.issue.pull_request && contains(github.event.comment.body, 'retest') runs-on: ubuntu-latest permissions: actions: write issues: write pull-requests: read steps: - name: Check authorization and trigger phrase uses: actions/github-script@v9 with: script: | const assoc = context.payload.comment.author_association; if (!['OWNER', 'MEMBER', 'COLLABORATOR'].includes(assoc)) { core.setFailed('Not authorized (association: ' + assoc + ')'); return; } const body = context.payload.comment.body; if (!body.includes('/retest') && !body.includes('[CI: retest]') && !body.includes('[ci: retest]')) { core.setFailed('No recognized retest trigger found.'); } - name: Get PR head SHA id: pr uses: actions/github-script@v9 with: script: | const pr = (await github.rest.pulls.get({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.issue.number, })).data; core.setOutput('sha', pr.head.sha); - name: Re-run CI uses: actions/github-script@v9 with: script: | const runs = await github.rest.actions.listWorkflowRuns({ owner: context.repo.owner, repo: context.repo.repo, workflow_id: 'ci.yml', head_sha: '${{ steps.pr.outputs.sha }}', per_page: 1, }); if (runs.data.workflow_runs.length === 0) { core.setFailed('No CI run found for this PR head SHA.'); return; } const run = runs.data.workflow_runs[0]; if (run.status === 'completed') { await github.rest.actions.reRunWorkflow({ owner: context.repo.owner, repo: context.repo.repo, run_id: run.id, }); } else { core.info('CI is already running (status: ' + run.status + '). Nothing to re-run.'); }