diff --git a/.travis.yml b/.travis.yml index 3088f432a02..034209a0ead 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,3 +59,20 @@ jobs: directories: - $HOME/.cache/go-build - $HOME/.gradle + - os: linux-diag + name: "Linux unit for diagnostic" + script: + - make make -f Makefile.diag coverage + cache: + directories: + - $HOME/.cache/go-build + - os: osx-diag + name: "OSX unit for diagnostic" + before_install: + - curl -Lo ${HOME}/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.5rc2/jq-osx-x86_64 + - chmod +x ${HOME}/bin/jq + script: + - make -f Makefile.diag test + cache: + directories: + - $HOME/.cache/go-build diff --git a/Makefile b/Makefile index 22671cd4905..e3833630e76 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,8 @@ GKE_ZONE ?= us-central1-a SUPPORTED_PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH) windows-$(GOARCH).exe BUILD_PACKAGE = $(REPOPATH)/cmd/skaffold +SKAFFOLD_TEST_PACKAGES := $(shell go list ./... | grep -v diag) + VERSION_PACKAGE = $(REPOPATH)/pkg/skaffold/version COMMIT = $(shell git rev-parse HEAD) @@ -64,7 +66,7 @@ GO_LDFLAGS_windows =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_windows)\"" GO_LDFLAGS_darwin =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_darwin)\"" GO_LDFLAGS_linux =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_linux)\"" -GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*") +GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/diag/*") DEPS_DIGEST := $(shell ./hack/skaffold-deps-sha1.sh) $(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) @@ -104,12 +106,12 @@ cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(pla .PHONY: test test: $(BUILD_DIR) - @ ./hack/gotest.sh -count=1 -race -short -timeout=90s ./... + @ ./hack/gotest.sh -count=1 -race -short -timeout=90s $(SKAFFOLD_TEST_PACKAGES) @ ./hack/checks.sh .PHONY: coverage coverage: $(BUILD_DIR) - @ ./hack/gotest.sh -count=1 -race -cover -short -timeout=90s -coverprofile=out/coverage.txt -coverpkg="./pkg/...,./cmd/..." ./... + @ ./hack/gotest.sh -count=1 -race -cover -short -timeout=90s -coverprofile=out/coverage.txt -coverpkg="./pkg/...,./cmd/..." $(SKAFFOLD_TEST_PACKAGES) @- curl -s https://codecov.io/bash > $(BUILD_DIR)/upload_coverage && bash $(BUILD_DIR)/upload_coverage .PHONY: checks @@ -118,7 +120,7 @@ checks: $(BUILD_DIR) .PHONY: quicktest quicktest: - @ ./hack/gotest.sh -short -timeout=60s ./... + @ ./hack/gotest.sh -short -timeout=60s $(SKAFFOLD_TEST_PACKAGES) .PHONY: install install: $(GO_FILES) $(BUILD_DIR) diff --git a/Makefile.diag b/Makefile.diag new file mode 100644 index 00000000000..eff6bd064c6 --- /dev/null +++ b/Makefile.diag @@ -0,0 +1,35 @@ +# Copyright 2020 The Skaffold Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +GOOS ?= $(shell go env GOOS) +GOARCH = amd64 +BUILD_DIR ?= ./out +ORG := github.com/GoogleContainerTools +PROJECT := diag +REPOPATH ?= $(ORG)/skaffold +VERSION_PACKAGE = $(REPOPATH)/pkg/diag/version + +TEST_PACKAGES := $(shell go list ./pkg/diag/...) + +# Force using Go Modules and always read the dependencies from +# the `vendor` folder. +export GO111MODULE = on +export GOFLAGS = -mod=vendor + +.PHONY: test +test: $(BUILD_DIR) + @ ./hack/gotest.sh -count=1 -race -short -timeout=90s $(TEST_PACKAGES) + +.PHONY: coverage +coverage: $(BUILD_DIR) + @ ./hack/gotest.sh -count=1 -race -cover -short -timeout=90s -coverprofile=out/coverage.txt $(TEST_PACKAGES) diff --git a/hack/gotest.sh b/hack/gotest.sh index 20d40f337ca..b3b9d490d1f 100755 --- a/hack/gotest.sh +++ b/hack/gotest.sh @@ -35,7 +35,12 @@ else JQ_FILTER='select(has("Output") and (.Action=="output") and (has("Test")|not) and (.Output!="PASS\n") and (.Output!="FAIL\n") and (.Output|startswith("coverage:")|not) and (.Output|contains("[no test files]")|not)) | .Output' fi -echo "go test $@" +if [ "$#" -le 6 ]; then + echo "go test $@" +else + echo "go test ./..." +fi + go test -json $@ | tee $LOG | jq --unbuffered -j "${JQ_FILTER}" | sed ''/FAIL/s//`printf "${RED}FAIL${RESET}"`/'' RESULT=${PIPESTATUS[0]} diff --git a/pkg/diag/version/version.go b/pkg/diag/version/version.go new file mode 100644 index 00000000000..4d20cad9e7b --- /dev/null +++ b/pkg/diag/version/version.go @@ -0,0 +1,50 @@ +/* +Copyright 2020 The Skaffold Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package version + +import ( + "strings" + + "github.com/blang/semver" +) + +// VersionPrefix is the prefix of the git tag for a version +const VersionPrefix = "v" + +// The current version of the minikube + +// version is a private field and should be set when compiling with --ldflags="-X github.com/GoogleContainerTools/skaffold/pkg/diag/version.version=vX.Y.Z" +var version = "v0.0.0-unset" + +// gitCommitID is a private field and should be set when compiling with --ldflags="-X github.com/GoogleContainerTool/pkg/diag/version.gitCommitID=" +var gitCommitID = "" + + +// GetVersion returns the current diag pkg version +func GetVersion() string { + return version +} + +// GetGitCommitID returns the git commit id from which it is being built +func GetGitCommitID() string { + return gitCommitID +} + + +// GetSemverVersion returns the current semantic version (semver) +func GetSemverVersion() (semver.Version, error) { + return semver.Make(strings.TrimPrefix(GetVersion(), VersionPrefix)) +} \ No newline at end of file diff --git a/pkg/diag/version/version_test.go b/pkg/diag/version/version_test.go new file mode 100644 index 00000000000..ca5fbe30f6e --- /dev/null +++ b/pkg/diag/version/version_test.go @@ -0,0 +1,32 @@ +/* +Copyright 2019 The Skaffold Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package version + +import ( + "github.com/blang/semver" + "testing" + + "github.com/GoogleContainerTools/skaffold/testutil" +) + +func TestGetSemverVersion(t *testing.T) { + + actual, err := GetSemverVersion() + expected, _ := semver.Make("0.0.0-unset") + + testutil.CheckErrorAndDeepEqual(t,false, err, expected, actual) +}