Show app version from git tag instead of dev commit-diff link#3196
Conversation
Replace the developer-only commit-diff link in the admin sidebar and both site footers with a friendly app version derived from the latest git tag (e.g. v0.27.3), linking to the GitHub release page for that tag. - Add AppVersion (app/lib) encapsulating the label + URL fallback chain: ENV['APP_VERSION'] (git describe) -> short ENV['GIT_REV'] -> 'dev'/'main'. When APP_VERSION is set the link points at releases/tag/<tag> (the git-describe '-N-gSHA' suffix is stripped so the link stays valid when a build is ahead of the latest tag); otherwise it falls back to the commit diff (GIT_REV) or the repo home. - Inject APP_VERSION at Docker build via an ARG/ENV in the runtime stage and pass it through Kamal (config/deploy.yml builder.args + env.clear), computed on the host from 'git describe --tags --always' since .git is excluded from the build context (.dockerignore). - Update admin layout leftbar_build_info and both footers to use AppVersion; keep the existing admin.leftbar.build i18n key. - Specs: AppVersion unit spec, component specs for both footers, and a component spec covering leftbar_build_info (APP_VERSION set vs unset).
|
We are no longer using the main -> prod merge, we are using main to deploy to staging and releases to deploy to prod. Does that change this? It seems very complicated! |
|
Good question — the new model actually makes this cleaner, not broken:
So no change is needed for it to work under main→staging / releases→prod. The "complicated" bit is the Kamal wiring, and there's one real simplification available: I didn't edit
|
Per review: drop the redundant runtime env.clear.APP_VERSION from deploy.yml. The Dockerfile already bakes the builder.args APP_VERSION into the image as ENV (ARG->ENV in the runtime stage), so the value reaches runtime without a duplicate env var — one git-describe instead of two. Also tidy the spec stubs to the real current version (v0.27.3).
|
Done — went with the simplest option. Pushed: dropped the redundant runtime And re: your version note — nothing hardcodes a version; |
What & why
Closes #2055.
The admin sidebar and both site footers previously showed a 7-char commit SHA linking to the merge diff that produced the deploy. That diff is only intelligible to developers and is noisy (it's the squashed
main→prodmerge). This replaces it with a friendly app version derived from the latest git tag (e.g.v0.27.3), linking to the matching GitHub release page.Changes
app/lib/app_version.rb— newAppVersionvalue object encapsulating the display logic, so the three call sites don't duplicate it:AppVersion.label(fallback:)→ENV['APP_VERSION']→ shortENV['GIT_REV'](first 7) →fallback('dev'for admin,'main'for footers).AppVersion.url→releases/tag/<tag>whenAPP_VERSIONis set (the-N-gSHAgit-describe suffix is stripped so the link stays valid when a build is ahead of the latest tag) → commit diff when onlyGIT_REVis set → repo home otherwise..presence), so a tarball deploy with no git context degrades gracefully.app/views/layouts/admin/application.rb(leftbar_build_info),app/components/footer.rb,app/components/directory/footer.rb— now useAppVersion. The existingadmin.leftbar.buildi18n key is kept.Dockerfile— addedARG APP_VERSION/ENV APP_VERSIONto the runtime stage..gitis excluded from the build context (.dockerignore), so the value cannot be derived inside the build and is passed in.config/deploy.yml— Kamal computesgit describe --tags --alwayson the host and passes it both as abuilder.argsbuild arg (baked into the image) and viaenv.clear(present in the running container), mirroring the existingRUBY_VERSIONpattern.Tests
spec/lib/app_version_spec.rb— label + URL fallback chain, suffix stripping, blank-env handling.spec/components/footer_component_spec.rb,spec/components/directory/footer_component_spec.rb— render the version + release link whenAPP_VERSIONis set, fall back tomain+ repo link when unset.spec/components/admin/leftbar_build_info_spec.rb— covers the admin sidebar fragment (APP_VERSIONset vs unset), asserts theBuildlabel is retained.All 15 examples pass; Rubocop clean.
The
Dockerfile/config/deploy.ymlgit describeinjection cannot be RSpec-verified and needs a maintainer to confirm on a real build/deploy thatAPP_VERSIONreaches the running container (and shows e.g.v0.27.3rather than a SHA) — particularly that the deploy host's checkout has tags available (git fetch --tags).Note:
config/appsignal.ymlstill usesGIT_REVfor revision tracking; that's intentionally left unchanged.🤖 Generated with Claude Code