ci(CheckSignOff.yml): add DCO check #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check Sign-off | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| push: | |
| branches: [ main ] # 可根据需要指定分支,例如 "main", "master" | |
| jobs: | |
| check-signoff: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # 获取所有历史和分支,以便正确比较 | |
| - name: Check for Sign-off | |
| run: | | |
| check_commit() { | |
| local commit_hash=$1 | |
| local commit_msg=$(git show -s --format=%B "$commit_hash") | |
| if ! echo "$commit_msg" | grep -q "Signed-off-by:"; then | |
| echo "提交 $commit_hash 缺少 Signed-off-by 签署。" | |
| echo "请使用 'git commit -s' 添加签署,或手动在提交信息中包含 'Signed-off-by: Your Name <your.email@example.com>'。" | |
| return 1 | |
| fi | |
| } | |
| if [ "${{ github.event_name }}" = "push" ]; then | |
| if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then | |
| COMMITS_TO_CHECK=$(git log --oneline --format=%H ${{ github.event.after }}) | |
| else | |
| COMMITS_TO_CHECK=$(git log --oneline --format=%H ${{ github.event.before }}..${{ github.event.after }}) | |
| fi | |
| else | |
| COMMITS_TO_CHECK=$(git log --oneline --format=%H ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}) | |
| fi | |
| if [ -z "$COMMITS_TO_CHECK" ]; then | |
| exit 0 | |
| fi | |
| echo "$COMMITS_TO_CHECK" | |
| HAS_ERROR=0 | |
| for commit in $COMMITS_TO_CHECK; do | |
| if ! check_commit "$commit"; then | |
| HAS_ERROR=1 | |
| fi | |
| done | |
| if [ $HAS_ERROR -eq 1 ]; then | |
| echo "::error::部分提交缺少开发者签署认证(DCO)。" | |
| exit 1 | |
| else | |
| echo "所有提交均已签署。" | |
| fi |