Skip to content

Embed release version in backend builds#43

Merged
Kzoeps merged 2 commits into
mainfrom
display-release-version
Apr 30, 2026
Merged

Embed release version in backend builds#43
Kzoeps merged 2 commits into
mainfrom
display-release-version

Conversation

@Kzoeps
Copy link
Copy Markdown
Collaborator

@Kzoeps Kzoeps commented Apr 30, 2026

Summary

  • Replace the hard-coded backend status version with a build-info variable that can be set via Go ldflags.
  • Teach Makefile and Docker builds to embed an explicit version, with Docker falling back to the latest committed Changie release file.
  • Add tests and a Changie fragment for operator-facing release/version visibility.

Validation

  • go build -ldflags "-X github.com/GainForest/hyperindex/internal/buildinfo.Version=v9.9.9-test" -o /tmp/hyperindex-version-test ./cmd/hyperindex
  • make build VERSION=v9.9.9-test
  • go build -v ./...
  • DATABASE_URL=sqlite::memory: go test -v -race ./...
  • make lint

Not yet validated

  • Docker build validation is intentionally left for PR/remote environment because the local Docker daemon is unavailable in this session.

Summary by CodeRabbit

  • Changed
    • The Hyperindex status endpoint now reports the deployed release version instead of a static development version string, allowing users to verify the exact version running in their environment.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hyperindex-atproto-client Ready Ready Preview, Comment Apr 30, 2026 8:38am
hyperindex-client Ready Ready Preview, Comment Apr 30, 2026 8:38am

Request Review

@railway-app
Copy link
Copy Markdown

railway-app Bot commented Apr 30, 2026

🚅 Deployed to the hyperindex-pr-43 environment in hyperindex-v2-setup

Service Status Web Updated (UTC)
hyperindex ✅ Success (View Logs) Web Apr 30, 2026 at 8:38 am
hyperindex-client ⏭️ Skipped (View Logs) Web Apr 30, 2026 at 8:37 am
1 service not affected by this PR
  • hyperindex-client

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@Kzoeps has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 56 minutes and 4 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5eba8b5d-9379-46a6-a329-42f245295276

📥 Commits

Reviewing files that changed from the base of the PR and between 3fea31f and fce9c54.

📒 Files selected for processing (7)
  • .changes/unreleased/embed-backend-build-version.yaml
  • Dockerfile
  • Makefile
  • cmd/hyperindex/main.go
  • cmd/hyperindex/main_test.go
  • internal/buildinfo/buildinfo.go
  • internal/buildinfo/buildinfo_test.go
📝 Walkthrough

Walkthrough

This pull request adds build-time version embedding to the Hyperindex application. A new buildinfo package exposes a version variable that can be overridden during compilation. The Makefile and Dockerfile are updated to compute and inject a version string via linker flags, and the root HTTP endpoint now reports the embedded build version instead of a static development string.

Changes

Cohort / File(s) Summary
Build Configuration
Makefile, Dockerfile
Modified to accept and compute a VERSION value, then pass it to the Go linker via -X flags to inject internal/buildinfo.Version at build time. Dockerfile computes version from git index if not explicitly provided.
Build Info Package
internal/buildinfo/buildinfo.go, internal/buildinfo/buildinfo_test.go
New package introducing an exported Version string variable (defaults to "0.1.0-dev"). Includes test validating the default value and documenting linker flag override capability.
Root Endpoint
cmd/hyperindex/main.go, cmd/hyperindex/main_test.go
Updated to report the runtime build version from buildinfo.Version instead of a static dev string. New test validates the root endpoint correctly returns the injected version in its JSON response.
Changelog Metadata
.changes/unreleased/embed-backend-build-version.yaml
New unreleased changelog fragment documenting this change as affecting the operator component.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit's hop through versioned code,
where builds now sing of versions stowed,
from Makefile flags to Docker's care,
embedded versions float on air!
Status endpoints now reveal,
what releases truly feel.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the pull request: embedding the release version in backend builds through build-time linker flags in Makefile and Docker configurations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch display-release-version

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.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 56 minutes and 4 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
Dockerfile (1)

24-30: ⚡ Quick win

Harden Docker version fallback when .git metadata is unavailable.

The current fallback only inspects version files through Git plumbing. If .git isn’t present in the Docker context, this silently drops to 0.1.0-dev even when .changes/v*.md exists.

Proposed patch
-        release_file="$(git ls-files '.changes/v*.md' 2>/dev/null | sort -V | tail -n 1 || true)"; \
+        release_file="$(git ls-tree -r --name-only HEAD '.changes/v*.md' 2>/dev/null | sort -V | tail -n 1 || true)"; \
+        if [ -z "$release_file" ]; then \
+            release_file="$(ls -1 .changes/v*.md 2>/dev/null | sort -V | tail -n 1 || true)"; \
+        fi; \
         if [ -n "$release_file" ]; then \
             release_name="${release_file##*/}"; \
             build_version="${release_name%.md}"; \
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Dockerfile` around lines 24 - 30, The version fallback block using
release_file/release_name/build_version should be hardened to handle contexts
without .git by falling back to filesystem globbing when git ls-files yields
nothing; update the logic in that shell block so after trying git ls-files for
'.changes/v*.md' it checks for the existence of matching files in the workspace
(e.g., via shell glob or find) and uses the newest match to set release_name and
build_version before defaulting to "0.1.0-dev", ensuring you reference the same
variables (release_file, release_name, build_version) and preserve the existing
sort -V | tail -n 1 behavior.
cmd/hyperindex/main_test.go (1)

17-19: ⚡ Quick win

Assert against an immutable expected value instead of the mutable global.

This makes the test more robust against accidental cross-test mutation of buildinfo.Version.

Proposed patch
-	previousVersion := buildinfo.Version
-	buildinfo.Version = "v9.9.9-test"
+	previousVersion := buildinfo.Version
+	expectedVersion := "v9.9.9-test"
+	buildinfo.Version = expectedVersion
@@
-	if body["version"] != buildinfo.Version {
-		t.Fatalf("version = %q, want buildinfo.Version %q", body["version"], buildinfo.Version)
+	if body["version"] != expectedVersion {
+		t.Fatalf("version = %q, want %q", body["version"], expectedVersion)
 	}

Also applies to: 37-39

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/hyperindex/main_test.go` around lines 17 - 19, The test currently mutates
the global buildinfo.Version (saving previousVersion then restoring in
t.Cleanup) and asserts against that mutable value; instead, set
buildinfo.Version to the test value ("v9.9.9-test") and assert against the
literal expected string in assertions (e.g., use "v9.9.9-test" directly),
keeping the t.Cleanup restore of buildinfo.Version to previousVersion; update
both places where this pattern appears (the block that assigns
previousVersion/buildinfo.Version and the second instance at 37-39) so
assertions compare to the immutable expected literal rather than the global
variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/hyperindex/main_test.go`:
- Around line 17-19: The test currently mutates the global buildinfo.Version
(saving previousVersion then restoring in t.Cleanup) and asserts against that
mutable value; instead, set buildinfo.Version to the test value ("v9.9.9-test")
and assert against the literal expected string in assertions (e.g., use
"v9.9.9-test" directly), keeping the t.Cleanup restore of buildinfo.Version to
previousVersion; update both places where this pattern appears (the block that
assigns previousVersion/buildinfo.Version and the second instance at 37-39) so
assertions compare to the immutable expected literal rather than the global
variable.

In `@Dockerfile`:
- Around line 24-30: The version fallback block using
release_file/release_name/build_version should be hardened to handle contexts
without .git by falling back to filesystem globbing when git ls-files yields
nothing; update the logic in that shell block so after trying git ls-files for
'.changes/v*.md' it checks for the existence of matching files in the workspace
(e.g., via shell glob or find) and uses the newest match to set release_name and
build_version before defaulting to "0.1.0-dev", ensuring you reference the same
variables (release_file, release_name, build_version) and preserve the existing
sort -V | tail -n 1 behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dd1bb1d6-1608-4384-b0a2-3bca1546ee9b

📥 Commits

Reviewing files that changed from the base of the PR and between c446f67 and 3fea31f.

📒 Files selected for processing (7)
  • .changes/unreleased/embed-backend-build-version.yaml
  • Dockerfile
  • Makefile
  • cmd/hyperindex/main.go
  • cmd/hyperindex/main_test.go
  • internal/buildinfo/buildinfo.go
  • internal/buildinfo/buildinfo_test.go

@Kzoeps Kzoeps force-pushed the display-release-version branch from eca967f to fce9c54 Compare April 30, 2026 08:37
@railway-app railway-app Bot temporarily deployed to hyperindex-v2-setup / hyperindex-pr-43 April 30, 2026 08:37 Destroyed
@Kzoeps Kzoeps merged commit fbbc7b1 into main Apr 30, 2026
10 checks passed
@Kzoeps Kzoeps deleted the display-release-version branch April 30, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant