File: dco

package info (click to toggle)
docker.io 20.10.24%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 60,824 kB
  • sloc: sh: 5,621; makefile: 593; ansic: 179; python: 162; asm: 7
file content (55 lines) | stat: -rwxr-xr-x 1,736 bytes parent folder | download | duplicates (6)
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
50
51
52
53
54
55
#!/usr/bin/env bash

export SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPTDIR}/.validate"

adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }')
dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }')
#notDocs="$(validate_diff --numstat | awk '$3 !~ /^docs\// { print $3 }')"

: ${adds:=0}
: ${dels:=0}

# "Username may only contain alphanumeric characters or dashes and cannot begin with a dash"
githubUsernameRegex='[a-zA-Z0-9][a-zA-Z0-9-]+'

# https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work
dcoPrefix='Signed-off-by:'
dcoRegex="^(Docker-DCO-1.1-)?$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)>( \\(github: ($githubUsernameRegex)\\))?$"

check_dco() {
	grep -qE "$dcoRegex"
}

if [ ${adds} -eq 0 -a ${dels} -eq 0 ]; then
	echo '0 adds, 0 deletions; nothing to validate! :)'
else
	commits=($(validate_log --format='format:%H%n'))
	badCommits=()
	for commit in "${commits[@]}"; do
		if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then
			# no content (ie, Merge commit, etc)
			continue
		fi
		if ! git log -1 --format='format:%B' "$commit" | check_dco; then
			badCommits+=("$commit")
		fi
	done
	if [ ${#badCommits[@]} -eq 0 ]; then
		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:'
			echo ' https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work'
			echo
		} >&2
		false
	fi
fi