Merge pull request #162 from helmfile/qtran/version-dev

on canary build, version should show "0.0.0-dev"
This commit is contained in:
yxxhero 2022-07-18 19:25:13 +08:00 committed by GitHub
commit eb0415b139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 1 deletions

View File

@ -19,7 +19,7 @@ func RootCommand() *cli.App {
cliApp := cli.NewApp() cliApp := cli.NewApp()
cliApp.Name = "helmfile" cliApp.Name = "helmfile"
cliApp.Usage = "" cliApp.Usage = ""
cliApp.Version = version.Version cliApp.Version = version.GetVersion()
cliApp.EnableBashCompletion = true cliApp.EnableBashCompletion = true
cliApp.Before = configureLogging cliApp.Before = configureLogging
setRootCommandFlags(cliApp) setRootCommandFlags(cliApp)

1
go.mod
View File

@ -32,6 +32,7 @@ require (
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
gotest.tools v2.2.0+incompatible
k8s.io/apimachinery v0.23.4 k8s.io/apimachinery v0.23.4
) )

View File

@ -1,5 +1,28 @@
// Package version is used to get the version of the Helmfile CLI. // Package version is used to get the version of the Helmfile CLI.
package version package version
import "fmt"
// Version is the version of Helmfile // Version is the version of Helmfile
var Version string var Version string
// Commit is the git revision
var Commit string
func GetVersion() string {
if Version == "" {
Version = "0.0.0-dev"
}
return Version
}
func GetCommit() string {
if Commit == "" {
Commit = "unknown_commit"
}
return Commit
}
func GetVersionWithCommit() string {
return fmt.Sprintf("%s-%s", GetVersion(), GetCommit())
}

View File

@ -0,0 +1,38 @@
package version
import (
"testing"
"gotest.tools/assert"
)
func TestGetVersion(t *testing.T) {
current := Version
Version = ""
assert.Equal(t, "0.0.0-dev", GetVersion())
Version = "1.2.3"
assert.Equal(t, "1.2.3", GetVersion())
Version = current
}
func TestGetCommit(t *testing.T) {
current := Commit
Commit = ""
assert.Equal(t, "unknown_commit", GetCommit())
Commit = "abc123xyz"
assert.Equal(t, "abc123xyz", GetCommit())
Commit = current
}
func TestGetVersionWithCommit(t *testing.T) {
currentVersion := Version
currentCommit := Commit
Version = ""
Commit = ""
assert.Equal(t, "0.0.0-dev-unknown_commit", GetVersionWithCommit())
Version = "1.2.3"
Commit = "abc123xyz"
assert.Equal(t, "1.2.3-abc123xyz", GetVersionWithCommit())
Version = currentVersion
Commit = currentCommit
}