diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2021-04-14 16:47:04 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2021-04-14 16:49:53 +0200 |
commit | 2e8f2a2e8e83fd89f956cdde886d5d9d808132da (patch) | |
tree | 84312e815be8c092dcbe22955df439969972cc92 /pkg | |
parent | eba7fe9f49a5156991ec0924ab86848fb681f03a (diff) |
[pkg] modify version gen to read static version file
this can be used from any build script to distinguish the version string
that will be displayed (ie: 0.21.2-debian-1)
- Resolves: #468
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/config/version/genver/main.go | 14 | ||||
-rw-r--r-- | pkg/version | 1 |
2 files changed, 13 insertions, 2 deletions
diff --git a/pkg/config/version/genver/main.go b/pkg/config/version/genver/main.go index e0d80b0..d4b72d8 100644 --- a/pkg/config/version/genver/main.go +++ b/pkg/config/version/genver/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "io" + "io/ioutil" "log" "os" "os/exec" @@ -43,7 +44,7 @@ func main() { vers, err := GitDescribe(dir) if err != nil { - log.Fatal(err) + vers = ReadVersionFile(dir) } vp := VersionPackage{ Name: *flPackageName, @@ -70,7 +71,7 @@ var packageLayout = `package {{.Name}} // AUTO-GENERATED. DO NOT EDIT // {{.Date}} -// {{.Variable}} is generated by git-describe from gen.go +// {{.Variable}} is generated by git-describe or static version file from gen.go var {{.Variable}} = "{{.Version}}" ` @@ -93,3 +94,12 @@ func GitDescribe(path string) (string, error) { return strings.TrimSpace(string(buf)), nil } + +func ReadVersionFile(path string) string { + versionFile := filepath.Join(path, "../../../version") + content, err := ioutil.ReadFile(versionFile) + if err != nil { + return "unknown" + } + return strings.Trim(string(content), "\n") +} diff --git a/pkg/version b/pkg/version new file mode 100644 index 0000000..146720c --- /dev/null +++ b/pkg/version @@ -0,0 +1 @@ +0.21.2+git |