|
1 | 1 | name: DCO Check |
2 | 2 |
|
3 | | -on: [pull_request] |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + branches: [main] |
4 | 7 |
|
5 | 8 | permissions: |
6 | 9 | contents: read |
7 | | - pull-requests: write |
8 | 10 |
|
9 | 11 | jobs: |
10 | | - check: |
| 12 | + dco-check: |
11 | 13 | runs-on: ubuntu-latest |
| 14 | + name: Check DCO Sign-off |
12 | 15 | steps: |
13 | | - - name: Check for DCO |
14 | | - id: dco-check |
15 | | - uses: tisonkun/actions-dco@6d1f8a197db1b04df1769707b46b9366b1eca902 # v1.1 |
16 | | - - name: Comment about DCO status |
17 | | - uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7 |
18 | | - if: ${{ failure() }} |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
19 | 18 | with: |
20 | | - script: | |
21 | | - github.rest.issues.createComment({ |
22 | | - issue_number: context.issue.number, |
23 | | - owner: context.repo.owner, |
24 | | - repo: context.repo.repo, |
25 | | - body: `Thanks for your contribution! To satisfy the DCO policy in our \ |
26 | | - [contributing guide](https://github.com/databricks/databricks-sql-python/blob/main/CONTRIBUTING.md) \ |
27 | | - every commit message must include a sign-off message. One or more of your commits is missing this message. \ |
28 | | - You can reword previous commit messages with an interactive rebase (\`git rebase -i main\`).` |
29 | | - }) |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Check DCO Sign-off |
| 22 | + env: |
| 23 | + BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 24 | + HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 25 | + run: | |
| 26 | + #!/bin/bash |
| 27 | + set -e |
| 28 | +
|
| 29 | + echo "Checking commits from $BASE_SHA to $HEAD_SHA" |
| 30 | +
|
| 31 | + COMMITS=$(git rev-list --no-merges "$BASE_SHA..$HEAD_SHA") |
| 32 | +
|
| 33 | + if [ -z "$COMMITS" ]; then |
| 34 | + echo "No commits found in this PR" |
| 35 | + exit 0 |
| 36 | + fi |
| 37 | +
|
| 38 | + FAILED_COMMITS=() |
| 39 | +
|
| 40 | + for commit in $COMMITS; do |
| 41 | + echo "Checking commit: $commit" |
| 42 | + COMMIT_MSG=$(git log --format=%B -n 1 "$commit") |
| 43 | + if echo "$COMMIT_MSG" | grep -q "^Signed-off-by: "; then |
| 44 | + echo " Commit $commit has DCO sign-off" |
| 45 | + else |
| 46 | + echo " Commit $commit is missing DCO sign-off" |
| 47 | + FAILED_COMMITS+=("$commit") |
| 48 | + fi |
| 49 | + done |
| 50 | +
|
| 51 | + if [ ${#FAILED_COMMITS[@]} -ne 0 ]; then |
| 52 | + echo "" |
| 53 | + echo "DCO Check Failed!" |
| 54 | + echo "The following commits are missing the required 'Signed-off-by' line:" |
| 55 | + for commit in "${FAILED_COMMITS[@]}"; do |
| 56 | + echo " - $commit: $(git log --format=%s -n 1 "$commit")" |
| 57 | + done |
| 58 | + echo "" |
| 59 | + echo "To fix this, you need to sign off your commits. You can:" |
| 60 | + echo "1. Add sign-off to new commits: git commit -s -m 'Your commit message'" |
| 61 | + echo "2. Amend existing commits: git commit --amend --signoff" |
| 62 | + echo "3. For multiple commits, use: git rebase --signoff HEAD~N (where N is the number of commits)" |
| 63 | + echo "" |
| 64 | + echo "The sign-off should be in the format:" |
| 65 | + echo "Signed-off-by: Your Name <your.email@example.com>" |
| 66 | + echo "" |
| 67 | + echo "For more details, see CONTRIBUTING.md" |
| 68 | + exit 1 |
| 69 | + else |
| 70 | + echo "" |
| 71 | + echo "All commits have proper DCO sign-off!" |
| 72 | + fi |
0 commit comments