Semaphore/util/version_gen/generator.go

47 lines
711 B
Go
Raw Normal View History

2018-03-08 00:42:11 +01:00
// +build ignore
package main
import (
"log"
"os"
"text/template"
)
var versionTmpl = `package util
//Version is the Semaphore build version as a string
2018-03-08 00:42:11 +01:00
var Version = "{{ .VERSION }}"
`
func main(){
if len(os.Args) <= 1 {
log.Fatalln("Must pass in version number")
}
data := make(map[string]string)
data["VERSION"] = os.Args[1]
tmpl := template.New("version")
var err error
if tmpl, err = tmpl.Parse(versionTmpl); err != nil {
log.Fatalln(err)
}
f, err := os.Create("util/version.go")
if err != nil {
log.Fatalln(err)
}
defer func(r *os.File) {
err = r.Close()
if err != nil {
log.Fatalln(err)
}
}(f)
err = tmpl.Execute(f, data)
if err != nil {
log.Println(err)
}
2018-03-08 00:42:11 +01:00
}