-
Notifications
You must be signed in to change notification settings - Fork 28
feat: Add more build metadata like commit hash, commit date, build date and git tag #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- CLI: 'capture --version' - API: GET /api/v1/metrics | jq '.capture' Signed-off-by: Mert Şişmanoğlu <[email protected]>
WalkthroughAdds build-time metadata injection via Goreleaser ldflags and extends the Capture binary’s -version output to include commit, commit date, compiled timestamp, and git tag using new public variables. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Dev as Developer
participant GR as Goreleaser
participant Go as Go Compiler
participant Bin as Capture Binary
Dev->>GR: goreleaser release
GR->>Go: Build with ldflags (-X main.* from templates)
Go-->>Bin: Produce binary with embedded Version, Commit, CommitDate, CompiledAt, GitTag
sequenceDiagram
autonumber
participant User as User
participant Bin as Capture (main)
participant OS as OS
User->>Bin: Run capture -version
Bin->>Bin: Read Version, Commit, CommitDate, CompiledAt, GitTag
Bin-->>User: Print multi-line build information
Bin->>OS: Exit(0)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (7)
.goreleaser.yml (2)
11-14: Avoid empty GitTag values on snapshot builds (fallback to 'unknown').When building snapshots (no tag),
{{.Tag}}can be empty. With-X "main.GitTag={{.Tag}}"this will override the in-binary default and setGitTagto the empty string, which then yields an empty/incorrect Git Tag and a broken Git Tag URL at runtime.Use a conditional to set a sensible fallback for snapshots:
Apply this diff in both ldflags blocks:
- - -X "main.GitTag={{.Tag}}" + - -X "main.GitTag={{ if not .IsSnapshot }}{{ .Tag }}{{ else }}unknown{{ end }}"Also applies to: 50-53
7-14: DRY the duplicate ldflags with a YAML anchor.The ldflags list is duplicated for builds and kos. Consider a YAML anchor to keep them in sync and reduce maintenance errors.
You can refactor like this (illustrative snippet):
builds: - id: capture main: ./cmd/capture ldflags: &common_ldflags - -s -w - -extldflags "-static" - -X "main.Version={{.Version}}" - -X "main.Commit={{.Commit}}" - -X "main.CommitDate={{.CommitDate}}" - -X "main.CompiledAt={{.Date}}" - -X "main.GitTag={{ if not .IsSnapshot }}{{ .Tag }}{{ else }}unknown{{ end }}" kos: - id: capture main: ./cmd/capture ldflags: *common_ldflagsAlso applies to: 47-53
internal/server/handler/types.go (1)
12-18: Consider omitting empty metadata fields from the API response.Right now, unknown values will serialize as empty strings. If you prefer a leaner response, add
omitemptyso snapshot/local builds don’t show placeholders clients can’t use (particularlygit_tag_url).Example diff:
- Version string `json:"version"` - Mode string `json:"mode"` - Commit string `json:"commit"` - CommitDate string `json:"commit_date"` - CompiledAt string `json:"compiled_at"` - GitTag string `json:"git_tag"` - GitTagURL string `json:"git_tag_url"` + Version string `json:"version"` + Mode string `json:"mode,omitempty"` + Commit string `json:"commit,omitempty"` + CommitDate string `json:"commit_date,omitempty"` + CompiledAt string `json:"compiled_at,omitempty"` + GitTag string `json:"git_tag,omitempty"` + GitTagURL string `json:"git_tag_url,omitempty"`If keeping fields always present is intentional for clients, feel free to ignore.
cmd/capture/main.go (4)
15-20: Fix comment: APISecret is required (fatal if missing), not “default is blank”.Per prior implementation in internal/config/config.go, API_SECRET is required and the app exits if it’s missing. Update the comment to avoid misleading readers.
Apply this diff:
-// Application configuration variable that holds the settings. -// -// -// - Port: Server port, default is 59232 -// -// -// - APISecret: Secret key for API access, default is a blank string. +// appConfig holds application settings. +// - Port: Server port (defaults to 59232 if empty). +// - APISecret: Secret key for API access (required; process exits if missing).
22-38: Derive GitTagURL at runtime to avoid “unknown”/empty URLs.When building snapshots,
GitTagmay beunknownor empty. Pre-initializingGitTagURLto a constant string concatenation will produce a broken URL. Compute it at runtime and omit when not meaningful.Apply this diff:
- // GitTagURL holds the URL of the Git tag, if any. - GitTagURL = "https://github.com/bluewave-labs/capture/releases/tag/" + GitTag + // GitTagURL holds the URL of the Git tag, if any. Set at runtime from GitTag. + GitTagURL = ""Then add this helper (outside the shown ranges):
// buildGitTagURL returns the GitHub release URL for the given tag, or "" if tag is empty/unknown. func buildGitTagURL(tag string) string { if tag == "" || tag == "unknown" { return "" } return "https://github.com/bluewave-labs/capture/releases/tag/" + tag }
44-54: Only print Git Tag URL when available and build it from the tag.This keeps the output clean on snapshot/local builds and avoids showing a broken URL.
Apply this diff:
- // Check if the version flag is provided and show build information + // Check if the version flag is provided and show build information if *showVersion { fmt.Println("Capture Build Information") fmt.Println("-------------------------") fmt.Printf("Version : %s\n", Version) fmt.Printf("Commit Hash : %s\n", Commit) fmt.Printf("Commit Date : %s\n", CommitDate) fmt.Printf("Compiled At : %s\n", CompiledAt) fmt.Printf("Git Tag : %s\n", GitTag) - fmt.Printf("Git Tag URL : %s\n", GitTagURL) + if url := buildGitTagURL(GitTag); url != "" { + fmt.Printf("Git Tag URL : %s\n", url) + } os.Exit(0) }
62-69: Populate GitTagURL from the tag at startup (omit when not available).This ensures API responses don’t expose a broken URL on snapshot/local builds.
Apply this diff:
srv := server.NewServer(appConfig, nil, &handler.CaptureMeta{ Version: Version, Commit: Commit, CommitDate: CommitDate, CompiledAt: CompiledAt, GitTag: GitTag, - GitTagURL: GitTagURL, + GitTagURL: buildGitTagURL(GitTag), })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
.goreleaser.yml(2 hunks)cmd/capture/main.go(2 hunks)internal/server/handler/types.go(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-02-01T14:10:43.142Z
Learnt from: mertssmnoglu
PR: bluewave-labs/capture#45
File: cmd/capture/main.go:34-38
Timestamp: 2025-02-01T14:10:43.142Z
Learning: In the Capture project, environment variable validation for PORT and API_SECRET is handled in internal/config/config.go's NewConfig function. PORT gets a default value if not set, and API_SECRET is required with a fatal error if missing.
Applied to files:
cmd/capture/main.go
🧬 Code Graph Analysis (2)
internal/server/handler/types.go (1)
cmd/capture/main.go (6)
Version(27-27)Commit(29-29)CommitDate(31-31)CompiledAt(33-33)GitTag(35-35)GitTagURL(37-37)
cmd/capture/main.go (1)
internal/config/config.go (1)
Config(5-8)
🔇 Additional comments (2)
cmd/capture/main.go (2)
41-45: No action required:--versionis supported by the stdlib flagGo’s standard flag package accepts both
-versionand--versioninterchangeably, socapture --versionwill work without any preprocessing or external libraries.
62-69: No action needed:CaptureMeta.Modeis already setThe call to
server.NewServer(appConfig, nil, &handler.CaptureMeta{…})passes your metadata intoInitializeHandler, which immediately does:metadata.Mode = gin.Mode()so
.modewill always reflect the active Gin mode. You can safely ignore the suggestion to setModein the struct literal.Likely an incorrect or invalid review comment.
…' in goreleaser Signed-off-by: Mert Şişmanoğlu <[email protected]>
|
These commit hash and build time values are useful for troubleshooting but I'm not sure about sending so much metadata on each request. What is your opinion? I can make it only appear on CLI and stop exposing them through the API. |
I feel like this is too much for production. Your suggestion is better. |
Yeah cli is probably good, or add a dev flag and only add that info if the flag is set. |
Signed-off-by: Mert Şişmanoğlu <[email protected]>
|
Thank you for the responses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
cmd/capture/main.go (2)
15-19: Fix inaccurate config comment: APISecret is required; avoid hardcoding defaultsPer the project’s config behavior (see internal/config.NewConfig), PORT has a default if unset, and API_SECRET is required and fatal if missing. The current comment says APISecret defaults to blank and hardcodes a port value, which can drift.
Apply this diff to make the comment accurate and resilient to future changes:
-// Application configuration variable that holds the settings. -// -// -// - Port: Server port, default is 59232 -// -// -// - APISecret: Secret key for API access, default is a blank string. +// Application configuration parsed by internal/config.NewConfig: +// - Port: Server port. Default is provided by NewConfig when PORT is unset. +// - APISecret: Secret key for API access. Required; NewConfig exits fatally if missing.If you want to keep the exact default port documented, please verify it from internal/config and then update the comment accordingly. I can run a repo search to confirm the current default if you want.
42-51: No action needed for “--version”; consider optional JSON output
- The Go standard
flagpackage accepts both-versionand--version(they’re treated identically), socapture --versionalready works as intended.- Only migrate to a GNU‐style parser (e.g.
spf13/pflagorcobra) if you require strict long/short distinctions, flag chaining, or specialized help formatting.- Optional: in
cmd/capture/main.go:42-51, add a JSON output mode (e.g.--version-json) or detect a TTY to emit machine-readable version info for scripting purposes.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
cmd/capture/main.go(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-02-01T14:10:43.142Z
Learnt from: mertssmnoglu
PR: bluewave-labs/capture#45
File: cmd/capture/main.go:34-38
Timestamp: 2025-02-01T14:10:43.142Z
Learning: In the Capture project, environment variable validation for PORT and API_SECRET is handled in internal/config/config.go's NewConfig function. PORT gets a default value if not set, and API_SECRET is required with a fatal error if missing.
Applied to files:
cmd/capture/main.go
🧬 Code Graph Analysis (1)
cmd/capture/main.go (1)
internal/config/config.go (1)
Config(5-8)
Summary
Extend Capture metadata to include more build information when execute
capture --versionFixes: #92
CLI
Execute capture with --version flag
Output
API
{ "version": "1.3.0-SNAPSHOT-f9dc4b8", "mode": "release" }Summary by CodeRabbit
New Features
Chores