Skip to content
Snippets Groups Projects
Commit 4be74723ba63 authored by Christophe de Vienne's avatar Christophe de Vienne
Browse files

build_version_file: fix a crash when no active topic

parent c26b7fd68dd7
No related branches found
No related tags found
No related merge requests found
Pipeline #114608 failed
package main package main
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
...@@ -8,6 +9,6 @@ ...@@ -8,6 +9,6 @@
"text/template" "text/template"
) )
func syscmd(name string, arg ...string) string { func sysCmd(name string, arg ...string) (string, error) {
cmd := exec.Command(name, arg...) cmd := exec.Command(name, arg...)
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
...@@ -12,9 +13,5 @@ ...@@ -12,9 +13,5 @@
cmd := exec.Command(name, arg...) cmd := exec.Command(name, arg...)
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(string(out))
panic(err)
}
splitted := strings.Split(string(out), "\n") splitted := strings.Split(string(out), "\n")
lines := make([]string, 0, len(splitted)) lines := make([]string, 0, len(splitted))
for _, l := range splitted { for _, l := range splitted {
...@@ -26,6 +23,7 @@ ...@@ -26,6 +23,7 @@
} }
if len(lines) != 1 { if len(lines) != 1 {
fmt.Println(string(out)) fmt.Println(string(out))
panic("Expects a single line")
return "", errors.New("Expects a single line")
} }
...@@ -30,6 +28,15 @@ ...@@ -30,6 +28,15 @@
} }
return lines[0] return lines[0], err
}
func mustSysCmd(name string, arg ...string) string {
out, err := sysCmd(name, arg...)
if err != nil {
panic(err)
}
return out
} }
func getVersionTag(tags string) string { func getVersionTag(tags string) string {
...@@ -56,9 +63,9 @@ ...@@ -56,9 +63,9 @@
`)) `))
func main() { func main() {
sha := syscmd("hg", "id", "--id") sha := mustSysCmd("hg", "id", "--id")
curVersion := getVersionTag(syscmd("hg", "id", "--tags")) curVersion := getVersionTag(mustSysCmd("hg", "id", "--tags"))
lastVersion := getVersionTag(syscmd("hg", "id", "--tags", "-r", "limit(last(ancestors(.)&tag('re:v.*'))|.,1)")) lastVersion := getVersionTag(mustSysCmd("hg", "id", "--tags", "-r", "limit(last(ancestors(.)&tag('re:v.*'))|.,1)"))
modified := strings.HasSuffix(sha, "+") modified := strings.HasSuffix(sha, "+")
jobID := os.Getenv("CI_JOB_ID") jobID := os.Getenv("CI_JOB_ID")
...@@ -62,6 +69,6 @@ ...@@ -62,6 +69,6 @@
modified := strings.HasSuffix(sha, "+") modified := strings.HasSuffix(sha, "+")
jobID := os.Getenv("CI_JOB_ID") jobID := os.Getenv("CI_JOB_ID")
topic := syscmd("hg", "topic", "--current") topic, err := sysCmd("hg", "topic", "--current")
if topic == "no active topic" { if topic == "no active topic" {
topic = "" topic = ""
...@@ -66,3 +73,5 @@ ...@@ -66,3 +73,5 @@
if topic == "no active topic" { if topic == "no active topic" {
topic = "" topic = ""
} else if err != nil {
panic(err)
} }
...@@ -68,5 +77,5 @@ ...@@ -68,5 +77,5 @@
} }
branch := syscmd("hg", "id", "--branch") branch := mustSysCmd("hg", "id", "--branch")
var version string var version string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment