Report the build commit in avocado --version - #186
Open
jetm wants to merge 1 commit into
Open
Conversation
A bug report that says "avocado 1.0.0-rc.1" does not identify which build it came from, and release candidates move faster than the version number, so the same string covers many different binaries. build.rs already computed a short SHA into AVOCADO_CLI_VERSION, but nothing consumed it: the CLI declared a bare `#[command(version)]`, which clap fills from CARGO_PKG_VERSION. Consume that env var and report the commit in rustc's shape, "avocado 1.0.0-rc.1 (abc1234 2026-03-05)". Keeping the version in its own field leaves it a bare semver, so the comparisons that read it need no special handling for an appended commit. The date is the commit date rather than the build date, so rebuilding a commit yields the same string. This moves the version out of the last field, which two consumers were reading. Fix the one in this repo: check_cli_version took `split_whitespace().last()`, which now yields the commit date, and an unparseable version makes that check fail OPEN and silently accept a remote running an older CLI. It reads the second field via a parse_reported_version helper that still tolerates a bare version from an older remote. avocado-desktop's parse_cli_version needs the same fix and is handled separately. Harden the build script while it is being wired up. It unwrapped the git invocation, so building outside a checkout (source tarball, vendored crate) aborted the build instead of falling back to the bare version; it never trimmed the trailing newline off `rev-parse`, which would have put a line break inside the version string; and it declared no rerun-if-changed, so cargo cached the script output and kept reporting a stale commit. The rerun hint follows the branch ref rather than HEAD alone, because HEAD is a symref whose contents do not change on commit. Signed-off-by: Javier Tia <javier@peridio.com>
jetm
force-pushed
the
jtia/version-git-sha
branch
from
July 31, 2026 23:40
e566baa to
730d38b
Compare
Contributor
Author
|
Companion PR: avocado-linux/avocado-desktop#73 fixes the other consumer of this line ( Suggested order: merge the desktop one first. It accepts both the old bare |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
avocado --versionreports onlyavocado 1.0.0-rc.1, which does not identify which build a user is running. Release candidates move faster than the version number, so one string covers many different binaries and a bug report cannot be tied to a commit.build.rsalready computed a short SHA intoAVOCADO_CLI_VERSION, but nothing consumed it: the CLI declared a bare#[command(version)], which clap fills fromCARGO_PKG_VERSION.Solution
Report the commit in rustc's shape:
Keeping the version in its own field leaves it a bare semver, so version comparisons need no special handling for an appended commit. The date is the commit date, not the build date, so rebuilding the same commit yields the same string.
This does move the version out of the last field, which two consumers were reading:
utils::remote::check_cli_version(this repo) — fixed here.parse_cli_version— fixed in avocado-linux/avocado-desktop#73. That one accepts both the old and new shapes, so it is safe to merge first and is correct against today's released CLI too.Key changes
main.rs:#[command(version = env!("AVOCADO_CLI_VERSION"))], so the valuebuild.rscomputes actually reaches--version.build.rsemits<version> (<short-sha> <commit-date>), and is hardened: it unwrapped the git invocation, so building outside a checkout (source tarball, vendored crate) aborted the build instead of falling back to the bare version; it never trimmed the trailing newline offrev-parse, which would have put a line break inside the version string; and it declared norerun-if-changed, so cargo cached the script output and kept reporting a stale commit. The rerun hint follows the branch ref, notHEADalone, becauseHEADis a symref whose contents do not change on commit.check_cli_versionreads the version field via aparse_reported_versionhelper instead ofsplit_whitespace().last(), which now yields the commit date. This matters beyond cosmetics: an unparseable version makes that check fail open and silently accept a remote running an older CLI. The helper still tolerates a bare version from an older remote.tests/version.rs: the version field is a bare semver equal to the crate version, and the line carries the current commit and date (skips outside a git checkout).parse_reported_versionacross the new shape, the old bare shape, and a version with no prefix.Reviewer notes
avocado 1.0.0-rc.1 (e566baa 2026-07-31); committing without touchingbuild.rsrebuilds and reports the new commit, which is the check that the stale-commit fix actually works.cargo fmt,cargo clippy --all-targets --all-features -- -D warnings, and the fullcargo testsuite are clean.actions/checkout@v5leaves.gitpresent, so release and PR builds resolve a commit;crossmusl builds and the Windowscargo checkfall back to the bare version if git is unavailable rather than failing.env!("TARGET")from the same build script is unchanged (still used byavocado upgrade)..dirtymarker for uncommitted builds was deliberately left out to keep this focused; easy follow-up if wanted.