diff --git a/tests/python/test_release_version.py b/tests/python/test_release_version.py index 8dfc3e26b..16b3714a9 100644 --- a/tests/python/test_release_version.py +++ b/tests/python/test_release_version.py @@ -76,3 +76,62 @@ def test_only_v_tags_trigger_and_a_tag_can_be_rebuilt(): assert "aura-v" not in text # A manual run can rebuild an existing tag's sources under that tag's label. assert re.search(r"workflow_dispatch:\s*\n\s*inputs:\s*\n\s*tag:", text) + + +def _run_version_sh(repo, env=None): + merged = {"PATH": "/usr/bin:/bin:/opt/homebrew/bin"} + if env: + merged.update(env) + result = subprocess.run( + ["sh", str(repo / "version.sh")], cwd=repo, capture_output=True, text=True, check=True, + env=merged) + match = re.fullmatch(r'#define BUILD_TAG "([^"]+)"\n', result.stdout) + assert match, result.stdout + return match.group(1) + + +def test_version_sh_includes_commit_count_after_release_tag(tmp_path): + """Post-tag git builds carry --g so Stage 2 downgrade checks can order them.""" + repo = tmp_path / "aura" + repo.mkdir() + (repo / "version.sh").write_text((REPO / "version.sh").read_text()) + (repo / "VERSION").write_text("1.0.0b18\n") + git_env = { + "PATH": "/usr/bin:/bin:/opt/homebrew/bin", + "GIT_AUTHOR_NAME": "Test", + "GIT_AUTHOR_EMAIL": "test@example.invalid", + "GIT_COMMITTER_NAME": "Test", + "GIT_COMMITTER_EMAIL": "test@example.invalid", + } + + def git(*args): + subprocess.run(["git", *args], cwd=repo, check=True, capture_output=True, env=git_env) + + git("init", "-q") + git("add", "VERSION", "version.sh") + git("commit", "-q", "-m", "release") + git("tag", "-a", "v1.0.0b18", "-m", "v1.0.0b18") + assert _run_version_sh(repo) == "1.0.0b18" + + for i in (1, 2): + (repo / "note.txt").write_text(f"commit {i}\n") + git("add", "note.txt") + git("commit", "-q", "-m", f"change {i}") + sha = subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"], cwd=repo, text=True).strip() + tag = _run_version_sh(repo) + assert tag == f"1.0.0b18-2-g{sha}" + assert re.fullmatch(UPDATER_PATTERN, tag) + + (repo / "note.txt").write_text("dirty\n") + dirty_tag = _run_version_sh(repo) + assert dirty_tag == f"1.0.0b18-2-g{sha}-dirty" + assert re.fullmatch(UPDATER_PATTERN, dirty_tag) + + # Without an ancestor v tag (e.g. VERSION bumped before tagging), omit the count. + (repo / "VERSION").write_text("1.0.0b19\n") + git("add", "VERSION", "note.txt") + git("commit", "-q", "-m", "bump version") + sha2 = subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"], cwd=repo, text=True).strip() + untagged = _run_version_sh(repo) + assert untagged == f"1.0.0b19-g{sha2}" + assert re.fullmatch(UPDATER_PATTERN, untagged) diff --git a/version.sh b/version.sh index 4eeed3c82..79cf4b945 100755 --- a/version.sh +++ b/version.sh @@ -12,6 +12,10 @@ if [ -n "$AURA_VERSION_TAG" ]; then elif [ -e ".git" ] && commit="$(git rev-parse --short=8 HEAD 2>/dev/null)"; then if [ "$(git describe --tags --exact-match HEAD 2>/dev/null)" = "v$release" ]; then version="$release" + elif git merge-base --is-ancestor "v$release" HEAD 2>/dev/null && + count="$(git rev-list --count "v$release..HEAD" 2>/dev/null)" && + [ -n "$count" ] && [ "$count" -gt 0 ] 2>/dev/null; then + version="$release-$count-g$commit" else version="$release-g$commit" fi