-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App version is taken from version.json compiled in (#149)
* App version is taken from version.json compiled in This ensures that the version is always set to the correct value. making version.json the source of truth. Fixes #146 Fixes #113 * remove version number from README * include date and dirty flag in version
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |