feat: add commit HASH to extra v2

This commit is contained in:
liruichen 2023-09-08 11:31:19 +08:00
parent 7e18447f9a
commit 7b53901a34
3 changed files with 10 additions and 6 deletions

View File

@ -46,6 +46,7 @@ var (
id string
cond = sync.NewCond(&sync.Mutex{})
register_extra = ""
commitID string = "{{.CommitID}}"
)
func init() {
@ -115,8 +116,9 @@ func register (host string) {
time.Sleep(waitDelay)
continue
}
register_extra = fmt.Sprintf("%v_%v", os.Getenv("ECHO_APP_ID"), {{.CommitID}})
app := os.Getenv("ECHO_APP_ID")
log.Printf("app: %v, commit: %v", app, commitID)
register_extra = fmt.Sprintf("%v_%v", app, commitID)
// 注册,直接将元信息放在 ws 地址中
v := url.Values{}
v.Set("hostname", ps.hostname)

View File

@ -71,7 +71,7 @@ func (b *Build) displayProjectMetaInfo() {
log.Infof("GOPATH: %v", b.GOPATH)
log.Infof("GOBIN: %v", b.GOBIN)
log.Infof("Project Directory: %v", b.CurModProjectDir)
log.Infof("GOC_REGISTER_EXTRA: %v", os.Getenv("GOC_REGISTER_EXTRA"))
log.Infof("GOC_REGISTER_EXTRA from env: %v", os.Getenv("GOC_REGISTER_EXTRA"))
log.Infof("Temporary Project Directory: %v", b.TmpModProjectDir)
if b.IsVendorMod {
log.Infof("Project in vendor mod")

View File

@ -19,6 +19,7 @@ import (
"os/exec"
"path"
"path/filepath"
"strings"
"github.com/RickLeee/goc-v2/pkg/build/internal/tool"
"github.com/RickLeee/goc-v2/pkg/build/internal/websocket"
@ -190,14 +191,15 @@ func (b *Build) injectGocAgent(where string, covers []*PackageCover) {
} else {
_coverMode = b.Mode
}
var CommitID string
var commitID string
cmd := exec.Command("git", "describe", "--abbrev=8", "--always")
output, err := cmd.Output()
if err != nil {
log.Errorf("git describe Error:", err)
} else {
CommitID = string(output)
commitID = strings.TrimRight(string(output), "\n")
}
log.Infof("[goc][info] commitID: %v", commitID)
tmplData := struct {
Covers []*PackageCover
GlobalCoverVarImportPath string
@ -211,7 +213,7 @@ func (b *Build) injectGocAgent(where string, covers []*PackageCover) {
Package: injectPkgName,
Host: b.Host,
Mode: _coverMode,
CommitID: CommitID,
CommitID: commitID,
}
if err := coverMainTmpl.Execute(f2, tmplData); err != nil {