Skip to content

Commit 215cbcf

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

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)