|
3 | 3 | pull_request: |
4 | 4 | merge_group: |
5 | 5 | types: [checks_requested] |
| 6 | + schedule: |
| 7 | + - cron: '43 11 * * 0' |
| 8 | + workflow_dispatch: |
6 | 9 | permissions: {} |
7 | 10 | concurrency: |
8 | 11 | group: dco-${{ github.event.pull_request.number || github.ref }} |
@@ -32,36 +35,74 @@ jobs: |
32 | 35 | run: | |
33 | 36 | set -euo pipefail |
34 | 37 |
|
35 | | - test -n "$BASE_SHA" |
36 | | - test -n "$HEAD_SHA" |
37 | | - git cat-file -e "${BASE_SHA}^{commit}" |
| 38 | + check_signoffs() { |
| 39 | + test -n "$BASE_SHA" |
| 40 | + test -n "$HEAD_SHA" |
| 41 | + git cat-file -e "${BASE_SHA}^{commit}" |
38 | 42 |
|
39 | | - if ! git cat-file -e "${HEAD_SHA}^{commit}"; then |
40 | | - if [ "$EVENT_NAME" = pull_request ] && [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then |
41 | | - git fetch --no-tags origin "refs/pull/${PR_NUMBER}/head" |
| 43 | + if ! git cat-file -e "${HEAD_SHA}^{commit}"; then |
| 44 | + if [ "$EVENT_NAME" = pull_request ] && [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then |
| 45 | + git fetch --no-tags origin "refs/pull/${PR_NUMBER}/head" |
| 46 | + fi |
42 | 47 | fi |
43 | | - fi |
44 | | - git cat-file -e "${HEAD_SHA}^{commit}" |
| 48 | + git cat-file -e "${HEAD_SHA}^{commit}" |
45 | 49 |
|
46 | | - commit_range="${BASE_SHA}..${HEAD_SHA}" |
47 | | - # GitHub's merge queue adds an unsigned synthetic tip commit. The |
48 | | - # commits it contains were already checked on the pull request; skip |
49 | | - # only that generated tip and continue checking every real commit. |
50 | | - if [ "$EVENT_NAME" = merge_group ]; then |
51 | | - commit_range="${BASE_SHA}..${HEAD_SHA}^" |
52 | | - fi |
| 50 | + local commit_range="${BASE_SHA}..${HEAD_SHA}" |
| 51 | + # GitHub's merge queue adds an unsigned synthetic tip commit. The |
| 52 | + # commits it contains were already checked on the pull request; skip |
| 53 | + # only that generated tip and continue checking every real commit. |
| 54 | + if [ "$EVENT_NAME" = merge_group ]; then |
| 55 | + commit_range="${BASE_SHA}..${HEAD_SHA}^" |
| 56 | + fi |
| 57 | +
|
| 58 | + local missing=() commit author |
| 59 | + while IFS= read -r commit; do |
| 60 | + author=$(git show -s --format='%an <%ae>' "$commit") |
| 61 | + if git show -s --format='%B' "$commit" | grep -Fqx "Signed-off-by: $author"; then |
| 62 | + continue |
| 63 | + fi |
| 64 | +
|
| 65 | + # Dependabot authors with its GitHub noreply identity but uses its |
| 66 | + # support address in the DCO trailer. |
| 67 | + if [ "$author" = 'dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>' ] && |
| 68 | + git show -s --format='%B' "$commit" | grep -Fqx 'Signed-off-by: dependabot[bot] <support@github.com>'; then |
| 69 | + continue |
| 70 | + fi |
53 | 71 |
|
54 | | - missing=() |
55 | | - while IFS= read -r commit; do |
56 | | - author=$(git show -s --format='%an <%ae>' "$commit") |
57 | | - if ! git show -s --format='%B' "$commit" | grep -Fqx "Signed-off-by: $author"; then |
58 | 72 | missing+=("$commit $author") |
| 73 | + done < <(git rev-list --no-merges "$commit_range") |
| 74 | +
|
| 75 | + if [ "${#missing[@]}" -gt 0 ]; then |
| 76 | + printf '%s\n' 'Every commit must contain a valid Signed-off-by trailer for its author.' |
| 77 | + printf 'Missing sign-off: %s\n' "${missing[@]}" |
| 78 | + printf '%s\n' 'Use: git commit --signoff' |
| 79 | + return 1 |
59 | 80 | fi |
60 | | - done < <(git rev-list --no-merges "$commit_range") |
| 81 | + } |
61 | 82 |
|
62 | | - if [ "${#missing[@]}" -gt 0 ]; then |
63 | | - printf '%s\n' "Every commit must contain a Signed-off-by trailer matching its author." |
64 | | - printf 'Missing sign-off: %s\n' "${missing[@]}" |
65 | | - printf '%s\n' 'Use: git commit --signoff' |
66 | | - exit 1 |
| 83 | + if [ "$EVENT_NAME" = schedule ] || [ "$EVENT_NAME" = workflow_dispatch ]; then |
| 84 | + fixture=$(mktemp -d) |
| 85 | + trap 'rm -rf "$fixture"' EXIT |
| 86 | + cd "$fixture" |
| 87 | + git init -q |
| 88 | + git config commit.gpgsign false |
| 89 | + git -c user.name=Fixture -c user.email=fixture@example.invalid commit --allow-empty -qm base |
| 90 | + BASE_SHA=$(git rev-parse HEAD) |
| 91 | + git -c user.name='dependabot[bot]' -c user.email='49699333+dependabot[bot]@users.noreply.github.com' \ |
| 92 | + commit --allow-empty -qm $'bot update\n\nSigned-off-by: dependabot[bot] <support@github.com>' |
| 93 | + git -c user.name=Fixture -c user.email=fixture@example.invalid \ |
| 94 | + commit --allow-empty -qm $'human update\n\nSigned-off-by: Fixture <fixture@example.invalid>' |
| 95 | + HEAD_SHA=$(git rev-parse HEAD) |
| 96 | + check_signoffs |
| 97 | + BASE_SHA=$HEAD_SHA |
| 98 | + git -c user.name='dependabot[bot]' -c user.email='49699333+dependabot[bot]@users.noreply.github.com' \ |
| 99 | + commit --allow-empty -qm $'bad trailer\n\nSigned-off-by: dependabot[bot] <wrong@example.invalid>' |
| 100 | + HEAD_SHA=$(git rev-parse HEAD) |
| 101 | + if check_signoffs; then |
| 102 | + echo 'DCO fixture accepted an invalid Dependabot trailer' >&2 |
| 103 | + exit 1 |
| 104 | + fi |
| 105 | + echo 'DCO fixture passed' |
| 106 | + else |
| 107 | + check_signoffs |
67 | 108 | fi |
0 commit comments