Skip to content

Commit dd2e812

Browse files
[main] Provide default version based on latest tag in branch (#3283)
* Provide default version based on latest tag in branch * Full depth retrieval Signed-off-by: João Pereira <joao.pereira@broadcom.com> --------- Signed-off-by: João Pereira <joao.pereira@broadcom.com>
1 parent a3d74bb commit dd2e812

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

.github/workflows/tests-integration-reusable.yml

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
uses: actions/checkout@v4
5151
with:
5252
ref: ${{inputs.gitRef}}
53+
fetch-depth: 0
5354

5455
- name: Checkout cf-acceptance-tests
5556
if: ${{ inputs.name == 'cats' }}

.github/workflows/tests-integration.yml

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ jobs:
104104
if: ${{ inputs.run_unit_tests || inputs.run_unit_tests == '' }}
105105
with:
106106
ref: ${{needs.get-sha.outputs.gitRef}}
107+
fetch-depth: 0
107108
- name: Set Up Go
108109
uses: actions/setup-go@v5
109110
if: ${{ inputs.run_unit_tests || inputs.run_unit_tests == '' }}

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ FLAKE_ATTEMPTS ?=5
44
PACKAGES ?= api actor command types util version integration/helpers
55
LC_ALL = "en_US.UTF-8"
66

7+
CF_BUILD_VERSION ?= $$(git describe --tags --abbrev=0)
78
CF_BUILD_SHA ?= $$(git rev-parse --short HEAD)
89
CF_BUILD_DATE ?= $$(date -u +"%Y-%m-%d")
910
LD_FLAGS_COMMON=-w -s \

version/version.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package version
22

3-
import "github.com/blang/semver/v4"
3+
import (
4+
"strings"
5+
6+
"github.com/blang/semver/v4"
7+
)
48

59
const DefaultVersion = "0.0.0-unknown-version"
610

@@ -11,6 +15,8 @@ var (
1115
)
1216

1317
func VersionString() string {
18+
// Remove the "v" prefix from the binary in case it is present
19+
binaryVersion = strings.TrimPrefix(binaryVersion, "v")
1420
versionString, err := semver.Make(binaryVersion)
1521
if err != nil {
1622
versionString = semver.MustParse(DefaultVersion)

0 commit comments

Comments
 (0)