|
8 | 8 |
|
9 | 9 | permissions: |
10 | 10 | contents: read |
| 11 | + actions: write |
11 | 12 |
|
12 | 13 | jobs: |
13 | 14 | check: |
|
34 | 35 | 'https://raw.githubusercontent.com/christophebedard/dco-check/${{ env.DCO_CHECK_VERSION }}/dco_check/dco_check.py' |
35 | 36 |
|
36 | 37 | - name: Run DCO check |
| 38 | + id: dco-check |
37 | 39 | env: |
38 | 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
39 | 41 | DCO_CHECK_VERBOSE: "true" |
40 | 42 | DCO_CHECK_EXCLUDE_PATTERN: dependabot\[bot\]@users\.noreply\.github\.com |
41 | 43 | run: python3 dco_check.py |
| 44 | + |
| 45 | + - name: Cancel workflows on DCO failure |
| 46 | + if: failure() && steps.dco-check.outcome == 'failure' |
| 47 | + uses: actions/github-script@v8 |
| 48 | + with: |
| 49 | + script: | |
| 50 | + const currentRunId = context.runId; |
| 51 | + const prNumber = context.payload.pull_request.number; |
| 52 | +
|
| 53 | + // Get both queued and in_progress workflows |
| 54 | + for (const status of ['queued', 'in_progress']) { |
| 55 | + const runs = await github.rest.actions.listWorkflowRunsForRepo({ |
| 56 | + owner: context.repo.owner, |
| 57 | + repo: context.repo.repo, |
| 58 | + event: 'pull_request', |
| 59 | + status: status, |
| 60 | + }); |
| 61 | +
|
| 62 | + for (const run of runs.data.workflow_runs) { |
| 63 | + // Cancel workflows for the same PR, but not this DCO workflow itself |
| 64 | + if (run.id !== currentRunId && |
| 65 | + run.pull_requests.some(pr => pr.number === prNumber)) { |
| 66 | + console.log(`Cancelling ${status} workflow run ${run.id} (${run.name})`); |
| 67 | + await github.rest.actions.cancelWorkflowRun({ |
| 68 | + owner: context.repo.owner, |
| 69 | + repo: context.repo.repo, |
| 70 | + run_id: run.id, |
| 71 | + }); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
0 commit comments