Browse code

Add new validate-dco and validate-gofmt bundlescripts for DCO and gofmt validation

Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)

Tianon Gravi authored on 2014/04/04 15:37:50
Showing 5 changed files
... ...
@@ -12,19 +12,11 @@ before_script:
12 12
   - env | sort
13 13
   - sudo apt-get update -qq
14 14
   - sudo apt-get install -qq python-yaml
15
-  - git remote add upstream git://github.com/dotcloud/docker.git
16
-  - upstream=master;
17
-    if [ "$TRAVIS_PULL_REQUEST" != false ]; then
18
-      upstream=$TRAVIS_BRANCH;
19
-    fi;
20
-    git fetch --append --no-tags upstream refs/heads/$upstream:refs/remotes/upstream/$upstream
21
-# sometimes we have upstream master already as origin/master (PRs), but other times we don't, so let's just make sure we have a completely unambiguous way to specify "upstream master" from here out
22
-# but if it's a PR against non-master, we need that upstream branch instead :)
23 15
   - sudo pip install -r docs/requirements.txt
24 16
 
25 17
 script:
26
-  - hack/travis/dco.py
27
-  - hack/travis/gofmt.py
18
+  - hack/make.sh validate-dco
19
+  - hack/make.sh validate-gofmt
28 20
   - make -sC docs SPHINXOPTS=-qW docs man
29 21
 
30 22
 # vim:set sw=2 ts=2:
... ...
@@ -40,13 +40,19 @@ echo
40 40
 
41 41
 # List of bundles to create when no argument is passed
42 42
 DEFAULT_BUNDLES=(
43
+	validate-dco
44
+	validate-gofmt
45
+	
43 46
 	binary
47
+	
44 48
 	test
45 49
 	test-integration
46 50
 	test-integration-cli
51
+	
47 52
 	dynbinary
48 53
 	dyntest
49 54
 	dyntest-integration
55
+	
50 56
 	cover
51 57
 	cross
52 58
 	tgz
53 59
new file mode 100644
... ...
@@ -0,0 +1,33 @@
0
+#!/bin/bash
1
+
2
+if [ -z "$VALIDATE_UPSTREAM" ]; then
3
+	# this is kind of an expensive check, so let's not do this twice if we
4
+	# are running more than one validate bundlescript
5
+	
6
+	VALIDATE_REPO='https://github.com/dotcloud/docker.git'
7
+	VALIDATE_BRANCH='master'
8
+	
9
+	if [ "$TRAVIS" = 'true' -a "$TRAVIS_PULL_REQUEST" != 'false' ]; then
10
+		VALIDATE_REPO="https://github.com/${TRAVIS_REPO_SLUG}.git"
11
+		VALIDATE_BRANCH="${TRAVIS_BRANCH}"
12
+	fi
13
+	
14
+	VALIDATE_HEAD="$(git rev-parse --verify HEAD)"
15
+	
16
+	git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH"
17
+	VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)"
18
+	
19
+	VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD"
20
+	VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD"
21
+	
22
+	validate_diff() {
23
+		if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
24
+			git diff "$VALIDATE_COMMIT_DIFF" "$@"
25
+		fi
26
+	}
27
+	validate_log() {
28
+		if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
29
+			git log "$VALIDATE_COMMIT_LOG" "$@"
30
+		fi
31
+	}
32
+fi
0 33
new file mode 100644
... ...
@@ -0,0 +1,47 @@
0
+#!/bin/bash
1
+
2
+source "$(dirname "$BASH_SOURCE")/.validate"
3
+
4
+adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }')
5
+dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }')
6
+notDocs="$(validate_diff --numstat | awk '$3 !~ /^docs\// { print $3 }')"
7
+
8
+: ${adds:=0}
9
+: ${dels:=0}
10
+
11
+if [ $adds -eq 0 -a $dels -eq 0 ]; then
12
+	echo '0 adds, 0 deletions; nothing to validate! :)'
13
+elif [ -z "$notDocs" -a $adds -le 1 -a $dels -le 1 ]; then
14
+	echo 'Congratulations!  DCO small-patch-exception material!'
15
+else
16
+	dcoPrefix='Docker-DCO-1.1-Signed-off-by:'
17
+	dcoRegex="^$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)> \\(github: (\S+)\\)$"
18
+	commits=( $(validate_log --format='format:%H%n') )
19
+	badCommits=()
20
+	for commit in "${commits[@]}"; do
21
+		if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then
22
+			# no content (ie, Merge commit, etc)
23
+			continue
24
+		fi
25
+		if ! git log -1 --format='format:%B' "$commit" | grep -qE "$dcoRegex"; then
26
+			badCommits+=( "$commit" )
27
+		fi
28
+	done
29
+	if [ ${#badCommits[@]} -eq 0 ]; then
30
+		echo "Congratulations!  All commits are properly signed with the DCO!"
31
+	else
32
+		{
33
+			echo "These commits do not have a proper '$dcoPrefix' marker:"
34
+			for commit in "${badCommits[@]}"; do
35
+				echo " - $commit"
36
+			done
37
+			echo
38
+			echo 'Please amend each commit to include a properly formatted DCO marker.'
39
+			echo
40
+			echo 'Visit the following URL for information about the Docker DCO:'
41
+			echo ' https://github.com/dotcloud/docker/blob/master/CONTRIBUTING.md#sign-your-work'
42
+			echo
43
+		} >&2
44
+		false
45
+	fi
46
+fi
0 47
new file mode 100644
... ...
@@ -0,0 +1,30 @@
0
+#!/bin/bash
1
+
2
+source "$(dirname "$BASH_SOURCE")/.validate"
3
+
4
+IFS=$'\n'
5
+files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) )
6
+unset IFS
7
+
8
+badFiles=()
9
+for f in "${files[@]}"; do
10
+	# we use "git show" here to validate that what's committed is formatted
11
+	if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then
12
+		badFiles+=( "$f" )
13
+	fi
14
+done
15
+
16
+if [ ${#badFiles[@]} -eq 0 ]; then
17
+	echo 'Congratulations!  All Go source files are properly formatted.'
18
+else
19
+	{
20
+		echo "These files are not properly gofmt'd:"
21
+		for f in "${badFiles[@]}"; do
22
+			echo " - $f"
23
+		done
24
+		echo
25
+		echo 'Please reformat the above files using "gofmt -s -w" and commit the result.'
26
+		echo
27
+	} >&2
28
+	false
29
+fi