diff --git a/.travis.yml b/.travis.yml index 15b0f1b2c..a68a37275 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ install: true script: - ./travis/verify-deps.sh - - ./travis/pre-commit.sh + - make verify-kustomize - ./travis/kyaml-pre-commit.sh # TBD. Suppressing for now. diff --git a/Makefile b/Makefile index e6ab1db28..d6bc424cf 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,21 @@ -# This Makefile is (and must be) used by -# travis/pre-commit.sh to qualify pull requests. +# Copyright 2019 The Kubernetes Authors. +# SPDX-License-Identifier: Apache-2.0 # -# That script generates all the code that needs -# to be generated, and runs all the tests. -# -# Functionality in that script is gradually moving here. +# Makefile for the kustomize repo. MYGOBIN := $(shell go env GOPATH)/bin PATH := $(PATH):$(MYGOBIN) SHELL := env PATH=$(PATH) /bin/bash .PHONY: all -all: pre-commit +all: verify-kustomize -# The pre-commit.sh script generates, lints and tests. -# It uses this makefile. For more clarity, would like -# to stop that - any scripts invoked by targets here -# shouldn't "call back" to the makefile. -.PHONY: pre-commit -pre-commit: - ./travis/pre-commit.sh +.PHONY: verify-kustomize +verify-kustomize: \ + lint-kustomize \ + test-unit-kustomize-all \ + test-examples-kustomize-against-HEAD \ + test-examples-kustomize-against-latest # Version pinned by api/go.mod $(MYGOBIN)/golangci-lint: @@ -46,6 +42,11 @@ $(MYGOBIN)/pluginator: cd api; \ go install sigs.k8s.io/kustomize/pluginator/v2 +# Install kustomize from whatever is checked out. +$(MYGOBIN)/kustomize: + cd kustomize; \ + go install . + .PHONY: install-tools install-tools: \ $(MYGOBIN)/goimports \ @@ -72,8 +73,8 @@ builtinplugins = \ api/builtins/replicacounttransformer.go \ api/builtins/secretgenerator.go -.PHONY: lint -lint: install-tools $(builtinplugins) +.PHONY: lint-kustomize +lint-kustomize: install-tools $(builtinplugins) cd api; $(MYGOBIN)/golangci-lint run ./... cd kustomize; $(MYGOBIN)/golangci-lint run ./... cd pluginator; $(MYGOBIN)/golangci-lint run ./... @@ -85,23 +86,36 @@ api/builtins/%.go: $(MYGOBIN)/pluginator cd ../../../api/builtins; \ $(MYGOBIN)/goimports -w $*.go -.PHONY: generate -generate: $(builtinplugins) - -.PHONY: unit-test-api -unit-test-api: $(builtinplugins) +.PHONY: test-unit-kustomize-api +test-unit-kustomize-api: $(builtinplugins) cd api; go test ./... -.PHONY: unit-test-plugins -unit-test-plugins: - ./hack/runPluginUnitTests.sh +.PHONY: test-unit-kustomize-plugins +test-unit-kustomize-plugins: + ./hack/testUnitKustomizePlugins.sh -.PHONY: unit-test-kustomize -unit-test-kustomize: +.PHONY: test-unit-kustomize-cli +test-unit-kustomize-cli: cd kustomize; go test ./... -.PHONY: unit-test-all -unit-test-all: unit-test-api unit-test-kustomize unit-test-plugins +.PHONY: test-unit-kustomize-all +test-unit-kustomize-all: \ + test-unit-kustomize-api \ + test-unit-kustomize-cli \ + test-unit-kustomize-plugins + +.PHONY: +test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip + ./hack/testExamplesAgainstKustomize.sh HEAD + +.PHONY: +test-examples-kustomize-against-latest: $(MYGOBIN)/mdrip + /bin/rm -f $(MYGOBIN)/kustomize; \ + echo "Installing kustomize from latest."; \ + go install sigs.k8s.io/kustomize/kustomize/v3; \ + ./hack/testExamplesAgainstKustomize.sh latest; \ + echo "Reinstalling kustomize from HEAD."; \ + cd kustomize; go install . # linux only. # This is for testing an example plugin that @@ -133,6 +147,7 @@ $(MYGOBIN)/helm: clean: rm -f $(builtinplugins) rm -f $(MYGOBIN)/pluginator + rm -f $(MYGOBIN)/kustomize .PHONY: nuke nuke: clean diff --git a/hack/testExamplesAgainstKustomize.sh b/hack/testExamplesAgainstKustomize.sh new file mode 100755 index 000000000..eb186cc40 --- /dev/null +++ b/hack/testExamplesAgainstKustomize.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# Copyright 2019 The Kubernetes Authors. +# SPDX-License-Identifier: Apache-2.0 + +set -o nounset +set -o errexit +set -o pipefail + +version=$1 + +function onLinuxAndNotOnTravis { + [[ ("linux" == "$(go env GOOS)") && (-z ${TRAVIS+x}) ]] && return + false +} + +# TODO: change the label? +# We test against the latest release, and HEAD, and presumably +# any branch using this label, so it should probably get +# a new value. +mdrip --mode test \ + --label testAgainstLatestRelease examples + +# TODO: make work for non-linux +if onLinuxAndNotOnTravis; then + echo "On linux, and not on travis, so running the notravis example tests." + + # Requires helm. + make $(go env GOPATH)/bin/helm + mdrip --mode test \ + --label helmtest examples/chart.md +fi + +echo "Example tests passed against ${version}." diff --git a/hack/runPluginUnitTests.sh b/hack/testUnitKustomizePlugins.sh similarity index 95% rename from hack/runPluginUnitTests.sh rename to hack/testUnitKustomizePlugins.sh index 80a77bcc1..99ba361ac 100755 --- a/hack/runPluginUnitTests.sh +++ b/hack/testUnitKustomizePlugins.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash +# # Copyright 2019 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -# TODO: get rid of this script, make individual targets -# in the makefile. - # Run this script with no arguments from the repo root # to test all the plugins. diff --git a/travis/pre-commit.sh b/travis/pre-commit.sh deleted file mode 100755 index 57e2d61e7..000000000 --- a/travis/pre-commit.sh +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash -set -e - -# Tracks success or failure of various operations. -# 0==success, any other value is a failure. -rcAccumulator=0 - -function removeBin { - local d=$(go env GOPATH)/bin/$1 - echo "Removing binary $d" - /bin/rm -f $d -} - -function installTools { - make install-tools - ls -C1 -g -G -h $(go env GOPATH)/bin -} - -function runFunc { - local name=$1 - local result="SUCCESS" - printf "============== begin %s\n" "$name" - $name - local code=$? - rcAccumulator=$((rcAccumulator || $code)) - if [ $code -ne 0 ]; then - result="FAILURE" - fi - printf "============== end %s : %s; exit code=%d\n\n\n" "$name" "$result" $code -} - -function runLint { - make lint -} - -function runUnitTests { - make unit-test-all -} - -function onLinuxAndNotOnTravis { - [[ ("linux" == "$(go env GOOS)") && (-z ${TRAVIS+x}) ]] && return - false -} - -function testExamplesAgainstLatestKustomizeRelease { - removeBin kustomize - - local latest=sigs.k8s.io/kustomize/kustomize/v3 - echo "Installing latest kustomize from $latest" - (cd ~; GO111MODULE=on go install $latest) - - mdrip --mode test \ - --label testAgainstLatestRelease examples - - # TODO: make work for non-linux - if onLinuxAndNotOnTravis; then - echo "On linux, and not on travis, so running the notravis example tests." - - # Requires helm. - make $(go env GOPATH)/bin/helm - mdrip --mode test \ - --label helmtest examples/chart.md - fi - echo "Example tests passed against $latest" -} - -function testExamplesAgainstLocalHead { - removeBin kustomize - - echo "Installing kustomize from HEAD" - (cd kustomize; go install .) - - # To test examples of unreleased features, add - # examples with code blocks annotated with some - # label _other than_ @testAgainstLatestRelease. - mdrip --mode test \ - --label testAgainstLatestRelease examples - echo "Example tests passed against HEAD" -} - - -# Don't override go's notion of where to -# install stuff. -unset GOPATH - -# Ease running the tooling installed by 'go'; -# mdrip, pluginator, stringer, etc. -PATH=$(go env GOPATH)/bin:$PATH - -# Assure that this script runs from the repo -# root, since some tests might rely on it. -base_dir="$( cd "$(dirname "$0")/.." && pwd )" -cd "$base_dir" || { - echo "Cannot cd to '$base_dir'. Aborting." >&2 - exit 1 -} - -echo "HOME = $HOME" -echo "PATH = $PATH" -echo " PWD = $PWD" -echo " " -echo "Working..." - -runFunc installTools -runFunc runLint -runFunc runUnitTests -runFunc testExamplesAgainstLatestKustomizeRelease -runFunc testExamplesAgainstLocalHead - -if [ $rcAccumulator -eq 0 ]; then - echo "SUCCESS!" -else - echo "FAILURE; exit code $rcAccumulator" -fi - -exit $rcAccumulator