Skip to content

Commit e25cc60

Browse files
authored
ci: validate Dependabot DCO on a schedule (#48)
Signed-off-by: IanHollow <72767437+IanHollow@users.noreply.github.com>
1 parent bb1b39a commit e25cc60

1 file changed

Lines changed: 66 additions & 25 deletions

File tree

‎.github/workflows/dco.yml‎

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ on:
33
pull_request:
44
merge_group:
55
types: [checks_requested]
6+
schedule:
7+
- cron: '43 11 * * 0'
8+
workflow_dispatch:
69
permissions: {}
710
concurrency:
811
group: dco-${{ github.event.pull_request.number || github.ref }}
@@ -32,36 +35,74 @@ jobs:
3235
run: |
3336
set -euo pipefail
3437
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}"
3842
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
4247
fi
43-
fi
44-
git cat-file -e "${HEAD_SHA}^{commit}"
48+
git cat-file -e "${HEAD_SHA}^{commit}"
4549
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
5371
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
5872
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
5980
fi
60-
done < <(git rev-list --no-merges "$commit_range")
81+
}
6182
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
67108
fi

0 commit comments

Comments
 (0)