Skip to content

Commit

Permalink
versioning test
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickcping committed Aug 27, 2024
1 parent d2d8b84 commit 639bdaa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ builds:
flags:
- -trimpath
main: ./main.go
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
goos:
- freebsd
- windows
Expand Down
18 changes: 5 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ import (
"github.com/spf13/viper"
)

var (
// these will be set by the goreleaser configuration
// to appropriate values for the compiled binary
version string = "dev"

// goreleaser can also pass the specific commit if you want
commit string = ""
)

const (
jsonFilePathConfigKey = "jsonFilePath"
jsonFilePathParamNameLong = "export-file-path"
Expand Down Expand Up @@ -75,14 +66,15 @@ var rootCmd = &cobra.Command{

return nil
},
Version: fmt.Sprintf("%s-%s", version, commit),
}

func SetVersionInfo(version, commit string) {
rootCmd.Version = fmt.Sprintf("%s (Git Commit SHA %s)", version, commit)
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute(versionP, commitP string) {
version = versionP
commit = commitP
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ var (
version string = "dev"

// goreleaser can also pass the specific commit if you want
commit string = ""
commit string = "none"
)

func main() {
l := logger.Get()

l.Debug().Msg("Starting dvtf")

cmd.Execute(version, commit)
cmd.SetVersionInfo(version, commit)
cmd.Execute()
}

0 comments on commit 639bdaa

Please sign in to comment.