60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: MIT
|
|
"""Check candidate numbering and covered-commit reruns with real Git tags."""
|
|
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
|
|
|
|
VERSION = Path(__file__).with_name("version.py")
|
|
|
|
|
|
def git(root: Path, *args: str) -> str:
|
|
result = subprocess.run(
|
|
["git", *args], cwd=root, text=True, check=True, capture_output=True
|
|
)
|
|
return result.stdout.strip()
|
|
|
|
|
|
def selected(root: Path, branch: str) -> dict[str, str]:
|
|
result = subprocess.run(
|
|
["python3", str(VERSION), branch], cwd=root,
|
|
text=True, check=True, capture_output=True
|
|
)
|
|
return dict(line.split("=", 1) for line in result.stdout.splitlines())
|
|
|
|
|
|
def main() -> None:
|
|
with tempfile.TemporaryDirectory(prefix="alkane-os-version-") as path:
|
|
root = Path(path)
|
|
(root / "ci").mkdir()
|
|
(root / "ci/version-x.txt").write_text("0\n")
|
|
git(root, "init", "-q")
|
|
git(root, "config", "user.name", "Alkane CI")
|
|
git(root, "config", "user.email", "ci@example.invalid")
|
|
git(root, "add", ".")
|
|
git(root, "commit", "-qm", "First source")
|
|
first = git(root, "rev-parse", "HEAD")
|
|
assert selected(root, "next") == {
|
|
"release": "true", "tag": "v0.1.0-rc.1", "version": "0.1.0-rc.1"
|
|
}
|
|
git(root, "tag", "v0.1.0-rc.1")
|
|
assert selected(root, "next") == {"release": "false"}
|
|
|
|
(root / "README.md").write_text("A later merge.\n")
|
|
git(root, "add", ".")
|
|
git(root, "commit", "-qm", "Later source")
|
|
assert selected(root, "next") == {
|
|
"release": "true", "tag": "v0.1.0-rc.2", "version": "0.1.0-rc.2"
|
|
}
|
|
git(root, "tag", "v0.1.0-rc.2")
|
|
assert selected(root, "next") == {"release": "false"}
|
|
git(root, "checkout", "-q", first)
|
|
assert selected(root, "next") == {"release": "false"}
|
|
print("PASS: exact and superseded candidate reruns do not publish")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|