changeset: allow override the revision through ldflags (#2601)

The main reason for this is to support cases where the `go build`
happens on a non git folder but we want to pass a revision anyway.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2022-11-02 20:10:08 +00:00 committed by GitHub
parent 92ed919344
commit dc1fae1337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -39,7 +39,10 @@ var (
// The result will have a '-dirty' suffix if the workspace was not clean
func Get() string {
once.Do(func() {
rev = get()
if rev == "" {
rev = get()
}
// It has been set through ldflags, do nothing
})
return rev

View File

@ -73,6 +73,7 @@ func TestGet(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
rev = ""
once = sync.Once{}
readBuildInfo = func() (info *debug.BuildInfo, ok bool) {
return c.info, c.ok