fix(deploy): rebuild when deployed binary is stale, not just on ref change #31

Merged
addison merged 2 commits from fix/deploy-retry-stale-binary into main 2026-08-12 05:50:48 -04:00
Collaborator

Problem

If a deploy fast-forwarded the git ref but the build failed (as happened with the missing npm dep), subsequent runs of deploy.sh saw before == after and exited as a no-op — never retrying the build. A human had to rebuild and restart manually.

Changes

  • deploy/deploy.sh: after fetch/pull, also checks whether the deployed binary is stale. It runs /usr/local/bin/kwila-tournaments --version 2>&1 and greps for HEAD's short SHA (the build embeds it via -ldflags -X main.Version, e.g. 2026.8.12+1cdcdda). The script now rebuilds + redeploys when the binary version doesn't match HEAD or the binary is missing entirely, even when the git ref is unchanged. No-op only when both ref and binary match.
  • main.go: fixes --version, which previously printed PocketBase's own (untracked) version. app.RootCmd.Version = Version wires in the build-time version so the flag reports it on stdout.
  • deploy/README.md: clarifies that "up to date" means both git ref AND deployed binary match HEAD.

Testing

  • bash -n syntax check; detection snippet verified against the real deployed binary (read-only)
  • End-to-end simulation with stubbed git/just/sudo: stale binary → rebuilds, up-to-date binary → no-op, missing binary → rebuilds
  • go test passes on all backend packages; --version output verified with a test-ldflags build

Note: the deploy script greps combined 2>&1 output, so it works with both the currently-deployed binary (version only in the stderr startup log) and new binaries (version in --version stdout).

## Problem If a deploy fast-forwarded the git ref but the build failed (as happened with the missing npm dep), subsequent runs of `deploy.sh` saw `before == after` and exited as a no-op — never retrying the build. A human had to rebuild and restart manually. ## Changes - **`deploy/deploy.sh`**: after fetch/pull, also checks whether the deployed binary is stale. It runs `/usr/local/bin/kwila-tournaments --version 2>&1` and greps for HEAD's short SHA (the build embeds it via `-ldflags -X main.Version`, e.g. `2026.8.12+1cdcdda`). The script now rebuilds + redeploys when the binary version doesn't match HEAD or the binary is missing entirely, even when the git ref is unchanged. No-op only when both ref and binary match. - **`main.go`**: fixes `--version`, which previously printed PocketBase's own `(untracked)` version. `app.RootCmd.Version = Version` wires in the build-time version so the flag reports it on stdout. - **`deploy/README.md`**: clarifies that "up to date" means both git ref AND deployed binary match HEAD. ## Testing - `bash -n` syntax check; detection snippet verified against the real deployed binary (read-only) - End-to-end simulation with stubbed `git`/`just`/`sudo`: stale binary → rebuilds, up-to-date binary → no-op, missing binary → rebuilds - `go test` passes on all backend packages; `--version` output verified with a test-ldflags build Note: the deploy script greps combined `2>&1` output, so it works with both the currently-deployed binary (version only in the stderr startup log) and new binaries (version in `--version` stdout).
If a deploy fast-forwarded the git ref but the build failed, subsequent
runs saw before == after and exited as a no-op, never retrying the build.

Now deploy.sh also checks the deployed binary's version (which embeds
HEAD's short sha via -ldflags -X main.Version) and rebuilds when it is
stale or the binary is missing entirely.

Co-authored-by: Shelley <[email protected]>
fix(cli): report build version in --version output
All checks were successful
PR Validation / validate (pull_request) Successful in 4m30s
8c92991740
PocketBase's root command is constructed with its own Version variable
("(untracked)"), so --version never reported the version embedded at
build time via -ldflags -X main.Version. Override RootCmd.Version after
pocketbase.New() so --version prints it (e.g. 2026.8.12+1cdcdda) on
stdout, which the deploy script uses to detect a stale binary.

Co-authored-by: Shelley <[email protected]>
addison deleted branch fix/deploy-retry-stale-binary 2026-08-12 05:50:48 -04:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kwila/tournaments!31
No description provided.