maintain (generator): simplify build command

Before this commit our build had this option:
-ldflags "-X github.com/mickael-kerjean/filestash/server/common.BUILD_DATE=`date -u +%Y%m%d` -X github.com/mickael-kerjean/filestash/server/common.BUILD_REF=`git rev-parse HEAD`"

Doing this via a generator is much easier for people getting started
with Filestash
This commit is contained in:
Mickael Kerjean
2022-09-28 18:11:58 +10:00
parent 3013141999
commit 21a72b2048
2 changed files with 33 additions and 0 deletions
+1
View File
@@ -5,6 +5,7 @@ import (
"path/filepath"
)
//go:generate go run ../generator/constants.go
const (
APP_VERSION = "v0.5"
LOG_PATH = "data/state/log/"
+32
View File
@@ -0,0 +1,32 @@
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"time"
)
func main() {
cmd, b := exec.Command("git", "rev-parse", "HEAD"), new(strings.Builder)
cmd.Stdout = b
cmd.Run()
content := fmt.Sprintf(`package common
func init() {
BUILD_REF = "%s"
BUILD_DATE = "%s"
}
`, strings.TrimSpace(b.String()), time.Now().Format("20060102"))
f, err := os.OpenFile("../common/constants_generated.go", os.O_CREATE|os.O_WRONLY, os.ModePerm)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
return
}
f.Write([]byte(content))
f.Close()
}