From 6fdc1e4a705705c468ed4d3fd8e06b5be861e842 Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Tue, 23 Apr 2019 11:12:42 +0200 Subject: [PATCH] automatically get latest k3s version tag at build time --- Makefile | 5 ++++- main.go | 2 +- version/version.go | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6131ede4..b7b52c67 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/main.go b/main.go index 501d51de..c72529d8 100644 --- a/main.go +++ b/main.go @@ -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{ diff --git a/version/version.go b/version/version.go index 8fc22c07..f3b784a4 100644 --- a/version/version.go +++ b/version/version.go @@ -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 +}