Skip to content

Commit

Permalink
Set version based on git tags.
Browse files Browse the repository at this point in the history
Signed-off-by: Lantao Liu <[email protected]>
  • Loading branch information
Random-Liu committed Jul 11, 2018
1 parent 3bf77bf commit 60ed6e6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ PATH := $(GOBINDIR)/bin:$(PATH)
GOPKGDIR := $(GOPATH)/src/$(PROJECT)
GOPKGBASEDIR := $(shell dirname "$(GOPKGDIR)")

VERSION := $(shell git describe --tags --dirty --always)
VERSION := $(VERSION:v%=%)
GO_LDFLAGS := -X $(PROJECT)/pkg/version.Version=$(VERSION)

all: binaries

Expand All @@ -45,11 +48,13 @@ endif

critest: check-gopath
CGO_ENABLED=0 $(GO) test -c \
-ldflags '$(GO_LDFLAGS)' \
$(PROJECT)/cmd/critest \
-o $(GOBINDIR)/bin/critest

crictl: check-gopath
CGO_ENABLED=0 $(GO) install \
-ldflags '$(GO_LDFLAGS)' \
$(PROJECT)/cmd/crictl

clean:
Expand All @@ -58,8 +63,10 @@ clean:

cross: check-gopath
GOOS=windows $(GO) test -c -o $(CURDIR)/_output/critest.exe \
-ldflags '$(GO_LDFLAGS)' \
$(PROJECT)/cmd/critest
GOOS=windows $(GO) build -o $(CURDIR)/_output/crictl.exe \
-ldflags '$(GO_LDFLAGS)' \
$(PROJECT)/cmd/crictl

binaries: critest crictl
Expand Down
5 changes: 3 additions & 2 deletions cmd/crictl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ import (
"k8s.io/kubernetes/pkg/kubelet/apis/cri"
"k8s.io/kubernetes/pkg/kubelet/remote"
"k8s.io/kubernetes/pkg/kubelet/util"

"github.com/kubernetes-incubator/cri-tools/pkg/version"
)

const (
defaultConfigPath = "/etc/crictl.yaml"
defaultTimeout = 10 * time.Second
crictlVersion = "1.11.0"
)

var (
Expand Down Expand Up @@ -97,7 +98,7 @@ func main() {
app := cli.NewApp()
app.Name = "crictl"
app.Usage = "client for CRI"
app.Version = crictlVersion
app.Version = version.Version

app.Commands = []cli.Command{
runtimeAttachCommand,
Expand Down
5 changes: 2 additions & 3 deletions cmd/critest/cri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/onsi/gomega"

"github.com/kubernetes-incubator/cri-tools/pkg/framework"
versionconst "github.com/kubernetes-incubator/cri-tools/pkg/version"

_ "github.com/kubernetes-incubator/cri-tools/pkg/benchmark"
_ "github.com/kubernetes-incubator/cri-tools/pkg/validate"
Expand All @@ -41,8 +42,6 @@ const (
parallelFlag = "parallel"
benchmarkFlag = "benchmark"
versionFlag = "version"

criTestVersion = "1.11.0"
)

var (
Expand Down Expand Up @@ -125,7 +124,7 @@ func runParallelTestSuite(t *testing.T) {

func TestCRISuite(t *testing.T) {
if *version {
fmt.Printf("critest version: %s\n", criTestVersion)
fmt.Printf("critest version: %s\n", versionconst.Version)
return
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2018 The Kubernetes 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

// Version holds the complete version number. Filled in at linking time.
var Version = "1.11.0+unknown"

0 comments on commit 60ed6e6

Please sign in to comment.