2017-02-13 14:01:54 -05:00
|
|
|
#!/usr/bin/env bash
|
2014-04-04 02:37:50 -04:00
|
|
|
|
2020-03-02 22:27:49 -05:00
|
|
|
export SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
2016-10-12 15:25:49 -04:00
|
|
|
source "${SCRIPTDIR}/.validate"
|
2014-04-04 02:37:50 -04:00
|
|
|
|
|
|
|
adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }')
|
|
|
|
dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }')
|
2014-11-06 15:26:16 -05:00
|
|
|
#notDocs="$(validate_diff --numstat | awk '$3 !~ /^docs\// { print $3 }')"
|
2014-04-04 02:37:50 -04:00
|
|
|
|
|
|
|
: ${adds:=0}
|
|
|
|
: ${dels:=0}
|
|
|
|
|
2014-07-07 10:32:09 -04:00
|
|
|
# "Username may only contain alphanumeric characters or dashes and cannot begin with a dash"
|
2014-07-07 11:57:50 -04:00
|
|
|
githubUsernameRegex='[a-zA-Z0-9][a-zA-Z0-9-]+'
|
2014-07-07 10:32:09 -04:00
|
|
|
|
2014-07-24 18:19:50 -04:00
|
|
|
# https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work
|
2014-08-01 15:22:04 -04:00
|
|
|
dcoPrefix='Signed-off-by:'
|
|
|
|
dcoRegex="^(Docker-DCO-1.1-)?$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)>( \\(github: ($githubUsernameRegex)\\))?$"
|
2014-07-07 10:32:09 -04:00
|
|
|
|
|
|
|
check_dco() {
|
|
|
|
grep -qE "$dcoRegex"
|
|
|
|
}
|
|
|
|
|
2019-01-09 20:50:47 -05:00
|
|
|
if [ ${adds} -eq 0 -a ${dels} -eq 0 ]; then
|
2014-04-04 02:37:50 -04:00
|
|
|
echo '0 adds, 0 deletions; nothing to validate! :)'
|
|
|
|
else
|
2020-03-02 22:27:49 -05:00
|
|
|
commits=($(validate_log --format='format:%H%n'))
|
2014-04-04 02:37:50 -04:00
|
|
|
badCommits=()
|
|
|
|
for commit in "${commits[@]}"; do
|
2019-01-09 20:23:38 -05:00
|
|
|
if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then
|
2014-04-04 02:37:50 -04:00
|
|
|
# no content (ie, Merge commit, etc)
|
|
|
|
continue
|
|
|
|
fi
|
2014-07-07 10:32:09 -04:00
|
|
|
if ! git log -1 --format='format:%B' "$commit" | check_dco; then
|
2020-03-02 22:27:49 -05:00
|
|
|
badCommits+=("$commit")
|
2014-04-04 02:37:50 -04:00
|
|
|
fi
|
|
|
|
done
|
2019-01-09 20:23:38 -05:00
|
|
|
if [ ${#badCommits[@]} -eq 0 ]; then
|
2014-04-04 02:37:50 -04:00
|
|
|
echo "Congratulations! All commits are properly signed with the DCO!"
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo "These commits do not have a proper '$dcoPrefix' marker:"
|
|
|
|
for commit in "${badCommits[@]}"; do
|
|
|
|
echo " - $commit"
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
echo 'Please amend each commit to include a properly formatted DCO marker.'
|
|
|
|
echo
|
|
|
|
echo 'Visit the following URL for information about the Docker DCO:'
|
2014-07-24 18:19:50 -04:00
|
|
|
echo ' https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work'
|
2014-04-04 02:37:50 -04:00
|
|
|
echo
|
|
|
|
} >&2
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
fi
|