Skip to content

Commit

Permalink
refac(ci/scripts): centralize code and remove duplications
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Nov 13, 2019
1 parent 1705128 commit f8b626c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 65 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ services:

before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mkdir -p /Users/travis/gopath/bin; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then GO111MODULE=on scripts/install_and_setup.sh $KIND_K8S_VERSION; fi
- GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/[email protected]
- GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/[email protected]
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then scripts/setup.sh $KIND_K8S_VERSION; fi

before_script:

Expand All @@ -53,11 +51,13 @@ install:
-

script:
- GO111MODULE=on TRACE=1 ./golden_test.sh
- GO111MODULE=on TRACE=1 ./test.sh
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then GO111MODULE=on TRACE=1 PATH=$PATH:$(pwd) ./test_e2e_v1.sh ; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then GO111MODULE=on TRACE=1 PATH=$PATH:$(pwd) ./test_e2e_v2.sh ; fi
# The golden_test.sh check if the the testdata is updated according to the current changes
# To update the testdata use the Makefile targets `make generate-setup` then `make generate-testdata`
- ./golden_test.sh
- ./test.sh
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then PATH=$PATH:$(pwd) ./test_e2e.sh; fi

# TBD. Suppressing for now.
notifications:
email: false

11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/ku
GO111MODULE=on ./generate_golden.sh

.PHONY: generate-vendor
generate-vendor: ## (deprecated) - Update/generate the vendor by using the path $GOPATH/src/sigs.k8s.io/kubebuilder-test
generate-vendor: ## (Deprecated) Update/generate the vendor by using the path $GOPATH/src/sigs.k8s.io/kubebuilder-test
GO111MODULE=off ./generate_vendor.sh

.PHONY: generate-setup
Expand All @@ -68,12 +68,11 @@ generate-setup: ## Current workarround to generate the testdata with the correct
test: ## Run the go tests ($ go test -v ./cmd/... ./pkg/...)
go test -v ./cmd/... ./pkg/...

.PHONY: test-project-generation
test-project-generation: ## Run the unit tests (used in the CI)
- go get sigs.k8s.io/[email protected]
.PHONY: test-ci
test-ci: ## Run the unit tests (used in the CI)
./setup.sh
./test.sh

.PHONY: test-e2e
test-e2e: ## Run the integration tests (used in the CI)
./test_e2e_v1.sh
./test_e2e_v2.sh
./test_e2e.sh
3 changes: 3 additions & 0 deletions golden_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ set -o pipefail

source common.sh

export TRACE=1
export GO111MODULE=on

fetch_tools
install_go_dep
build_kb
Expand Down
4 changes: 4 additions & 0 deletions scripts/generate_dep_manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# depManifestOverride variable in cmd/kubebuilder/initproject/dep_manifest.go
#

########################################################################################################
# NOTE: It is deprecated since is valid just for version 1 #
########################################################################################################

tmp_file="/tmp/dep.txt"
dep status -json|jq '.[]|.ProjectRoot,.Revision, .Version' > $tmp_file
while read name ; do
Expand Down
5 changes: 5 additions & 0 deletions scripts/install_and_setup.sh → scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ K8S_VERSION=$1

export GO111MODULE=on

# setup go module to create the cluster
go get sigs.k8s.io/[email protected]

# You can use --image flag to specify the cluster version you want, e.g --image=kindest/node:v1.13.6, the supported version are listed at https://hub.docker.com/r/kindest/node/tags
kind create cluster --config test/kind-config.yaml --image=kindest/node:$K8S_VERSION

# setup the go modules required
go get sigs.k8s.io/controller-tools/cmd/[email protected]
go get sigs.k8s.io/kustomize/kustomize/[email protected]
9 changes: 7 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ set -o pipefail

source common.sh

export TRACE=1
export GO111MODULE=on

# This test is used by prow and if the dep not be installed by git then it will face the GOBIN issue.
install_dep_by_git

function test_init_project {
Expand Down Expand Up @@ -100,7 +104,7 @@ function test_project {
fi
cd testdata/$project_dir
# v2 uses modules, and thus doesn't have a vendor directory
[[ -e ${vendor_tarball} ]] && tar -zxf $vendor_tarball
[[ -e ${vendor_tarball} ]] && tar -zxf $vendor_tarball
make all test # v2 doesn't test on all by default
[[ -e ${vendor_tarball} ]] && rm -rf ./vendor && rm -f Gopkg.lock
cd -
Expand Down Expand Up @@ -153,11 +157,12 @@ export GO111MODULE=on
go test ./cmd/... ./pkg/...

# test project v1
# auto is roughly equivalent to off in our case,
# auto is roughly equivalent to off in our case,
# since we'll be in a gopath (basically, reset to default)
GO111MODULE=off test_project gopath/src/project 1

# test project v2
GO111MODULE=on test_project project-v2 2

exit $rc

19 changes: 0 additions & 19 deletions test_ci.sh

This file was deleted.

5 changes: 5 additions & 0 deletions test_e2e_v1.sh → test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ set -o pipefail

source common.sh

export TRACE=1
export GO111MODULE=on

fetch_tools
install_go_dep
build_kb
Expand All @@ -28,4 +31,6 @@ setup_envs
docker pull gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1
kind load docker-image gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1

# The v1 is deprecated
go test ./test/e2e/v1
go test ./test/e2e/v2
31 changes: 0 additions & 31 deletions test_e2e_v2.sh

This file was deleted.

0 comments on commit f8b626c

Please sign in to comment.