From c8548960ba8b3af5a569daf1f878209ecc3c77c6 Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Mon, 13 Nov 2017 14:43:48 -0800 Subject: [PATCH] Simplify travis script, work against `vendor/` The current travis script currently fails if we have a `vendor/` directory, and is also quite longer than necessary. --- bin/pre-commit.sh | 53 ++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/bin/pre-commit.sh b/bin/pre-commit.sh index 9fd673c7a..c81e9ca08 100755 --- a/bin/pre-commit.sh +++ b/bin/pre-commit.sh @@ -1,46 +1,25 @@ #!/bin/bash -# Runs pre-commit tests. -# -# Instead of failing on first error, complete all checks, then fail if need be. -# Echo go's version to verify against go's behavior below. -# Different versions do different things with respect to vendored code. -go version +rc=0 -# Assert state. -if [ -n "$failIt" ]; then - echo "Expecting failIt to be empty." - exit 1 -fi +go_dirs() { + go list -f '{{.Dir}}' ./... | tr '\n' '\0' +} -wantEmpty=$(gofmt -s -d -l . 2>&1 ) -if [ -n "$wantEmpty" ]; then - printf >&2 '\ngofmt failed for:\n%s\n' "$wantEmpty" - failIt=1 -fi +echo "Running go fmt" +go_dirs | xargs -0 gofmt -s -d -l +rc=$((rc || $?)) -wantEmpty=$(goimports -l $(find . -type f -name '*.go' -not -path "./vendor/*") 2>&1) -if [ -n "$wantEmpty" ]; then - printf >&2 '\ngoimports failed for:\n%s\n' "$wantEmpty" - failIt=1 -fi +echo "Running goimports" +diff -u <(echo -n) <(go_dirs | xargs -0 goimports -l) +rc=$((rc || $?)) -wantEmpty=$(go vet -all ./... 2>&1) -if [ -n "$wantEmpty" ]; then - printf >&2 '\ngo vet failed for:\n%s\n' "$wantEmpty" - failIt=1 -fi - -wantEmpty=$(golint ./...) -if [ -n "$wantEmpty" ]; then - printf >&2 '\ngolint failed for:\n%s\n' "$wantEmpty" - failIt=1 -fi - -if [ -n "$failIt" ]; then - unset failIt - exit 1 -fi +echo "Running go vet" +go vet -all ./... +rc=$((rc || $?)) +echo "Running go test" go test -v ./... +rc=$((rc || $?)) +exit $rc