diff options
| author | jannfis <jann@mistrust.net> | 2020-09-27 21:34:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-27 21:34:05 +0200 |
| commit | 881ad1bf523044f888eef8e5e69070481cdc4e97 (patch) | |
| tree | cb33ae5b26fabfd0bfbaec7b085c063fe1c1cc7a /pkg/version | |
| parent | fa95873da285ee00713e4041d117ad37f43d899e (diff) | |
chore: Externalize version & build information (#104)
* chore: Externalize version information
* Use full Git commit information
* Introduce short and long version information
* Typos
* More typos
Diffstat (limited to 'pkg/version')
| -rw-r--r-- | pkg/version/version.go | 45 | ||||
| -rw-r--r-- | pkg/version/version_test.go | 4 |
2 files changed, 34 insertions, 15 deletions
diff --git a/pkg/version/version.go b/pkg/version/version.go index 140b016..d9c405a 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,21 +1,20 @@ package version -import "fmt" - -const ( - majorVersion = "0" - minorVersion = "7" - patchVersion = "0" - preReleaseString = "master" +import ( + "fmt" + "runtime" + "time" ) -const binaryName = "argocd-image-updater" +var ( + version = "9.9.99" + buildDate = time.Now().UTC().Format(time.RFC3339) + gitCommit = "unknown" + binaryName = "argocd-image-updater" +) func Version() string { - version := fmt.Sprintf("v%s.%s.%s", majorVersion, minorVersion, patchVersion) - if preReleaseString != "" { - version += fmt.Sprintf("-%s", preReleaseString) - } + version := fmt.Sprintf("v%s+%s", version, gitCommit[0:7]) return version } @@ -24,5 +23,25 @@ func BinaryName() string { } func Useragent() string { - return fmt.Sprintf("%s %s", BinaryName(), Version()) + return fmt.Sprintf("%s: %s", BinaryName(), Version()) +} + +func GitCommit() string { + return gitCommit +} + +func BuildDate() string { + return buildDate +} + +func GoVersion() string { + return runtime.Version() +} + +func GoPlatform() string { + return runtime.GOOS + "/" + runtime.GOARCH +} + +func GoCompiler() string { + return runtime.Compiler } diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go index a68c88f..638daa4 100644 --- a/pkg/version/version_test.go +++ b/pkg/version/version_test.go @@ -12,9 +12,9 @@ func Test_BinaryName(t *testing.T) { } func Test_Version(t *testing.T) { - assert.Regexp(t, `^v[0-9]\.[0-9]\.[0-9](-[a-z]+)*$`, Version()) + assert.Regexp(t, `^v[0-9]+\.[0-9]+\.[0-9]+(\-[a-z]+)*(\+[a-z0-9]+)*$`, Version()) } func Test_Useragent(t *testing.T) { - assert.Regexp(t, `^[a-z\-]+\sv[0-9]\.[0-9]\.[0-9](-[a-z]+)*$`, Useragent()) + assert.Regexp(t, `^[a-z\-]+:\sv[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)*(\+[a-z0-9]+)*$`, Useragent()) } |
