Skip to content

ci(github): action

ci(github): action #3

Workflow file for this run

name: Verify Latest Commit Signature
on:
pull_request:
branches: [ develop, master ]
push:
branches: [ develop, master ]
jobs:
verify-latest-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1 # Only fetch the latest commit
- name: Import GPG keys from GitHub
run: |
# Get the author email of the latest commit
AUTHOR_EMAIL=$(git log -1 --pretty='format:%ae')
echo "Commit author email: $AUTHOR_EMAIL"
# Get GPG keys from GitHub for the commit author
curl -s https://github.com/${{ github.actor }}.gpg | gpg --import -
# List imported keys for debugging
gpg --list-keys
- name: Verify Latest Commit
shell: bash # Explicitly use bash
run: |
# Get the latest commit hash
LATEST_COMMIT=$(git rev-parse HEAD)
echo "Checking signature for commit: $LATEST_COMMIT"
# Show commit details
echo "Commit details:"
git log -1 --pretty='format:Commit: %h%nAuthor: %an%nDate: %ad%nMessage: %s'
echo -e "\n-----------------------------------"
# Check signature status using git log (with quoted format)
SIGNATURE_STATUS=$(git log --format='%G?' -n 1 "$LATEST_COMMIT")
case "$SIGNATURE_STATUS" in
"G")
echo "✅ Good signature from valid key"
echo "Verification successful!"
exit 0
;;
"U")
echo "❌ Good signature from UNKNOWN key"
echo "::error::Commit is signed with an unknown key. Please add your GPG key to GitHub"
exit 1
;;
"B")
echo "❌ BAD signature"
echo "::error::Commit has an invalid signature"
exit 1
;;
"N")
echo "❌ NO signature"
echo "::error::Commit is not signed. Please sign your commits using GPG"
exit 1
;;
"E")
echo "❌ Signature verification ERROR"
echo "::error::Error occurred during signature verification"
exit 1
;;
"Y")
echo "❌ Good signature from expired key"
echo "::error::Commit is signed with an expired key. Please update your GPG key"
exit 1
;;
"R")
echo "❌ Good signature from revoked key"
echo "::error::Commit is signed with a revoked key. Please generate and use a new GPG key"
exit 1
;;
*)
echo "❌ Unknown verification status: $SIGNATURE_STATUS"
echo "::error::Unknown signature verification status"
exit 1
;;
esac