Skip to content

Commit

Permalink
fix: stop relying on goreleaser for version
Browse files Browse the repository at this point in the history
  • Loading branch information
tnyeanderson committed May 1, 2024
1 parent e105846 commit 7b48577
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.0.5
7 changes: 5 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ ENVIRONMENT VARIABLES

// 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(version string) {
rootCmd.Version = version
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func SetVersion(version string) {
rootCmd.Version = version
}
11 changes: 2 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package main

import (
"fmt"

"github.com/tnyeanderson/ddns/cmd"
)

// These get populated by goreleaser
var (
version = "dev"
commit = "none"
)

func main() {
cmd.Execute(fmt.Sprintf("%s commit:%s", version, commit))
cmd.SetVersion(version())
cmd.Execute()
}
30 changes: 30 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"runtime/debug"
"strings"

_ "embed"
)

//go:embed VERSION
var versionTag string

func getCommit() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return ""
}

func version() string {
s := strings.TrimSpace(versionTag)
if c := getCommit(); c != "" {
s += " commit:" + c
}
return s
}

0 comments on commit 7b48577

Please sign in to comment.