Skip to content

Commit

Permalink
App version is taken from version.json compiled in
Browse files Browse the repository at this point in the history
This ensures that the version is always set to the correct value. making version.json the source of truth.

Fixes #146
Fixes #113
  • Loading branch information
gammazero committed Aug 14, 2024
1 parent 2c06a6c commit 082283e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
app := cli.NewApp()
app.Name = "ipget"
app.Usage = "Retrieve and save IPFS objects."
app.Version = "0.9.2"
app.Version = version
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "output",
Expand Down
33 changes: 33 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
_ "embed"
"encoding/json"
"runtime/debug"
)

var version string

//go:embed version.json
var versionJSON []byte

func init() {
// Read version from embedded JSON file.
var verMap map[string]string
json.Unmarshal(versionJSON, &verMap)
version = verMap["version"]

// If running from a module, try to get the build info.
bi, ok := debug.ReadBuildInfo()
if !ok {
return
}

// Append the revision to the version.
for i := range bi.Settings {
if bi.Settings[i].Key == "vcs.revision" {
version += "-" + bi.Settings[i].Value
break
}
}
}

0 comments on commit 082283e

Please sign in to comment.