Skip to content

Commit

Permalink
changes requested on review
Browse files Browse the repository at this point in the history
  • Loading branch information
facuMH committed Jan 16, 2025
1 parent ae06fc3 commit ca0da37
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sonicd:
go build \
-ldflags "-s -w -X github.com/Fantom-foundation/go-opera/config.GitCommit=$${GIT_COMMIT} \
-X github.com/Fantom-foundation/go-opera/config.GitDate=$${GIT_DATE} \
-X github.com/Fantom-foundation/go-opera/version.GitTag=$${GIT_TAG}" \
-X github.com/Fantom-foundation/go-opera/version.Version=$${GIT_TAG}" \
-o build/sonicd \
./cmd/sonicd && \
./build/sonicd version
Expand All @@ -24,7 +24,7 @@ sonictool:
go build \
-ldflags "-s -w -X github.com/Fantom-foundation/go-opera/config.GitCommit=$${GIT_COMMIT} \
-X github.com/Fantom-foundation/go-opera/config.GitDate=$${GIT_DATE} \
-X github.com/Fantom-foundation/go-opera/version.GitTag=$${GIT_TAG}" \
-X github.com/Fantom-foundation/go-opera/version.Version=$${GIT_TAG}" \
-o build/sonictool \
./cmd/sonictool && \
./build/sonictool --version
Expand Down
25 changes: 7 additions & 18 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,8 @@ import (
"strings"
)

var (
GitTag = "" // Git tag of this release
versionMajor = 0 // Major version component of the current release
versionMinor = 0 // Minor version component of the current release
versionPatch = 0 // Patch version component of the current release
versionMeta = "" // Meta information of the current release
)

// Version holds the textual version string.
var Version = func() string {
// in case of no tag or small/irregular tag, return it as is
if len(GitTag) < 2 {
return GitTag
}
versionMajor, versionMinor, versionPatch, versionMeta = parseVersion(GitTag)
return GitTag
}()
var Version = ""

// parseVersion parses the GitTag into major, minor, patch, and meta components.
func parseVersion(gitTag string) (vMajor, vMinor, vPatch int, vMeta string) {
Expand Down Expand Up @@ -64,21 +49,25 @@ func parseVersionComponent(parts []string, index int, stripPrefix bool) int {
}

func VersionWithCommit(gitCommit, gitDate string) string {
vsn := GitTag
vsn := Version
if len(gitCommit) >= 8 {
vsn += "-" + gitCommit[:8]
}
if (strings.Split(GitTag, "-")[0] != "") && (gitDate != "") {
if (strings.Split(Version, "-")[0] != "") && (gitDate != "") {
vsn += "-" + gitDate
}
return vsn
}

func AsString() string {
// meta is not used for now, so we ignore it.
versionMajor, versionMinor, versionPatch, _ := parseVersion(Version)
return ToString(uint16(versionMajor), uint16(versionMinor), uint16(versionPatch))
}

func AsU64() uint64 {
// meta is not used for now, so we ignore it.
versionMajor, versionMinor, versionPatch, _ := parseVersion(Version)
return ToU64(uint16(versionMajor), uint16(versionMinor), uint16(versionPatch))
}

Expand Down
18 changes: 5 additions & 13 deletions version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,12 @@ func TestVersion_parseVersion(t *testing.T) {
"myTestTag": {},
}

originalGitTag := GitTag
for tag, want := range tests {
versionMajor = 0
versionMinor = 0
versionPatch = 0
versionMeta = ""
testVMajor, testVMinor, testVPatch, testVMeta := parseVersion(tag)

versionMajor, versionMinor, versionPatch, versionMeta = parseVersion(tag)

require.Equal(want.major, versionMajor, "major version mismatch")
require.Equal(want.minor, versionMinor, "minor version mismatch")
require.Equal(want.patch, versionPatch, "patch version mismatch")
require.Equal(want.meta, versionMeta, "meta version mismatch")
require.Equal(want.major, testVMajor, "major version mismatch")
require.Equal(want.minor, testVMinor, "minor version mismatch")
require.Equal(want.patch, testVPatch, "patch version mismatch")
require.Equal(want.meta, testVMeta, "meta version mismatch")
}

GitTag = originalGitTag
}

0 comments on commit ca0da37

Please sign in to comment.