Files
filestash/server/generator/constants.go
Mickael Kerjean 21a72b2048 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
2022-09-28 18:11:58 +10:00

33 lines
574 B
Go

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()
}