From 38a995d7830827fd024140578b923de528376eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pereira?= Date: Wed, 6 Nov 2024 08:42:23 -0600 Subject: [PATCH] [v7] Provide default version based on latest tag in branch (#3285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Provide default version based on latest tag in branch Signed-off-by: João Pereira --- .github/workflows/tests-integration-reusable.yml | 1 + .github/workflows/tests-integration.yml | 1 + Makefile | 1 + version/version.go | 8 +++++++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests-integration-reusable.yml b/.github/workflows/tests-integration-reusable.yml index 6ddcb98e5f7..241d1df7c1e 100644 --- a/.github/workflows/tests-integration-reusable.yml +++ b/.github/workflows/tests-integration-reusable.yml @@ -37,6 +37,7 @@ jobs: uses: actions/checkout@v4 with: ref: ${{inputs.gitRef}} + fetch-depth: 0 - name: Checkout CF deployment tasks uses: actions/checkout@v4 diff --git a/.github/workflows/tests-integration.yml b/.github/workflows/tests-integration.yml index 42b59e6cee4..14a9ca2dfab 100644 --- a/.github/workflows/tests-integration.yml +++ b/.github/workflows/tests-integration.yml @@ -54,6 +54,7 @@ jobs: uses: actions/checkout@v4 with: ref: ${{needs.get-sha.outputs.gitRef}} + fetch-depth: 0 - name: Set Up Go uses: actions/setup-go@v5 with: diff --git a/Makefile b/Makefile index a62625cdb14..f0bbc5eaf57 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ NODES ?= 10 PACKAGES ?= api actor command types util version integration/helpers LC_ALL = "en_US.UTF-8" +CF_BUILD_VERSION ?= $$(git describe --tags --abbrev=0) CF_BUILD_SHA ?= $$(git rev-parse --short HEAD) CF_BUILD_DATE ?= $$(date -u +"%Y-%m-%d") LD_FLAGS_COMMON=-w -s \ diff --git a/version/version.go b/version/version.go index 47a77f878d5..4878c51b59a 100644 --- a/version/version.go +++ b/version/version.go @@ -1,6 +1,10 @@ package version -import "github.com/blang/semver/v4" +import ( + "strings" + + "github.com/blang/semver/v4" +) const DefaultVersion = "0.0.0-unknown-version" @@ -11,6 +15,8 @@ var ( ) func VersionString() string { + // Remove the "v" prefix from the binary in case it is present + binaryVersion = strings.TrimPrefix(binaryVersion, "v") versionString, err := semver.Make(binaryVersion) if err != nil { versionString = semver.MustParse(DefaultVersion)