Skip to content

chore: auto-inject release version into server binary and OpenAPI spec#81

Merged
SyniRon merged 1 commit into
developfrom
chore/auto-version-injection
May 20, 2026
Merged

chore: auto-inject release version into server binary and OpenAPI spec#81
SyniRon merged 1 commit into
developfrom
chore/auto-version-injection

Conversation

@SyniRon
Copy link
Copy Markdown
Collaborator

@SyniRon SyniRon commented May 20, 2026

Summary

Eliminates the manual two-place version bump (the const in servers/server.go and the info.version literal in both .proto files) 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 -ldflags can override at link time.
  • proto/milpacs.proto + proto/tickets.proto: openapiv2_swagger info.version switched to the "dev" sentinel; make generate re-baked accordingly.
  • Dockerfile: accepts ARG VERSION=dev and passes it through -ldflags="-X github.com/7cav/api/servers.version=${VERSION}". Local docker build without --build-arg still works and produces a "dev" image.
  • .github/workflows/build_and_push.yml: new step before docker build sed-substitutes ${{ github.ref_name }} into both .proto files; the same value is passed as a build-arg so the Dockerfile's make generate step bakes the right info.version into 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: dev
  • go build -ldflags="-X github.com/7cav/api/servers.version=2.2.1-test" → startup log: Starting 7Cav API version: 2.2.1-test
  • make generate clean with the "dev" sentinel; both openapi JSONs render "version": "dev" as expected
  • First real release tag fires build_and_push.yml successfully (validation deferred to the actual 2.2.1 cut)

Note

build_and_push.yml only fires on release: 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

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>
@SyniRon SyniRon merged commit 86a96bd into develop May 20, 2026
2 checks passed
@SyniRon SyniRon deleted the chore/auto-version-injection branch May 20, 2026 01:02
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