-
Notifications
You must be signed in to change notification settings - Fork 577
49 lines (42 loc) · 1.61 KB
/
Copy pathdco.yml
File metadata and controls
49 lines (42 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: DCO
on:
pull_request:
permissions:
contents: read
jobs:
signoff:
name: Sign-off
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check out pull-request history
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Require a DCO trailer on every commit
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
shell: bash
run: |
set -euo pipefail
# The event's base SHA can predate upstream commits already in the PR.
# Refresh the exact target branch before selecting PR-only commits.
git fetch --no-tags origin \
"+refs/heads/${BASE_REF}:refs/remotes/origin/${BASE_REF}"
# Keep this outside process substitution so a failed range lookup
# cannot silently turn into a successful check of zero commits.
commits=$(git rev-list --reverse "refs/remotes/origin/${BASE_REF}..${HEAD_SHA}")
missing=0
while IFS= read -r commit; do
[[ -z "${commit}" ]] && continue
if ! git show -s --format=%B "${commit}" |
grep -Eq '^Signed-off-by: [^<]+ <[^<>[:space:]]+@[^<>[:space:]]+>$'; then
echo "::error::Commit ${commit} is missing a valid Signed-off-by trailer."
missing=1
fi
done <<< "${commits}"
if [[ "${missing}" -ne 0 ]]; then
echo "Add the DCO certification with: git commit --amend -s"
exit 1
fi