Skip to content

Commit ac0f516

Browse files
authored
feat: Add more build metadata like commit hash, commit date, build date and git tag (#121)
* feat: Add more build metadata to Capture and API response #92 - CLI: 'capture --version' - API: GET /api/v1/metrics | jq '.capture' Signed-off-by: Mert Şişmanoğlu <[email protected]> * fix: use YAML anchors for ldflags configuration for 'builds' and 'kos' in goreleaser Signed-off-by: Mert Şişmanoğlu <[email protected]> * fix: Show metadata at only CLI mode and delete GitTagURL Signed-off-by: Mert Şişmanoğlu <[email protected]> --------- Signed-off-by: Mert Şişmanoğlu <[email protected]>
1 parent 7ab5e04 commit ac0f516

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

.goreleaser.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ project_name: capture
44
builds:
55
- id: capture
66
main: ./cmd/capture
7-
ldflags:
7+
ldflags: &common_ldflags
88
- -s -w
99
- -extldflags "-static"
1010
- -X "main.Version={{.Version}}"
11+
- -X "main.Commit={{.Commit}}"
12+
- -X "main.CommitDate={{.CommitDate}}"
13+
- -X "main.CompiledAt={{.Date}}"
14+
- -X "main.GitTag={{.Tag}}"
1115
env:
1216
- CGO_ENABLED=0
1317
goos:
@@ -39,10 +43,7 @@ kos:
3943
main: ./cmd/capture
4044
flags:
4145
- -trimpath
42-
ldflags:
43-
- -s -w
44-
- -extldflags "-static"
45-
- -X "main.Version={{.Version}}"
46+
ldflags: *common_ldflags
4647
creation_time: "{{.CommitTimestamp}}"
4748
sbom: spdx
4849
env:

cmd/capture/main.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,42 @@ import (
1212
"github.com/bluewave-labs/capture/internal/server/handler"
1313
)
1414

15+
// Application configuration variable that holds the settings.
16+
//
17+
// - Port: Server port, default is 59232
18+
//
19+
// - APISecret: Secret key for API access, default is a blank string.
1520
var appConfig *config.Config
1621

17-
var Version = "develop" // This will be set during compile time using go build ldflags
22+
// Build information variables populated at build time.
23+
// These variables are typically set using ldflags during the build process
24+
// to provide runtime access to build metadata.
25+
var (
26+
// Version represents the Capture version (default: "develop").
27+
Version = "develop"
28+
// Commit contains the Git commit hash of the build.
29+
Commit = "unknown"
30+
// CommitDate holds the date of the commit.
31+
CommitDate = "unknown"
32+
// CompiledAt stores the build compilation date.
33+
CompiledAt = "unknown"
34+
// GitTag contains the Git tag associated with the build, if any.
35+
GitTag = "unknown"
36+
)
1837

1938
func main() {
2039
showVersion := flag.Bool("version", false, "Display the version of the capture")
2140
flag.Parse()
2241

23-
// Check if the version flag is provided
42+
// Check if the version flag is provided and show build information
2443
if *showVersion {
25-
fmt.Printf("Capture version: %s\n", Version)
44+
fmt.Println("Capture Build Information")
45+
fmt.Println("-------------------------")
46+
fmt.Printf("Version : %s\n", Version)
47+
fmt.Printf("Commit Hash : %s\n", Commit)
48+
fmt.Printf("Commit Date : %s\n", CommitDate)
49+
fmt.Printf("Compiled At : %s\n", CompiledAt)
50+
fmt.Printf("Git Tag : %s\n", GitTag)
2651
os.Exit(0)
2752
}
2853

0 commit comments

Comments
 (0)