|
| 1 | +name: Retest |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +jobs: |
| 8 | + retest: |
| 9 | + name: Retest PR |
| 10 | + runs-on: ubuntu-latest |
| 11 | + if: | |
| 12 | + github.event.issue.pull_request && |
| 13 | + contains(github.event.comment.body, '/retest') |
| 14 | + permissions: |
| 15 | + actions: write |
| 16 | + pull-requests: read |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Rerun from Prepare environment |
| 20 | + uses: actions/github-script@v7 |
| 21 | + with: |
| 22 | + script: | |
| 23 | + const prNumber = context.issue.number; |
| 24 | +
|
| 25 | + // Get the PR to find the head SHA |
| 26 | + const pr = await github.rest.pulls.get({ |
| 27 | + owner: context.repo.owner, |
| 28 | + repo: context.repo.repo, |
| 29 | + pull_number: prNumber |
| 30 | + }); |
| 31 | +
|
| 32 | + // Find the latest workflow run for this PR |
| 33 | + const runs = await github.rest.actions.listWorkflowRuns({ |
| 34 | + owner: context.repo.owner, |
| 35 | + repo: context.repo.repo, |
| 36 | + workflow_id: 'pull-requests.yaml', |
| 37 | + head_sha: pr.data.head.sha |
| 38 | + }); |
| 39 | +
|
| 40 | + if (runs.data.workflow_runs.length === 0) { |
| 41 | + core.setFailed('No workflow runs found for this PR'); |
| 42 | + return; |
| 43 | + } |
| 44 | +
|
| 45 | + const latestRun = runs.data.workflow_runs[0]; |
| 46 | + console.log(`Found workflow run: ${latestRun.id} (${latestRun.status})`); |
| 47 | +
|
| 48 | + // Check if workflow is waiting for approval (fork PRs) |
| 49 | + if (latestRun.conclusion === 'action_required') { |
| 50 | + core.setFailed('Workflow is waiting for approval. A maintainer must approve the workflow first.'); |
| 51 | + return; |
| 52 | + } |
| 53 | +
|
| 54 | + // Get jobs for this run |
| 55 | + const jobs = await github.rest.actions.listJobsForWorkflowRun({ |
| 56 | + owner: context.repo.owner, |
| 57 | + repo: context.repo.repo, |
| 58 | + run_id: latestRun.id |
| 59 | + }); |
| 60 | +
|
| 61 | + // Find "Prepare environment" job |
| 62 | + const prepareJob = jobs.data.jobs.find(j => j.name === 'Prepare environment'); |
| 63 | +
|
| 64 | + if (!prepareJob) { |
| 65 | + core.setFailed('Could not find "Prepare environment" job'); |
| 66 | + return; |
| 67 | + } |
| 68 | +
|
| 69 | + console.log(`Found job: ${prepareJob.name} (id: ${prepareJob.id}, status: ${prepareJob.status})`); |
| 70 | +
|
| 71 | + // Rerun the job |
| 72 | + await github.rest.actions.reRunJobForWorkflowRun({ |
| 73 | + owner: context.repo.owner, |
| 74 | + repo: context.repo.repo, |
| 75 | + job_id: prepareJob.id |
| 76 | + }); |
| 77 | +
|
| 78 | + console.log(`✅ Triggered rerun of job "${prepareJob.name}" (${prepareJob.id})`); |
0 commit comments