Skip to content

Commit c3b3fab

Browse files
committed
Add GHA to verify commit sign off
Signed-off-by: annecyh <anne.chew@canonical.com>
1 parent 25ec44f commit c3b3fab

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Verify Commit Signoff
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "main" # Run on pull requests to the main branch
7+
8+
jobs:
9+
verify-signoff:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Validate commits
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
run: |
20+
# Ensure both commits in the range exist locally
21+
if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
22+
# First push, check all commits
23+
COMMITS=$(git rev-list ${{ github.sha }})
24+
else
25+
# Fetch the commit range
26+
git fetch origin ${{ github.event.before }} --quiet
27+
COMMITS=$(git log --format='%H' ${{ github.event.before }}..${{ github.sha }})
28+
fi
29+
30+
# Check each commit
31+
for COMMIT in $COMMITS; do
32+
MESSAGE=$(git show -s --format='%B' $COMMIT)
33+
34+
# Check for sign-off
35+
if ! echo "$MESSAGE" | grep -q "Signed-off-by:"; then
36+
echo "❌ Commit $COMMIT is missing a 'Signed-off-by:' line."
37+
exit 1
38+
fi
39+
done
40+
41+
echo "✅ All commits are properly signed off."

0 commit comments

Comments
 (0)