mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2026-10-21 05:26:51 +00:00
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:
@@ -5,6 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
//go:generate go run ../generator/constants.go
|
||||
const (
|
||||
APP_VERSION = "v0.5"
|
||||
LOG_PATH = "data/state/log/"
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user