automatically get latest k3s version tag at build time

pull/12/head
iwilltry42 5 years ago
parent 9142529c62
commit 6fdc1e4a70
  1. 5
      Makefile
  2. 2
      main.go
  3. 8
      version/version.go

@ -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

@ -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{

@ -3,6 +3,9 @@ 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 {
@ -10,3 +13,8 @@ func GetVersion() string {
}
return Version
}
// GetK3sVersion returns the version string for K3s
func GetK3sVersion() string {
return K3sVersion
}

Loading…
Cancel
Save