fix version construction
This commit is contained in:
parent
6db32797dc
commit
2e900e88b0
@ -2,7 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"gitea.illuad.fr/adrien/middleman/command"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v3"
|
||||
@ -19,27 +20,17 @@ type noCommit struct {
|
||||
|
||||
func (nc noCommit) String() string {
|
||||
if nc.message == nil {
|
||||
nc.message = []byte("not tied to a commit") // 6344da387a21711b36a91c2fd55f48a026b2be8b5345cbbf32a31f5c089f4d75
|
||||
nc.message = []byte("not tied to a commit") // dbf242029aeedcfe71af2e5843474d8f8e2e9d63
|
||||
}
|
||||
sum := sha256.Sum256(nc.message)
|
||||
return string(sum[:])
|
||||
sum := sha1.Sum(nc.message)
|
||||
return fmt.Sprintf("%x", sum)
|
||||
}
|
||||
|
||||
const appName = "middleman"
|
||||
|
||||
var (
|
||||
version = "dev"
|
||||
commit = noCommit{}.String()
|
||||
)
|
||||
var version, commit string
|
||||
|
||||
func main() {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
if info.Main.Version != "" {
|
||||
version = info.Main.Version
|
||||
commit = info.Main.Sum
|
||||
}
|
||||
}
|
||||
// Note: os.Kill/syscall.SIGKILL (SIGKILL) signal cannot be caught or ignored.
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
@ -48,7 +39,7 @@ func main() {
|
||||
app := cli.Command{
|
||||
Name: appName,
|
||||
Usage: "Securely mount the Docker socket: apply fine-grained access control to Docker socket HTTP requests",
|
||||
Version: version + "-" + commit,
|
||||
Version: buildVersion(),
|
||||
DefaultCommand: command.ServeCmd,
|
||||
Commands: []*cli.Command{
|
||||
command.Serve(group),
|
||||
@ -66,3 +57,16 @@ func main() {
|
||||
log.Err(err).Send()
|
||||
}
|
||||
}
|
||||
|
||||
func buildVersion() string {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
if info.Main.Version != "" {
|
||||
return info.Main.Version + "-" + info.Main.Sum
|
||||
}
|
||||
}
|
||||
if version == "" && commit == "" {
|
||||
return "dev" + "-" + noCommit{}.String()
|
||||
}
|
||||
return version + "-" + commit
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user