Skip to content

Commit

Permalink
Add pkg/diag
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed Feb 7, 2020
1 parent c6bbc3e commit 5506bee
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions Makefile.diag
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 6 additions & 1 deletion hack/gotest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]}

Expand Down
50 changes: 50 additions & 0 deletions pkg/diag/version/version.go
Original file line number Diff line number Diff line change
@@ -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=<commit-id>"
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))
}
32 changes: 32 additions & 0 deletions pkg/diag/version/version_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 5506bee

Please sign in to comment.