feat: log version

This commit is contained in:
liruichen 2023-08-25 18:47:10 +08:00
parent d1708d550e
commit 147b8a47df
3 changed files with 7 additions and 6 deletions

View File

@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra"
)
var version = "unstable"
var Version = "unstable"
var versionCmd = &cobra.Command{
Use: "version",
@ -31,13 +31,13 @@ goc version
`,
Run: func(cmd *cobra.Command, args []string) {
// if it is "Unstable", means user build local or with go get
if version == "unstable" {
if Version == "unstable" {
if info, ok := debug.ReadBuildInfo(); ok {
fmt.Println(info.Main.Version)
}
} else {
// otherwise the value is injected in CI
fmt.Println(version)
fmt.Println(Version)
}
},
}

View File

@ -10,7 +10,7 @@ RELEASE_VERSION=$(echo $EVENT_DATA | jq -r .release.tag_name)
PROJECT_NAME=$(basename $GITHUB_REPOSITORY)
NAME="${NAME:-${PROJECT_NAME}-${RELEASE_VERSION}}-${GOOS}-${GOARCH}"
CGO_ENABLED=0 go build -ldflags "-X 'github.com/RickLeee/goc-v2/cmd.version=${RELEASE_VERSION}'" .
CGO_ENABLED=0 go build -ldflags "-X 'github.com/RickLeee/goc-v2/cmd.Version=${RELEASE_VERSION}'" .
ARCHIVE=tmp.tar.gz
FILE_LIST=goc

View File

@ -17,6 +17,7 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
"github.com/qiniu/goc/v2/cmd"
"math/rand"
"net/http"
"net/rpc"
@ -130,7 +131,7 @@ func RunGocServerUntilExit(host string, s store.Store) error {
}
go gs.watchLoop()
log.Infof("version: %v", cmd.Version)
return r.Run(host)
}