Skip to content

Commit 300d411

Browse files
committed
meta: add DCO sign-off check to commit workflow
All commits are technically supposed to be signed off with a DCO sign-off (using `Signed-off-by`) but we haven't enforced that. We really ought to be. Signed-off-by: James M Snell <[email protected]>
1 parent e78ccd8 commit 300d411

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

.github/workflows/commit-dco.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: DCO sign-off check
2+
3+
on: [pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
check-dco:
10+
runs-on: ubuntu-slim
11+
steps:
12+
- name: Compute number of commits in the PR
13+
id: nb-of-commits
14+
run: |
15+
echo "plusOne=$((${{ github.event.pull_request.commits }} + 1))" >> $GITHUB_OUTPUT
16+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
with:
18+
fetch-depth: ${{ steps.nb-of-commits.outputs.plusOne }}
19+
persist-credentials: false
20+
- run: git reset HEAD^2
21+
- name: Check commits for Signed-off-by
22+
run: |
23+
STATUS=0
24+
COMMITS=$(git log --format='%H' -n ${{ github.event.pull_request.commits }})
25+
for SHA in $COMMITS; do
26+
MESSAGE=$(git log --format='%B' -n 1 "$SHA")
27+
if ! echo "$MESSAGE" | grep -qP '^Signed-off-by: .+ <[^@]+@[^@]+\.[^@]+>'; then
28+
SUBJECT=$(git log --format='%s' -n 1 "$SHA")
29+
SIGNOFF=$(echo "$MESSAGE" | grep -P '^Signed-off-by: ' || true)
30+
if [ -z "$SIGNOFF" ]; then
31+
echo "::error::Commit ${SHA:0:12} is missing a 'Signed-off-by' trailer. Subject: $SUBJECT"
32+
else
33+
echo "::error::Commit ${SHA:0:12} has a 'Signed-off-by' trailer with an invalid email address. Subject: $SUBJECT"
34+
fi
35+
STATUS=1
36+
fi
37+
done
38+
if [ "$STATUS" != "0" ]; then
39+
echo
40+
echo "All commits must contain a Signed-off-by trailer to indicate"
41+
echo "agreement with the Developer Certificate of Origin (DCO)."
42+
echo "Use 'git commit -s' to add it automatically."
43+
echo
44+
echo "Note: The Signed-off-by attestation must be made by a human author."
45+
echo "Bots and AI agents are not permitted to sign off on commits."
46+
exit 1
47+
fi

0 commit comments

Comments
 (0)