mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
feat(cli): new version format with commit hash and go version
This commit is contained in:
parent
071c22a881
commit
07eba99f2b
5 changed files with 73 additions and 5 deletions
|
@ -8,8 +8,10 @@ import (
|
|||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type VersionInfo struct {
|
||||
|
@ -59,6 +61,14 @@ func main() {
|
|||
log.Fatalf("Failed to parse JSON: %v", err)
|
||||
}
|
||||
|
||||
// get current git commit hash
|
||||
cmd := exec.Command("git", "-C", basePath, "rev-parse", "HEAD")
|
||||
commitHash, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Printf("Failed to get git commit hash: %v", err)
|
||||
commitHash = []byte("")
|
||||
}
|
||||
|
||||
// Generate the version.gen.go file content
|
||||
genContent := fmt.Sprintf(`// Code generated by cmd/version/generate.go; DO NOT EDIT.
|
||||
|
||||
|
@ -68,8 +78,9 @@ func init() {
|
|||
Version = "%s"
|
||||
BuildId = %d
|
||||
TotalBuild = %d
|
||||
Hash = "%s"
|
||||
}
|
||||
`, versionInfo.Version, versionInfo.BuildId, versionInfo.TotalBuild)
|
||||
`, versionInfo.Version, versionInfo.BuildId, versionInfo.TotalBuild, strings.TrimRight(string(commitHash), "\r\n"))
|
||||
|
||||
genPath := path.Join(basePath, "internal/version/version.gen.go")
|
||||
err = os.WriteFile(genPath, []byte(genContent), 0644)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue