feat: add commit branch to extra

This commit is contained in:
liruichen 2023-09-08 11:52:24 +08:00
parent 7b53901a34
commit 0a50f77815
2 changed files with 14 additions and 2 deletions

View File

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

View File

@ -199,7 +199,16 @@ func (b *Build) injectGocAgent(where string, covers []*PackageCover) {
} else {
commitID = strings.TrimRight(string(output), "\n")
}
log.Infof("[goc][info] commitID: %v", commitID)
var branch string
cmd = exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
br, err := cmd.Output()
if err != nil {
log.Errorf("git rev-parse Error:", err)
} else {
branch = strings.TrimRight(string(br), "\n")
branch = strings.TrimLeft(string(br), "heads/")
}
log.Infof("[goc][info] branch: %v --- commitID: %v", branch, commitID)
tmplData := struct {
Covers []*PackageCover
GlobalCoverVarImportPath string
@ -207,12 +216,14 @@ func (b *Build) injectGocAgent(where string, covers []*PackageCover) {
Host string
Mode string
CommitID string
Branch string
}{
Covers: covers,
GlobalCoverVarImportPath: b.GlobalCoverVarImportPath,
Package: injectPkgName,
Host: b.Host,
Mode: _coverMode,
Branch: branch,
CommitID: commitID,
}