Skip to content

Commit 7b8b9a1

Browse files
feat(ci): add DCO sign-off check for pull requests
Add a GitHub Actions workflow that verifies all commits in a PR have a 'Signed-off-by' line for Developer Certificate of Origin compliance. - Checks all non-merge commits in the PR - Provides clear error messages with instructions to fix - Shows which specific commits are missing sign-off To enforce this check, enable branch protection rules on master and require the "Verify DCO Sign-off" check to pass. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: JasonXuDeveloper - 傑 <jason@xgamedev.net>
1 parent 27c4a06 commit 7b8b9a1

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

.github/workflows/dco-check.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: DCO Check
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
dco-check:
9+
name: Verify DCO Sign-off
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # Fetch all commits for PR
17+
18+
- name: Check DCO sign-off on all commits
19+
run: |
20+
echo "Checking DCO sign-off for all commits in this PR..."
21+
echo ""
22+
23+
# Get the base and head commits
24+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
25+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
26+
27+
# Get list of commits in the PR
28+
COMMITS=$(git rev-list --no-merges $BASE_SHA..$HEAD_SHA)
29+
30+
if [ -z "$COMMITS" ]; then
31+
echo "No commits to check."
32+
exit 0
33+
fi
34+
35+
FAILED=0
36+
TOTAL=0
37+
38+
for COMMIT in $COMMITS; do
39+
TOTAL=$((TOTAL + 1))
40+
SUBJECT=$(git log -1 --format="%s" $COMMIT)
41+
AUTHOR=$(git log -1 --format="%an <%ae>" $COMMIT)
42+
43+
# Check for Signed-off-by line
44+
if git log -1 --format="%B" $COMMIT | grep -q "^Signed-off-by: "; then
45+
echo "✅ $COMMIT: $SUBJECT"
46+
else
47+
echo "❌ $COMMIT: $SUBJECT"
48+
echo " Author: $AUTHOR"
49+
echo " Missing 'Signed-off-by' line"
50+
echo ""
51+
FAILED=$((FAILED + 1))
52+
fi
53+
done
54+
55+
echo ""
56+
echo "----------------------------------------"
57+
echo "Total commits checked: $TOTAL"
58+
echo "Commits with sign-off: $((TOTAL - FAILED))"
59+
echo "Commits missing sign-off: $FAILED"
60+
echo "----------------------------------------"
61+
62+
if [ $FAILED -gt 0 ]; then
63+
echo ""
64+
echo "❌ DCO check failed!"
65+
echo ""
66+
echo "All commits must be signed off to certify you have the right to submit"
67+
echo "the code under the project's open source license."
68+
echo ""
69+
echo "To sign off your commits, use the --signoff (or -s) flag:"
70+
echo " git commit -s -m \"your commit message\""
71+
echo ""
72+
echo "To fix existing commits, you can:"
73+
echo " 1. Amend the last commit: git commit --amend -s"
74+
echo " 2. Rebase and sign all: git rebase --signoff HEAD~$FAILED"
75+
echo ""
76+
echo "For more information, see: https://developercertificate.org/"
77+
exit 1
78+
fi
79+
80+
echo ""
81+
echo "✅ All commits are properly signed off!"

0 commit comments

Comments
 (0)