From c9b5cedbe9f103862c2ff519c7c491f5373a75e6 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 23 Apr 2018 16:45:49 +0100 Subject: [PATCH] Presubmit (#1719) * build: add presubmits We didn't have a way to encode presubmit; with this hack we can just run a bunch of script on the build; this allows us to automatically capture things like using the wrong context and maybe other fluff. This allows us to cut down on code reviews and just have the build fail. * hook it up * put presubmit in checks; so we do it for tests as well * Add explicit exit 1 if things fails --- .presubmit/context | 8 ++++++++ Makefile | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100755 .presubmit/context diff --git a/.presubmit/context b/.presubmit/context new file mode 100755 index 000000000..b7d6ef971 --- /dev/null +++ b/.presubmit/context @@ -0,0 +1,8 @@ +#!/bin/bash + +echo "** presubmit/$(basename $0)" + +if grep -lr "golang.org/x/net/context" "$@"; then + echo "** presubmit/$(basename $0): please use std lib's 'context' instead" + exit 1 +fi diff --git a/Makefile b/Makefile index 6b06cd8f2..4c52b7717 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ SYSTEM:= CHECKS:=check godeps VERBOSE:=-v GOPATH?=$(HOME)/go +PRESUBMIT:=core coremain plugin all: coredns @@ -13,7 +14,7 @@ coredns: $(CHECKS) CGO_ENABLED=0 $(SYSTEM) go build $(VERBOSE) -ldflags="-s -w -X github.com/coredns/coredns/coremain.GitCommit=$(GITCOMMIT)" -o $(BINARY) .PHONY: check -check: linter goimports core/zplugin.go core/dnsserver/zdirectives.go godeps +check: presubmit linter goimports core/zplugin.go core/dnsserver/zdirectives.go godeps .PHONY: test test: check @@ -87,6 +88,11 @@ linter: goimports: ( gometalinter --deadline=2m --disable-all --enable=goimports --vendor --exclude=^pb/ ./... || true ) +# Presubmit runs all scripts in .presubmit; any non 0 exit code will fail the build. +.PHONY: presubmit +presubmit: + @for pre in $(PWD)/.presubmit/* ; do "$$pre" $(PRESUBMIT); done + .PHONY: clean clean: go clean