fix: resolve VERSION_NUMBER placeholder shown in --version output#69
fix: resolve VERSION_NUMBER placeholder shown in --version output#69JonathanRohland-TNG wants to merge 1 commit intoTNG:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes please --version printing the unreplaced VERSION_NUMBER placeholder when running from a source checkout or when installed via AUR packaging.
Changes:
- Add a
display_version()fallback that derives the version from git tags when the placeholder is still present. - Patch the AUR
PKGBUILDto sed-replace the placeholder duringprepare(). - Extend BATS tests to assert
--versionno longer containsVERSION_NUMBER, and to validate the git-tag fallback behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
test/main.bats |
Adds assertions ensuring --version is a real version and matches the derived git-tag fallback. |
please.sh |
Introduces _version placeholder variable and git-tag fallback logic in display_version(). |
PKGBUILD |
Adds prepare() step to replace the VERSION_NUMBER placeholder using a git-derived version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # bump-version CI workflow via sed. If it is still the literal string, the | ||
| # script is running from source or an unpatched install — fall back to git tags. | ||
| if [ "$_version" = "VERSION_NUMBER" ]; then | ||
| if [ -d "${_script_dir}/.git" ]; then |
There was a problem hiding this comment.
_tag is assigned inside display_version() without being declared local, which leaks a global variable into the script’s environment. Declare it as a local variable within the function to avoid unintended side effects with other globals.
| if [ -d "${_script_dir}/.git" ]; then | |
| if [ -d "${_script_dir}/.git" ]; then | |
| local _tag |
| # Replace VERSION_NUMBER placeholder with the actual version derived from git tags. | ||
| _pkgver=$(git tag --sort=v:refname | tail -n1) | ||
| sed -i -e "s/VERSION_NUMBER/${_pkgver#v}/" 'please.sh' |
There was a problem hiding this comment.
prepare() replaces VERSION_NUMBER using the highest tag in the repository, not necessarily the tag for the checked-out commit. This can produce an incorrect embedded version when building a specific release (VERSION set) or building from a commit that isn’t at the latest tag. Prefer deriving the tag from the current HEAD (or use $VERSION when it’s set), and handle the case where no tag is found so you don’t replace the placeholder with an empty string.
| # Replace VERSION_NUMBER placeholder with the actual version derived from git tags. | |
| _pkgver=$(git tag --sort=v:refname | tail -n1) | |
| sed -i -e "s/VERSION_NUMBER/${_pkgver#v}/" 'please.sh' | |
| # Replace VERSION_NUMBER with the version for the checked-out revision. | |
| if [ -n "$VERSION" ]; then | |
| _pkgver="$VERSION" | |
| else | |
| _pkgver=$(git tag --points-at HEAD --sort=v:refname | tail -n1) | |
| fi | |
| if [ -n "$_pkgver" ]; then | |
| sed -i -e "s/VERSION_NUMBER/${_pkgver#v}/" 'please.sh' | |
| fi |
| @test "version fallback derives version from git tags" { | ||
| _latest_tag=$(cd "$BATS_TEST_DIRNAME/.." && git tag --sort=v:refname | tail -n1) | ||
| _latest_tag="${_latest_tag#v}" | ||
| result=$($PLEASE_EXE '--version') | ||
| [ "$result" == "Please v${_latest_tag}" ] |
There was a problem hiding this comment.
These tests assume the local checkout has git tags available. In GitHub Actions, actions/checkout often fetches a shallow clone without tags, which would make _latest_tag empty and also make please --version fall back to printing VERSION_NUMBER, failing both assertions. Consider skipping these assertions when no tags are present, or adjust the test setup to ensure tags are fetched/available before running the tests.
| # script is running from source or an unpatched install — fall back to git tags. | ||
| if [ "$_version" = "VERSION_NUMBER" ]; then | ||
| if [ -d "${_script_dir}/.git" ]; then | ||
| _tag=$(cd "$_script_dir" && git tag --sort=v:refname 2>/dev/null | tail -n1) |
There was a problem hiding this comment.
The fallback version is derived from the highest tag in the repo (git tag --sort=v:refname | tail -n1), which can be incorrect if the user is on an older commit/branch (it can report a tag that doesn't point to the checked-out commit). Consider deriving the version from the current commit (e.g., nearest tag reachable from HEAD / tag pointing at HEAD) so --version reflects the code being executed.
| # script is running from source or an unpatched install — fall back to git tags. | |
| if [ "$_version" = "VERSION_NUMBER" ]; then | |
| if [ -d "${_script_dir}/.git" ]; then | |
| _tag=$(cd "$_script_dir" && git tag --sort=v:refname 2>/dev/null | tail -n1) | |
| # script is running from source or an unpatched install — fall back to a tag | |
| # that describes the currently checked-out commit. | |
| if [ "$_version" = "VERSION_NUMBER" ]; then | |
| if [ -d "${_script_dir}/.git" ]; then | |
| _tag=$(cd "$_script_dir" && git describe --tags --exact-match 2>/dev/null) | |
| if [ -z "$_tag" ]; then | |
| _tag=$(cd "$_script_dir" && git describe --tags --abbrev=0 2>/dev/null) | |
| fi |
438c478 to
02743c6
Compare
When please-cli is installed from AUR or run from source, the VERSION_NUMBER placeholder was never replaced, causing 'please -v' to print 'Please vVERSION_NUMBER' instead of the actual version. - Add git-tag fallback in display_version() when placeholder is still present (covers running from source / git clone) - Add sed replacement in PKGBUILD prepare() (covers AUR installs) - Add test asserting --version output contains a real version Signed-off-by: OpenCode Agent <agent@tngtech.com>
02743c6 to
8930907
Compare
When please-cli is installed from AUR or run from source, the VERSION_NUMBER placeholder was never replaced, causing 'please -v' to print 'Please vVERSION_NUMBER' instead of the actual version.