From aa748b62b22354d461f9955ab05f7c8c81511a8b Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Mon, 19 Sep 2016 08:28:34 +0200 Subject: [PATCH] makefile stuff Signed-off-by: Antonio Murdaca --- .tool/check-license | 13 ++++++++++++ .tool/lint | 25 ++++++++++++++++++++++ .travis.yml | 14 +++++++++--- Makefile | 52 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 99 insertions(+), 5 deletions(-) create mode 100755 .tool/check-license create mode 100755 .tool/lint diff --git a/.tool/check-license b/.tool/check-license new file mode 100755 index 00000000..ab6f803b --- /dev/null +++ b/.tool/check-license @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +ret=0 + +for file in $(find . -type f -iname '*.go' ! -path './vendor/*'); do + (head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)") || (echo "${file}:missing license header" && ret=1) +done + +exit $ret diff --git a/.tool/lint b/.tool/lint new file mode 100755 index 00000000..4a0120e6 --- /dev/null +++ b/.tool/lint @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +if [ ! $(command -v gometalinter) ]; then + go get -u github.com/alecthomas/gometalinter + gometalinter --update --install +fi + +for d in $(find . -type d -not -iwholename '*.git*' -a -not -iname '.tool' -a -not -iwholename '*vendor*'); do + gometalinter \ + --exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \ + --exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \ + --exclude='duplicate of.*_test.go.*\(dupl\)$' \ + --exclude='schema/fs.go' \ + --exclude='duplicate of.*main.go.*\(dupl\)$' \ + --disable=aligncheck \ + --disable=gotype \ + --disable=gas \ + --cyclo-over=35 \ + --tests \ + --deadline=10s "${d}" +done diff --git a/.travis.yml b/.travis.yml index 1f9ae111..7591c766 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,22 @@ language: go go: - 1.6 + - 1.7 -sudo: false +sudo: required + +before_script: + - export PATH=$HOME/gopath/bin:$PATH before_install: - - go get github.com/vbatts/git-validation + - make install.tools + - go get -u github.com/alecthomas/gometalinter + - gometalinter --install --update + - go get -t -d ./... install: true script: - - $HOME/gopath/bin/git-validation -run DCO,short-subject -v -range ${TRAVIS_COMMIT_RANGE} + - make .gitvalidation + - make lint - make diff --git a/Makefile b/Makefile index f68ee0a3..7d172fce 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,18 @@ -.PHONY: all clean conmon ocid ocic update-deps +EPOCH_TEST_COMMIT ?= 7fc874e05e74faa81e7c423b6514fc5c474c6b34 -all: conmon ocid ocic +default: help + +help: + @echo "Usage: make " + @echo + @echo " * 'binaries' - Build ocid, conmon andocic" + @echo " * 'clean' - Clean artifacts" + @echo " * 'lint' - Execute the source code linter" + @echo " * 'update-deps' - Update vendored dependencies" + +lint: + @echo "checking lint" + @./.tool/lint conmon: make -C $@ @@ -13,6 +25,7 @@ ocic: clean: rm -f ocic ocid + rm -f conmon/conmon.o conmon/conmon update-deps: @which glide > /dev/null 2>/dev/null || (echo "ERROR: glide not found." && false) @@ -20,3 +33,38 @@ update-deps: glide-vc --only-code --no-tests # see http://sed.sourceforge.net/sed1line.txt find vendor -type f -exec sed -i -e :a -e '/^\n*$$/{$$d;N;ba' -e '}' "{}" \; + +binaries: ocid ocic conmon + +.PHONY: .gitvalidation + # +# When this is running in travis, it will only check the travis commit range +.gitvalidation: + @which git-validation > /dev/null 2>/dev/null || (echo "ERROR: git-validation not found. Consider 'make install.tools' target" && false) +ifeq ($(TRAVIS),true) + git-validation -q -run DCO,short-subject,dangling-whitespace +else + git-validation -v -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..HEAD +endif + +.PHONY: install.tools + +install.tools: .install.gitvalidation .install.glide .install.glide-vc .install.gometalinter + +.install.gitvalidation: + go get github.com/vbatts/git-validation + +.install.glide: + go get github.com/Masterminds/glide + +.install.glide-vc: + go get github.com/sgotti/glide-vc + +.install.gometalinter: + go get github.com/alecthomas/gometalinter + gometalinter --install --update + +.PHONY: \ + binaries \ + clean \ + lint