Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit c3df0d4

Browse files
committed
chore: read commit from Go
That way we don't rely on an external tool to pass it and it's always set at build time. Signed-off-by: Yves Brissaud <[email protected]>
1 parent 7b5c3d9 commit c3df0d4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

.goreleaser.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ builds:
2222
-s
2323
-extldflags '-static'
2424
-X github.com/docker/index-cli-plugin/internal.version={{.Version}}
25-
-X github.com/docker/index-cli-plugin/internal.commit={{.Commit}}
2625

2726
archives:
2827
- format: tar.gz

internal/version.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package internal
2222
import (
2323
"fmt"
2424
"runtime"
25+
"runtime/debug"
2526
)
2627

2728
// build-time arguments
@@ -30,6 +31,16 @@ var (
3031
commit = "n/a"
3132
)
3233

34+
func init() {
35+
if info, ok := debug.ReadBuildInfo(); ok {
36+
for _, setting := range info.Settings {
37+
if setting.Key == "vcs.revision" {
38+
commit = setting.Value
39+
}
40+
}
41+
}
42+
}
43+
3344
// Version information from build time args and environment
3445
type Version struct {
3546
Version string

0 commit comments

Comments
 (0)