Skip to content

Commit

Permalink
automatically get latest k3s version tag at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Apr 23, 2019
1 parent 9142529 commit 6fdc1e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ ifeq ($(GIT_TAG),)
GIT_TAG := $(shell git describe --always)
endif

# get latest k3s version
K3S_TAG := $(shell curl --silent "https://api.github.com/repos/rancher/k3s/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

# Go options
GO ?= go
PKG := $(shell go mod vendor)
TAGS :=
TESTS := .
TESTFLAGS :=
LDFLAGS := -w -s -X github.com/rancher/k3d/version.Version=${GIT_TAG}
LDFLAGS := -w -s -X github.com/rancher/k3d/version.Version=${GIT_TAG} -X github.com/rancher/k3d/version.K3sVersion=${K3S_TAG}
GOFLAGS :=
BINDIR := $(CURDIR)/bin
BINARIES := k3d
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func main() {
},
cli.StringFlag{
Name: "version",
Value: "v0.4.0",
Value: version.GetK3sVersion(),
Usage: "Choose the k3s image version",
},
cli.IntFlag{
Expand Down
8 changes: 8 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ package version
// Version is the string that contains version
var Version string

// K3sVersion contains the latest version tag of K3s
var K3sVersion string

// GetVersion returns the version for cli, it gets it from "git describe --tags" or returns "dev" when doing simple go build
func GetVersion() string {
if len(Version) == 0 {
return "dev"
}
return Version
}

// GetK3sVersion returns the version string for K3s
func GetK3sVersion() string {
return K3sVersion
}

0 comments on commit 6fdc1e4

Please sign in to comment.