From 4dab6268daf784bb33021654c31bc47711924926 Mon Sep 17 00:00:00 2001 From: jregan Date: Sat, 9 Nov 2019 13:31:16 -0800 Subject: [PATCH] Less GOPATH dependence. --- travis/pre-commit.sh | 60 ++++++++++---------------------------------- 1 file changed, 13 insertions(+), 47 deletions(-) diff --git a/travis/pre-commit.sh b/travis/pre-commit.sh index f01c083d3..0b4aeec2b 100755 --- a/travis/pre-commit.sh +++ b/travis/pre-commit.sh @@ -38,6 +38,11 @@ function runUnitTests { make unit-test-all } +function onLinuxAndNotOnTravis { + [[ ("linux" == "$(go env GOOS)") && (-z ${TRAVIS+x}) ]] && return + false +} + function testExamplesAgainstLatestKustomizeRelease { removeBin kustomize @@ -49,7 +54,7 @@ function testExamplesAgainstLatestKustomizeRelease { --label testAgainstLatestRelease examples # TODO: make work for non-linux - if [[ (-z ${TRAVIS+x}) && ("linux" == "$(go env GOOS)") ]]; then + if onLinuxAndNotOnTravis; then echo "On linux, and not on travis, so running the notravis example tests." # Requires helm. @@ -74,53 +79,14 @@ function testExamplesAgainstLocalHead { echo "Example tests passed against HEAD" } -# This script tries to work for both travis -# and contributors who have or do not have -# GOPATH set. -# -# Use GOPATH to define XDG_CONFIG_HOME, then unset -# GOPATH so that go.mod is unambiguously honored. -# -function unsetGoPath { - local preferredGoPath=$GOPATH - if [ -z ${GOPATH+x} ]; then - # GOPATH is unset - local tmp=$HOME/gopath - if [ -d "$tmp" ]; then - preferredGoPath=$tmp - else - # this works even if GOPATH undefined. - preferredGoPath=$(go env GOPATH) - fi - else - unset GOPATH - fi +# Having this set might contradict the Makefile, +# so assure it's unset. +unset GOPATH - if [ -z ${GOPATH+x} ]; then - echo GOPATH is unset - else - echo "GOPATH=$GOPATH, but should be unset at this point." - exit 1 - fi - - # This is needed for plugins. - # TODO: switch this to set KUSTOMIZE_PLUGIN_HOME instead. - export XDG_CONFIG_HOME=$preferredGoPath/src/sigs.k8s.io - echo "XDG_CONFIG_HOME=$XDG_CONFIG_HOME" - if [ ! -d "$XDG_CONFIG_HOME" ]; then - echo "$XDG_CONFIG_HOME is not a directory." - echo "Unable to compile or otherwise work with kustomize plugins." - exit 1 - fi -} - -unsetGoPath - - -# With GOPATH now undefined, this most -# likely this puts $HOME/go/bin on the path. -# Regardless, subsequent go tool installs will -# be placing binaries in this location. +# With GOPATH now undefined, this most likely +# puts $HOME/go/bin on the path. Regardless, +# subsequent go tool installs will be placing +# binaries in this location. PATH=$(go env GOPATH)/bin:$PATH # Make sure we run in the root of the repo and