From 208da81a53a17bfdb6ac9bda0cc71dd05077d322 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Tue, 24 Oct 2017 16:05:55 -0700 Subject: [PATCH 01/15] Add travis CICD coverage. Also, rename "kexpand" to "kinflate" to ease pronunciation. --- pre-commit.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 pre-commit.sh diff --git a/pre-commit.sh b/pre-commit.sh new file mode 100755 index 000000000..33731b0bf --- /dev/null +++ b/pre-commit.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +if [ -n "$failIt" ]; then + echo "Expecting failIt to be empty." + exit 1 +fi + +tmp=$(gofmt -s -d -l . 2>&1 ) +if [ -n "$tmp" ]; then + printf >&2 'gofmt failed for:\n%s\n' "$tmp" + failIt=1 +fi + +tmp=$(goimports -l .) +if [ -n "$tmp" ]; then + printf >&2 'goimports failed for:\n%s\n' "$tmp" + failIt=1 +fi + +tmp=$(go vet -all ./... 2>&1) +if [ -n "$tmp" ]; then + printf >&2 'govet failed for:\n%s\n' "$tmp" + failIt=1 +fi + +tmp=$(golint ./...) +if [ -n "$tmp" ]; then + printf >&2 'golint failed for:\n%s\n' "$tmp" + failIt=1 +fi + +if [ -n "$failIt" ]; then + unset failIt + exit 1 +fi + +go test -v ./... From 4f0a99d509a410ab57df8d001e35966905b36816 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Wed, 25 Oct 2017 10:29:36 -0700 Subject: [PATCH 02/15] tweakprecommit --- pre-commit.sh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pre-commit.sh b/pre-commit.sh index 33731b0bf..8e3e11cd0 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -1,36 +1,36 @@ #!/bin/bash if [ -n "$failIt" ]; then - echo "Expecting failIt to be empty." + echo "Expecting failIt to be empty." exit 1 fi -tmp=$(gofmt -s -d -l . 2>&1 ) -if [ -n "$tmp" ]; then - printf >&2 'gofmt failed for:\n%s\n' "$tmp" - failIt=1 +wantEmpty=$(gofmt -s -d -l . 2>&1 ) +if [ -n "$wantEmpty" ]; then + printf >&2 'gofmt failed for:\n%s\n' "$wantEmpty" + failIt=1 fi -tmp=$(goimports -l .) -if [ -n "$tmp" ]; then - printf >&2 'goimports failed for:\n%s\n' "$tmp" - failIt=1 +wantEmpty=$(goimports -l .) +if [ -n "$wantEmpty" ]; then + printf >&2 'goimports failed for:\n%s\n' "$wantEmpty" + failIt=1 fi -tmp=$(go vet -all ./... 2>&1) -if [ -n "$tmp" ]; then - printf >&2 'govet failed for:\n%s\n' "$tmp" - failIt=1 +wantEmpty=$(go vet -all ./... 2>&1) +if [ -n "$wantEmpty" ]; then + printf >&2 'govet failed for:\n%s\n' "$wantEmpty" + failIt=1 fi -tmp=$(golint ./...) -if [ -n "$tmp" ]; then - printf >&2 'golint failed for:\n%s\n' "$tmp" - failIt=1 +wantEmpty=$(golint ./...) +if [ -n "$wantEmpty" ]; then + printf >&2 'golint failed for:\n%s\n' "$wantEmpty" + failIt=1 fi if [ -n "$failIt" ]; then - unset failIt + unset failIt exit 1 fi From af3e1d7b1bea23524cb614a99c37ddab915dc1b0 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Thu, 26 Oct 2017 16:12:13 -0700 Subject: [PATCH 03/15] Skip CICD build on markdown or doc changes. --- consider-early-travis-exit.sh | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 consider-early-travis-exit.sh diff --git a/consider-early-travis-exit.sh b/consider-early-travis-exit.sh new file mode 100644 index 000000000..2c090857c --- /dev/null +++ b/consider-early-travis-exit.sh @@ -0,0 +1,41 @@ +# Exits with status 0 if it can be determined that the +# current PR should not trigger all travis checks. +# +# This could be done with a "git ...|grep -vqE" oneliner +# but as travis triggering is refined it's useful to check +# travis logs to see how branch files were considered. +function consider-early-travis-exit { + if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + echo "Not a travis pull request." + return + fi + if [ -z "$TRAVIS_BRANCH" ]; then + echo "Unknown travis branch." + return + fi + echo "TRAVIS_BRANCH=$TRAVIS_BRANCH" + local branchFiles=$(git diff --name-only FETCH_HEAD...$TRAVIS_BRANCH) + local invisibles=0 + local triggers=0 + echo "Branch Files (X==invisible to travis):" + echo "---" + for fn in $branchFiles; do + if [[ "$fn" =~ (\.md$)|(^docs/) ]]; then + echo " X $fn" + let invisibles+=1 + else + echo " $fn" + let triggers+=1 + fi + done + echo "---" + printf >&2 "%6d files invisible to travis.\n" $invisibles + printf >&2 "%6d files trigger travis.\n" $triggers + if [ $triggers -eq 0 ]; then + echo "Exiting travis early." + # see https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh + travis_terminate 0 + fi +} +consider-early-travis-exit +unset -f consider-early-travis-exit From e46a805324297dcbb252a24531d09994cdae1112 Mon Sep 17 00:00:00 2001 From: jregan Date: Sat, 28 Oct 2017 13:47:12 -0700 Subject: [PATCH 04/15] Tweak travis early exit --- consider-early-travis-exit.sh | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/consider-early-travis-exit.sh b/consider-early-travis-exit.sh index 2c090857c..eea852bcf 100644 --- a/consider-early-travis-exit.sh +++ b/consider-early-travis-exit.sh @@ -6,25 +6,21 @@ # travis logs to see how branch files were considered. function consider-early-travis-exit { if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then - echo "Not a travis pull request." + echo "Unknown pull request." return fi - if [ -z "$TRAVIS_BRANCH" ]; then - echo "Unknown travis branch." - return - fi - echo "TRAVIS_BRANCH=$TRAVIS_BRANCH" - local branchFiles=$(git diff --name-only FETCH_HEAD...$TRAVIS_BRANCH) - local invisibles=0 - local triggers=0 - echo "Branch Files (X==invisible to travis):" + # Might use this to improve checks on multi-commit PRs. + echo "TRAVIS_COMMIT_RANGE=$TRAVIS_COMMIT_RANGE" + echo "Branch Files ('T'==trigger tests, ' '=ignore):" echo "---" - for fn in $branchFiles; do + local triggers=0 + local invisibles=0 + for fn in $(git diff --name-only HEAD origin/master); do if [[ "$fn" =~ (\.md$)|(^docs/) ]]; then - echo " X $fn" + echo " $fn" let invisibles+=1 else - echo " $fn" + echo " T $fn" let triggers+=1 fi done @@ -32,7 +28,7 @@ function consider-early-travis-exit { printf >&2 "%6d files invisible to travis.\n" $invisibles printf >&2 "%6d files trigger travis.\n" $triggers if [ $triggers -eq 0 ]; then - echo "Exiting travis early." + echo "No files triggered travis test, exiting early." # see https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh travis_terminate 0 fi From b9575a8eb77b4cf42ff0323167442295e0fb1959 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Fri, 17 Nov 2017 17:28:34 -0800 Subject: [PATCH 05/15] Tweak pre-commit to ignore vendor directory. --- pre-commit.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pre-commit.sh b/pre-commit.sh index 8e3e11cd0..9fd673c7a 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -1,5 +1,13 @@ #!/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 + +# Assert state. if [ -n "$failIt" ]; then echo "Expecting failIt to be empty." exit 1 @@ -7,25 +15,25 @@ fi wantEmpty=$(gofmt -s -d -l . 2>&1 ) if [ -n "$wantEmpty" ]; then - printf >&2 'gofmt failed for:\n%s\n' "$wantEmpty" + printf >&2 '\ngofmt failed for:\n%s\n' "$wantEmpty" failIt=1 fi -wantEmpty=$(goimports -l .) +wantEmpty=$(goimports -l $(find . -type f -name '*.go' -not -path "./vendor/*") 2>&1) if [ -n "$wantEmpty" ]; then - printf >&2 'goimports failed for:\n%s\n' "$wantEmpty" + printf >&2 '\ngoimports failed for:\n%s\n' "$wantEmpty" failIt=1 fi wantEmpty=$(go vet -all ./... 2>&1) if [ -n "$wantEmpty" ]; then - printf >&2 'govet failed for:\n%s\n' "$wantEmpty" + printf >&2 '\ngo vet failed for:\n%s\n' "$wantEmpty" failIt=1 fi wantEmpty=$(golint ./...) if [ -n "$wantEmpty" ]; then - printf >&2 'golint failed for:\n%s\n' "$wantEmpty" + printf >&2 '\ngolint failed for:\n%s\n' "$wantEmpty" failIt=1 fi @@ -35,3 +43,4 @@ if [ -n "$failIt" ]; then fi go test -v ./... + From beaadd7f04a87459425a120483902bef979b3d6d Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Mon, 13 Nov 2017 14:43:48 -0800 Subject: [PATCH 06/15] 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. --- pre-commit.sh | 53 ++++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/pre-commit.sh b/pre-commit.sh index 9fd673c7a..c81e9ca08 100755 --- a/pre-commit.sh +++ b/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 From 3ac8575ed87ed29bfa02011be71a23000706253e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20H=C3=B6rl?= Date: Wed, 29 Nov 2017 15:14:33 +0000 Subject: [PATCH 07/15] Make `pre-commit.sh` work with the test framework Eventually we want our framework to work nicely with just `go test`. To get there we need to - inject KUBE_ASSETS_DIR - make the framework work when run multiple times in parallel (port collitions, expose bound ports the the subject under test, ...) We decided to make sure our tests are run in sequence (and not in parallel to any other thing using etcd, for that matter) by making this explicit in the `pre-commit.sh` - for now. As soon as we are there, we can rollback the change to the `pre-commit.sh` end have the test framework be tested the same as everything else. [#153248975] --- pre-commit.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pre-commit.sh b/pre-commit.sh index c81e9ca08..fc519568e 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -19,7 +19,12 @@ go vet -all ./... rc=$((rc || $?)) echo "Running go test" -go test -v ./... +go list ./... | grep -vF pkg/framework/test | xargs go test -v +rc=$((rc || $?)) + +echo "Running test framework tests" +./pkg/framework/test/scripts/download-binaries.sh \ + && ./pkg/framework/test/scripts/run-tests.sh rc=$((rc || $?)) exit $rc From f229571edb21fcddb57eb751e6c5acf35376172a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20H=C3=B6rl?= Date: Wed, 29 Nov 2017 17:22:45 +0000 Subject: [PATCH 08/15] Install ginkgo --- pre-commit.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pre-commit.sh b/pre-commit.sh index fc519568e..c88607e48 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -23,7 +23,8 @@ go list ./... | grep -vF pkg/framework/test | xargs go test -v rc=$((rc || $?)) echo "Running test framework tests" -./pkg/framework/test/scripts/download-binaries.sh \ +go get github.com/onsi/ginkgo/ginkgo \ + && ./pkg/framework/test/scripts/download-binaries.sh \ && ./pkg/framework/test/scripts/run-tests.sh rc=$((rc || $?)) From aad4b1b3280e888aeb8b036c66008bd058ee45d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20H=C3=B6rl?= Date: Tue, 5 Dec 2017 13:23:15 +0000 Subject: [PATCH 09/15] Integrate test framework tests properly The test framework can now run properly with `go test` and we can remove - our test wrapper - special handling of tests for the test framewoek --- pre-commit.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pre-commit.sh b/pre-commit.sh index c88607e48..4ebd8824c 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -1,5 +1,13 @@ #!/bin/bash +# Make sure, we run in the root of the repo and +# therefore run the tests on all packages +base_dir="$( cd "$(dirname "$0")/.." && pwd )" +cd "$base_dir" || { + echo "Cannot cd to '$base_dir'. Aborting." >&2 + exit 1 +} + rc=0 go_dirs() { @@ -18,14 +26,12 @@ echo "Running go vet" go vet -all ./... rc=$((rc || $?)) -echo "Running go test" -go list ./... | grep -vF pkg/framework/test | xargs go test -v +echo "Installing test binaries" +./pkg/framework/test/scripts/download-binaries.sh rc=$((rc || $?)) -echo "Running test framework tests" -go get github.com/onsi/ginkgo/ginkgo \ - && ./pkg/framework/test/scripts/download-binaries.sh \ - && ./pkg/framework/test/scripts/run-tests.sh +echo "Running go test" +go test -v ./... rc=$((rc || $?)) exit $rc From 9344d3610acdcc1880a091db48d5d23f9d0d070a Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Tue, 16 Jan 2018 09:15:55 -0800 Subject: [PATCH 10/15] pre-commit: Check gofmt output for errors gofmt doesn't return an error exit code when it fails (because some files are improperly formatted). Make sure that the output is empty instead. --- pre-commit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-commit.sh b/pre-commit.sh index 4ebd8824c..d541eff4c 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -15,7 +15,7 @@ go_dirs() { } echo "Running go fmt" -go_dirs | xargs -0 gofmt -s -d -l +diff <(echo -n) <(go_dirs | xargs -0 gofmt -s -d -l) rc=$((rc || $?)) echo "Running goimports" From 5a1052f6b14eda006385c88afdcb5c9edf6844c4 Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Thu, 25 Jan 2018 09:07:45 -0800 Subject: [PATCH 11/15] Don't fetch fw/test binary anymore --- pre-commit.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pre-commit.sh b/pre-commit.sh index d541eff4c..9824c3c4e 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -26,10 +26,6 @@ echo "Running go vet" go vet -all ./... rc=$((rc || $?)) -echo "Installing test binaries" -./pkg/framework/test/scripts/download-binaries.sh -rc=$((rc || $?)) - echo "Running go test" go test -v ./... rc=$((rc || $?)) From a90a3cff3aac8f2661ae706fcf55d740c16e34a1 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Fri, 9 Feb 2018 16:36:53 -0800 Subject: [PATCH 12/15] add demo testing --- pre-commit.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pre-commit.sh b/pre-commit.sh index 9824c3c4e..551c65954 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -30,4 +30,8 @@ echo "Running go test" go test -v ./... rc=$((rc || $?)) +echo "Testing kinflate demos" +mdrip --mode test --label test ./cmd/kinflate +rc=$((rc || $?)) + exit $rc From 824b51eb84ea2d90bbe81437583b3d0a18d25126 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Tue, 13 Feb 2018 13:20:03 -0800 Subject: [PATCH 13/15] Make test failures easier to see and understand. --- pre-commit.sh | 51 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/pre-commit.sh b/pre-commit.sh index 551c65954..4774736d9 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -10,28 +10,47 @@ cd "$base_dir" || { rc=0 -go_dirs() { +function go_dirs { go list -f '{{.Dir}}' ./... | tr '\n' '\0' } -echo "Running go fmt" -diff <(echo -n) <(go_dirs | xargs -0 gofmt -s -d -l) -rc=$((rc || $?)) +function runTest { + local name=$1 + local result="SUCCESS" + printf "============== begin %s\n" "$name" + $name + local code=$? + rc=$((rc || $code)) + if [ $code -ne 0 ]; then + result="FAILURE" + fi + printf "============== end %s : %s code=%d\n\n\n" "$name" "$result" $code +} -echo "Running goimports" -diff -u <(echo -n) <(go_dirs | xargs -0 goimports -l) -rc=$((rc || $?)) +function testGoFmt { + diff <(echo -n) <(go_dirs | xargs -0 gofmt -s -d -l) +} -echo "Running go vet" -go vet -all ./... -rc=$((rc || $?)) +function testGoImports { + diff -u <(echo -n) <(go_dirs | xargs -0 goimports -l) +} -echo "Running go test" -go test -v ./... -rc=$((rc || $?)) +function testGoVet { + go vet -all ./... +} -echo "Testing kinflate demos" -mdrip --mode test --label test ./cmd/kinflate -rc=$((rc || $?)) +function testGoTest { + go test -v ./... +} + +function testTutorial { + mdrip --mode test --label test ./cmd/kinflate +} + +runTest testGoFmt +runTest testGoImports +runTest testGoVet +runTest testGoTest +runTest testTutorial exit $rc From cff6a528d407837c6ef55e9fc5475aeac5f9d2a1 Mon Sep 17 00:00:00 2001 From: Jingfang Liu Date: Tue, 10 Apr 2018 14:32:02 -0700 Subject: [PATCH 14/15] change kinflate to kustomize --- pre-commit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-commit.sh b/pre-commit.sh index 4774736d9..044720b4a 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -44,7 +44,7 @@ function testGoTest { } function testTutorial { - mdrip --mode test --label test ./cmd/kinflate + mdrip --mode test --label test ./cmd/kustomize } runTest testGoFmt From e01ba34e8de5f31ac979e84b2a1bb4a36bd358ae Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Fri, 11 May 2018 14:01:20 -0700 Subject: [PATCH 15/15] Isolated content of bin --- .../consider-early-travis-exit.sh | 0 pre-commit.sh => bin/pre-commit.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename consider-early-travis-exit.sh => bin/consider-early-travis-exit.sh (100%) rename pre-commit.sh => bin/pre-commit.sh (100%) diff --git a/consider-early-travis-exit.sh b/bin/consider-early-travis-exit.sh similarity index 100% rename from consider-early-travis-exit.sh rename to bin/consider-early-travis-exit.sh diff --git a/pre-commit.sh b/bin/pre-commit.sh similarity index 100% rename from pre-commit.sh rename to bin/pre-commit.sh