From af45591c25abdc96899e67246df3ec55f94dcbae Mon Sep 17 00:00:00 2001 From: Mike Dame Date: Tue, 31 May 2022 17:29:25 +0000 Subject: [PATCH] Fix version command to parse helm chart tags --- Makefile | 2 +- pkg/version/version.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 871dd618ad..a76bc7935b 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ .PHONY: test # VERSION is based on a date stamp plus the last commit -VERSION?=v$(shell date +%Y%m%d)-$(shell git describe --tags --match "v*") +VERSION?=v$(shell date +%Y%m%d)-$(shell git describe --tags) BRANCH?=$(shell git branch --show-current) SHA1?=$(shell git rev-parse HEAD) BUILD=$(shell date +%FT%T%z) diff --git a/pkg/version/version.go b/pkg/version/version.go index 0325d775b7..20acac3dc6 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -80,9 +80,19 @@ func splitVersion(version string) (string, string) { // Version from an automated container build environment(not a tag) or a local build. For example v20201009-v0.18.0-46-g939c1c0. m2, _ := regexp.MatchString(`^v\d{8}-v\d+\.\d+\.\d+-\w+-\w+$`, version) + // Version tagged by helm chart releaser action + helm, _ := regexp.MatchString(`^v\d{8}-descheduler-helm-chart-\d+\.\d+\.\d+$`, version) + // Dirty version where helm chart is the last known tag + helm2, _ := regexp.MatchString(`^v\d{8}-descheduler-helm-chart-\d+\.\d+\.\d+-\w+-\w+$`, version) + if m1 || m2 { semVer := strings.Split(version, "-")[1] - return strings.Trim(strings.Split(semVer, ".")[0], "v"), strings.Split(semVer, ".")[1] + "+" + return strings.Trim(strings.Split(semVer, ".")[0], "v"), strings.Split(semVer, ".")[1] + "." + strings.Split(semVer, ".")[2] + } + + if helm || helm2 { + semVer := strings.Split(version, "-")[4] + return strings.Split(semVer, ".")[0], strings.Split(semVer, ".")[1] + "." + strings.Split(semVer, ".")[2] } // Something went wrong