Skip to content

Commit

Permalink
Provide default version based on latest tag in branch
Browse files Browse the repository at this point in the history
Signed-off-by: João Pereira <joao.pereira@broadcom.com>
  • Loading branch information
joaopapereira committed Nov 4, 2024
1 parent 2353f30 commit d9886d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
10 changes: 9 additions & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package version

import "github.com/blang/semver/v4"
import (
"fmt"
"strings"

"github.com/blang/semver/v4"
)

const DefaultVersion = "0.0.0-unknown-version"

Expand All @@ -11,8 +16,11 @@ 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 {
fmt.Printf("%s - error: %s\n", binaryVersion, err)
versionString = semver.MustParse(DefaultVersion)
}

Expand Down

0 comments on commit d9886d9

Please sign in to comment.