Skip to content

Commit

Permalink
Add ld flags for git hash
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 committed Sep 3, 2024
1 parent efa91b2 commit 1d884f0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/tools/golang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ func buildArgsAndEnvs(ctx context.Context, config BuildConfig) (args, envs []str
if config.StaticBuild && config.Platform.OS == tools.OSDocker {
ldFlags = append(ldFlags, "-extldflags=-static")
}
commitHash := getCommitHash()
ldFlags = append(ldFlags, "-X github.com/sei-protocol/sei-v3/pkg/version/version.Commit="+commitHash)

args = []string{
"build",
Expand Down Expand Up @@ -403,3 +405,12 @@ func env(ctx context.Context) []string {
"GOLANGCI_LINT_CACHE=" + filepath.Join(tools.DevDir(ctx), "go", "cache", "golangci"),
}
}

func getCommitHash() string {
cmd := exec.Command("git", "rev-parse", "HEAD")
output, err := cmd.Output()
if err != nil {
return "failed to get commit hash"
}
return strings.TrimSpace(string(output))
}

0 comments on commit 1d884f0

Please sign in to comment.