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