Skip to content

Commit aca0e42

Browse files
committed
Validate DCO on Travis
Copied straight from Docker, replacing github.com/docker/docker with github.com/docker/fig in .validate. Signed-off-by: Ben Firshman <ben@firshman.co.uk>
1 parent 15037ce commit aca0e42

3 files changed

Lines changed: 90 additions & 0 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ install:
77
- pip install -r requirements.txt
88
- pip install -r requirements-dev.txt
99
script:
10+
- script/validate-dco
1011
- flake8 fig
1112
- nosetests tests/unit

script/.validate

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
if [ -z "$VALIDATE_UPSTREAM" ]; then
4+
# this is kind of an expensive check, so let's not do this twice if we
5+
# are running more than one validate bundlescript
6+
7+
VALIDATE_REPO='https://github.com/docker/fig.git'
8+
VALIDATE_BRANCH='master'
9+
10+
if [ "$TRAVIS" = 'true' -a "$TRAVIS_PULL_REQUEST" != 'false' ]; then
11+
VALIDATE_REPO="https://github.com/${TRAVIS_REPO_SLUG}.git"
12+
VALIDATE_BRANCH="${TRAVIS_BRANCH}"
13+
fi
14+
15+
VALIDATE_HEAD="$(git rev-parse --verify HEAD)"
16+
17+
git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH"
18+
VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)"
19+
20+
VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD"
21+
VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD"
22+
23+
validate_diff() {
24+
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
25+
git diff "$VALIDATE_COMMIT_DIFF" "$@"
26+
fi
27+
}
28+
validate_log() {
29+
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
30+
git log "$VALIDATE_COMMIT_LOG" "$@"
31+
fi
32+
}
33+
fi

script/validate-dco

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
source "$(dirname "$BASH_SOURCE")/.validate"
4+
5+
adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }')
6+
dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }')
7+
notDocs="$(validate_diff --numstat | awk '$3 !~ /^docs\// { print $3 }')"
8+
9+
: ${adds:=0}
10+
: ${dels:=0}
11+
12+
# "Username may only contain alphanumeric characters or dashes and cannot begin with a dash"
13+
githubUsernameRegex='[a-zA-Z0-9][a-zA-Z0-9-]+'
14+
15+
# https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work
16+
dcoPrefix='Signed-off-by:'
17+
dcoRegex="^(Docker-DCO-1.1-)?$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)>( \\(github: ($githubUsernameRegex)\\))?$"
18+
19+
check_dco() {
20+
grep -qE "$dcoRegex"
21+
}
22+
23+
if [ $adds -eq 0 -a $dels -eq 0 ]; then
24+
echo '0 adds, 0 deletions; nothing to validate! :)'
25+
elif [ -z "$notDocs" -a $adds -le 1 -a $dels -le 1 ]; then
26+
echo 'Congratulations! DCO small-patch-exception material!'
27+
else
28+
commits=( $(validate_log --format='format:%H%n') )
29+
badCommits=()
30+
for commit in "${commits[@]}"; do
31+
if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then
32+
# no content (ie, Merge commit, etc)
33+
continue
34+
fi
35+
if ! git log -1 --format='format:%B' "$commit" | check_dco; then
36+
badCommits+=( "$commit" )
37+
fi
38+
done
39+
if [ ${#badCommits[@]} -eq 0 ]; then
40+
echo "Congratulations! All commits are properly signed with the DCO!"
41+
else
42+
{
43+
echo "These commits do not have a proper '$dcoPrefix' marker:"
44+
for commit in "${badCommits[@]}"; do
45+
echo " - $commit"
46+
done
47+
echo
48+
echo 'Please amend each commit to include a properly formatted DCO marker.'
49+
echo
50+
echo 'Visit the following URL for information about the Docker DCO:'
51+
echo ' https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work'
52+
echo
53+
} >&2
54+
false
55+
fi
56+
fi

0 commit comments

Comments
 (0)