Skip to content

Commit 224149c

Browse files
committed
Enforce DCO
1 parent 62510ec commit 224149c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

.github/workflows/dco.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
permissions:
1010
contents: read
11+
actions: write
1112

1213
jobs:
1314
check:
@@ -34,8 +35,40 @@ jobs:
3435
'https://raw.githubusercontent.com/christophebedard/dco-check/${{ env.DCO_CHECK_VERSION }}/dco_check/dco_check.py'
3536
3637
- name: Run DCO check
38+
id: dco-check
3739
env:
3840
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3941
DCO_CHECK_VERBOSE: "true"
4042
DCO_CHECK_EXCLUDE_PATTERN: dependabot\[bot\]@users\.noreply\.github\.com
4143
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

Comments
 (0)