chore: auto-inject release version into server binary and OpenAPI spec#81
Merged
Conversation
Eliminates the manual two-place version bump that's been a recurring near-miss at release time (the 2.2.0 deploy nearly shipped with the const unbumped; only caught because PR #53 happened to include it). Changes: - servers/server.go: `const version = "2.2.0"` → `var version = "dev"` so -ldflags can override at link time. - proto/milpacs.proto + proto/tickets.proto: openapiv2_swagger info.version literal switched to "dev" sentinel. - Dockerfile: accepts `ARG VERSION=dev`, passes it through `-ldflags="-X github.com/7cav/api/servers.version=${VERSION}"`. - .github/workflows/build_and_push.yml: new step that sed-substitutes `${{ github.ref_name }}` into both .proto files before docker build, and passes the same value through as a build-arg. Both the runtime server log and the OpenAPI spec at `/` will report the released tag on production builds; local dev builds continue to report "dev". Mirrors the ldflags-injection pattern cavbot2 adopted in 0.7.4. Verified locally: - `go build` → "Starting 7Cav API version: dev" - `go build -ldflags=...` → "Starting 7Cav API version: 2.2.1-test" - `make generate` clean with the "dev" sentinel; openapi JSONs render `"version": "dev"` as expected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eliminates the manual two-place version bump (the
constinservers/server.goand theinfo.versionliteral in both.protofiles) that's been a recurring near-miss at release time. The 2.2.0 deploy nearly shipped with the constant un-bumped; only caught because PR #53 happened to carry the bump.Changes
servers/server.go:const version = "2.2.0"→var version = "dev"so-ldflagscan override at link time.proto/milpacs.proto+proto/tickets.proto:openapiv2_swaggerinfo.versionswitched to the"dev"sentinel;make generatere-baked accordingly.Dockerfile: acceptsARG VERSION=devand passes it through-ldflags="-X github.com/7cav/api/servers.version=${VERSION}". Localdocker buildwithout--build-argstill works and produces a "dev" image..github/workflows/build_and_push.yml: new step before docker build sed-substitutes${{ github.ref_name }}into both.protofiles; the same value is passed as abuild-argso the Dockerfile'smake generatestep bakes the rightinfo.versioninto the OpenAPI spec served at/.Mirrors the ldflags-injection pattern cavbot2 adopted in 0.7.4.
Test plan
go build(no flags) → startup log:Starting 7Cav API version: devgo build -ldflags="-X github.com/7cav/api/servers.version=2.2.1-test"→ startup log:Starting 7Cav API version: 2.2.1-testmake generateclean with the"dev"sentinel; both openapi JSONs render"version": "dev"as expectedbuild_and_push.ymlsuccessfully (validation deferred to the actual 2.2.1 cut)Note
build_and_push.ymlonly fires onrelease: published— go.yml's Build + Lint will pass on this PR but won't exercise the release workflow itself. The real test is the next tag cut. If the sed pattern or build-arg flow has a bug, the release build fails and we revert; no runtime impact.🤖 Generated with Claude Code