summaryrefslogtreecommitdiff
path: root/pkg/config
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2021-04-14 16:47:04 +0200
committerkali kaneko (leap communications) <kali@leap.se>2021-04-14 16:49:53 +0200
commit2e8f2a2e8e83fd89f956cdde886d5d9d808132da (patch)
tree84312e815be8c092dcbe22955df439969972cc92 /pkg/config
parenteba7fe9f49a5156991ec0924ab86848fb681f03a (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/config')
-rw-r--r--pkg/config/version/genver/main.go14
1 files changed, 12 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")
+}