Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App version is taken from version.json compiled in #149

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ USAGE:
ipget [global options] command [command options] [arguments...]

VERSION:
0.9.2
see version.json

COMMANDS:
help, h Shows a list of commands or help for one command
Expand Down
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
51 changes: 51 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

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

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

var version = buildVersion()

func buildVersion() string {
// Read version from embedded JSON file.
var v struct {
Version string `json:"version"`
}
json.Unmarshal(versionJSON, &v)
release := v.Version

info, ok := debug.ReadBuildInfo()
if !ok {
return release + " dev-build"
}

var dirty bool
var day, revision string

// Append the revision to the version.
for _, kv := range info.Settings {
switch kv.Key {
case "vcs.revision":
revision = kv.Value[:7]
case "vcs.time":
t, _ := time.Parse(time.RFC3339, kv.Value)
day = t.UTC().Format("2006-01-02")
case "vcs.modified":
dirty = kv.Value == "true"
}
}
if dirty {
revision += "-dirty"
}
if revision != "" {
return fmt.Sprintf("%s %s-%s", release, day, revision)
}
return release + " dev-build"
}
Loading