Fix version badge for non-Docker installs - #459
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the app’s version badge incorrectly showing 0 in non-Docker installs by improving how the application determines app_version, and by baking a VERSION file into the exported source ZIP.
Changes:
- Update
app_versioninitialization to fall back throughVERSIONandgit describebefore defaulting to"0". - Add a helper test for
version_badgerendering. - Write (and clean up) a
VERSIONfile duringbin/releasesource export, and ignore it in git.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
config/initializers/version.rb |
Implements version fallback chain (ENV → VERSION file → git describe → "0"). |
test/helpers/version_helper_test.rb |
Adds coverage for version_badge HTML rendering. |
bin/release |
Writes a VERSION file into the source ZIP export and attempts cleanup afterward. |
.gitignore |
Prevents locally-generated VERSION from being committed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| version_file = Rails.root.join("VERSION") | ||
| if version_file.exist? | ||
| version_file.read.strip | ||
| else | ||
| `git describe --tags --always 2>/dev/null`.strip.presence || "0" | ||
| end |
| assert_equal '<span class="product__version-badge">1.2.0</span>', version_badge | ||
| end | ||
|
|
||
| test "version_badge renders fallback zero when no version is set" do |
| Rails.application.config.app_version = ENV.fetch("APP_VERSION") do | ||
| version_file = Rails.root.join("VERSION") | ||
| if version_file.exist? | ||
| version_file.read.strip | ||
| else | ||
| `git describe --tags --always 2>/dev/null`.strip.presence || "0" | ||
| end |
Fall back through a VERSION file and `git describe --tags --always` before reaching "0", so the badge renders correctly for fresh clones without a tagged release. Fixes basecamp#447.
3bbab9e to
455777f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
config/initializers/version.rb:6
- If the VERSION file exists but is empty/whitespace, this currently sets app_version to an empty string, which will render a blank badge and blank X-Version header. Consider treating blank VERSION contents as “not set” and falling back to
git describe …(and then "0").
version_file = Rails.root.join("VERSION")
if version_file.exist?
version_file.read.strip
else
`git describe --tags --always 2>/dev/null`.strip.presence || "0"
test/helpers/version_helper_test.rb:17
- This test name says it covers the “no version is set” case, but it explicitly sets
app_versionto "0". Renaming the test will make it accurately describe what’s being asserted.
test "version_badge renders fallback zero when no version is set" do
config/initializers/version.rb:7
- The initializer now contains fallback logic (VERSION file ->
git describe-> "0"), but there’s no test coverage verifying these paths. Adding tests around the version resolution (e.g., extracting it to a small method/class that can be unit-tested while stubbing ENV, file existence/contents, and the git command) would prevent regressions.
Rails.application.config.app_version = ENV.fetch("APP_VERSION") do
version_file = Rails.root.join("VERSION")
if version_file.exist?
version_file.read.strip
else
`git describe --tags --always 2>/dev/null`.strip.presence || "0"
end
The version badge fell back to "0" whenever
APP_VERSIONwasn't set as an env var, which happens for fresh clones without a tagged release.Fall back through a
VERSIONfile andgit describe --tags --alwaysbefore reaching "0".Fixes #447.