Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions tests/python/test_release_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <VERSION>-<count>-g<commit> 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<VERSION> 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)
4 changes: 4 additions & 0 deletions version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading