Skip to content

Commit e2447f4

Browse files
committed
build: embed branch and version metadata in build artifacts
- Export GIT_BRANCH and GO_VERSION as environment variables in the before script - Update build ldflags to include branch, build time, commit, Go version, OS, and architecture - Change ldflags assignment to use the version package instead of cmd package Signed-off-by: appleboy <[email protected]>
1 parent 90c1032 commit e2447f4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

.goreleaser.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
before:
22
hooks:
33
- go mod tidy
4+
- export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
5+
- export GO_VERSION=$(go version | cut -d " " -f 3)
46

57
builds:
68
- env:
@@ -59,8 +61,13 @@ builds:
5961
- -trimpath
6062
ldflags:
6163
- -s -w
62-
- -X github.com/appleboy/CodeGPT/cmd.Version={{.Version}}
63-
- -X github.com/appleboy/CodeGPT/cmd.Commit={{.ShortCommit}}
64+
- -X 'github.com/appleboy/CodeGPT/version.Version={{.Version}}'
65+
- -X 'github.com/appleboy/CodeGPT/version.BuildTime={{.Date}}'
66+
- -X 'github.com/appleboy/CodeGPT/version.GitCommit={{.FullCommit}}'
67+
- -X 'github.com/appleboy/CodeGPT/version.GitBranch={{.Env.GIT_BRANCH}}'
68+
- -X 'github.com/appleboy/CodeGPT/version.GoVersion={{.Env.GO_VERSION}}'
69+
- -X 'github.com/appleboy/CodeGPT/version.BuildOS={{.Os}}'
70+
- -X 'github.com/appleboy/CodeGPT/version.BuildArch={{.Arch}}'
6471
binary: >-
6572
{{ .ProjectName }}-
6673
{{- if .IsSnapshot }}{{ .Branch }}-

0 commit comments

Comments
 (0)