|
| 1 | +name: DCO Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + branches: [ main ] |
| 7 | + |
| 8 | +jobs: |
| 9 | + dco-check: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + name: Check DCO Sign-off |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + fetch-depth: 0 # Fetch full history to check all commits |
| 17 | + ref: ${{ github.event.pull_request.head.ref }} |
| 18 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 19 | + |
| 20 | + - name: Add upstream remote (for forks) |
| 21 | + run: | |
| 22 | + # Add the upstream repository as a remote if this is a fork |
| 23 | + if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then |
| 24 | + echo "This is a fork, adding upstream remote" |
| 25 | + git remote add upstream https://github.com/${{ github.repository }}.git |
| 26 | + git fetch upstream ${{ github.event.pull_request.base.ref }} |
| 27 | + else |
| 28 | + echo "This is not a fork, using origin" |
| 29 | + fi |
| 30 | +
|
| 31 | + - name: Check DCO Sign-off |
| 32 | + run: | |
| 33 | + #!/bin/bash |
| 34 | + set -e |
| 35 | + |
| 36 | + # Get the list of commits in this PR |
| 37 | + BASE_SHA="${{ github.event.pull_request.base.sha }}" |
| 38 | + HEAD_SHA="${{ github.event.pull_request.head.sha }}" |
| 39 | + |
| 40 | + echo "Checking commits from $BASE_SHA to $HEAD_SHA" |
| 41 | + |
| 42 | + # Verify that both commits exist |
| 43 | + if ! git cat-file -e "$BASE_SHA" 2>/dev/null; then |
| 44 | + echo "Error: Base commit $BASE_SHA not found" |
| 45 | + echo "Trying to fetch from upstream..." |
| 46 | + if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then |
| 47 | + git fetch upstream ${{ github.event.pull_request.base.ref }} |
| 48 | + else |
| 49 | + git fetch origin ${{ github.event.pull_request.base.ref }} |
| 50 | + fi |
| 51 | + fi |
| 52 | + |
| 53 | + if ! git cat-file -e "$HEAD_SHA" 2>/dev/null; then |
| 54 | + echo "Error: Head commit $HEAD_SHA not found" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + |
| 58 | + # Get commit messages for all commits in the PR |
| 59 | + COMMITS=$(git rev-list --no-merges "$BASE_SHA..$HEAD_SHA") |
| 60 | + |
| 61 | + if [ -z "$COMMITS" ]; then |
| 62 | + echo "No commits found in this PR" |
| 63 | + exit 0 |
| 64 | + fi |
| 65 | + |
| 66 | + FAILED_COMMITS=() |
| 67 | + |
| 68 | + for commit in $COMMITS; do |
| 69 | + echo "Checking commit: $commit" |
| 70 | + |
| 71 | + # Get the commit message |
| 72 | + COMMIT_MSG=$(git log --format=%B -n 1 "$commit") |
| 73 | + |
| 74 | + # Check if the commit message contains "Signed-off-by:" |
| 75 | + if echo "$COMMIT_MSG" | grep -q "^Signed-off-by: "; then |
| 76 | + echo "✅ Commit $commit has DCO sign-off" |
| 77 | + else |
| 78 | + echo "❌ Commit $commit is missing DCO sign-off" |
| 79 | + FAILED_COMMITS+=("$commit") |
| 80 | + fi |
| 81 | + done |
| 82 | + |
| 83 | + if [ ${#FAILED_COMMITS[@]} -ne 0 ]; then |
| 84 | + echo "" |
| 85 | + echo "❌ DCO Check Failed!" |
| 86 | + echo "The following commits are missing the required 'Signed-off-by' line:" |
| 87 | + for commit in "${FAILED_COMMITS[@]}"; do |
| 88 | + echo " - $commit: $(git log --format=%s -n 1 "$commit")" |
| 89 | + done |
| 90 | + echo "" |
| 91 | + echo "To fix this, you need to sign off your commits. You can:" |
| 92 | + echo "1. Add sign-off to new commits: git commit -s -m 'Your commit message'" |
| 93 | + echo "2. Amend existing commits: git commit --amend --signoff" |
| 94 | + echo "3. For multiple commits, use: git rebase --signoff HEAD~N (where N is the number of commits)" |
| 95 | + echo "" |
| 96 | + echo "The sign-off should be in the format:" |
| 97 | + echo "Signed-off-by: Your Name <your.email@example.com>" |
| 98 | + echo "" |
| 99 | + echo "For more details, see CONTRIBUTING.md" |
| 100 | + exit 1 |
| 101 | + else |
| 102 | + echo "" |
| 103 | + echo "✅ All commits have proper DCO sign-off!" |
| 104 | + fi |
0 commit comments