Skip to content

Commit c043452

Browse files
author
CometAPI
committed
fix: harden stable release finalization
1 parent b3360d6 commit c043452

3 files changed

Lines changed: 50 additions & 14 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ Project links: [CometAPI](https://www.cometapi.com),
2929

3030
## Installation
3131

32-
Install the stable release from PyPI with:
32+
After the protected publication workflow and public-registry verification
33+
succeed, install the stable release from PyPI with:
3334

3435
```bash
3536
python -m pip install 'cometapi==0.1.0'
3637
```
3738

38-
See the immutable
39+
After those gates succeed, the immutable
3940
[GitHub release](https://github.com/cometapi-dev/cometapi-python/releases/tag/v0.1.0)
4041
and exact [PyPI release](https://pypi.org/project/cometapi/0.1.0/) for the
4142
published artifact.

scripts/check_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _artifact_version(path: Path) -> str:
6767
}
6868

6969

70-
def require_canonical_tag(tag: str, project_version: str) -> str:
70+
def _require_canonical_tag(tag: str, project_version: str) -> str:
7171
normalized = normalize_version(project_version)
7272
alpha = re.fullmatch(r"(?P<base>\d+\.\d+\.\d+)a(?P<number>\d+)", normalized)
7373
expected = (
@@ -310,7 +310,7 @@ def main() -> int:
310310
if args.expected:
311311
versions.append(("expected", args.expected))
312312
if args.tag:
313-
versions.append(("tag", require_canonical_tag(args.tag, project)))
313+
versions.append(("tag", _require_canonical_tag(args.tag, project)))
314314
for value in args.artifacts:
315315
path = Path(value)
316316
if not path.is_file():

tests/test_release_documents.py

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import shutil
34
import subprocess
45
import sys
56
from collections.abc import Callable
@@ -15,16 +16,20 @@
1516
CANONICAL_SUPPORT,
1617
CheckError,
1718
)
18-
from scripts.check_version import (
19-
require_canonical_tag,
20-
require_public_preview_docs,
21-
require_releasable_docs,
22-
)
19+
from scripts.check_version import require_public_preview_docs, require_releasable_docs
2320

2421
PROJECT_ROOT = Path(__file__).resolve().parents[1]
2522
VERSION_SCRIPT = PROJECT_ROOT / "scripts" / "check_version.py"
2623

2724

25+
def _copy_version_checker(root: Path) -> Path:
26+
scripts = root / "scripts"
27+
scripts.mkdir(exist_ok=True)
28+
for name in ("_checks.py", "check_version.py"):
29+
shutil.copy2(PROJECT_ROOT / "scripts" / name, scripts / name)
30+
return scripts / "check_version.py"
31+
32+
2833
def _write_release_documents(root: Path) -> None:
2934
files = {
3035
"pyproject.toml": f'''\
@@ -256,11 +261,41 @@ def test_release_version_cli_accepts_current_stable_tag() -> None:
256261
assert "version agreement passed: 0.1.0" in result.stdout
257262

258263

259-
def test_release_version_accepts_approved_initial_alpha_recovery_tag() -> None:
260-
assert require_canonical_tag("v0.1.0-alpha.1+recovery.1", "0.1.0a1") == "0.1.0a1"
264+
def test_release_version_cli_accepts_approved_initial_alpha_recovery_tag(
265+
releasable_documents: Path,
266+
) -> None:
267+
version_script = _copy_version_checker(releasable_documents)
268+
result = subprocess.run(
269+
[
270+
sys.executable,
271+
str(version_script),
272+
"--tag",
273+
"v0.1.0-alpha.1+recovery.1",
274+
"--require-changelog",
275+
],
276+
cwd=releasable_documents,
277+
text=True,
278+
check=False,
279+
capture_output=True,
280+
)
281+
282+
assert result.returncode == 0, result.stderr
283+
assert "version agreement passed: 0.1.0a1" in result.stdout
261284

262285

263286
@pytest.mark.parametrize("tag", ["v0.1.0-alpha.1", "v0.1.0-alpha.1+recovery.2"])
264-
def test_release_version_rejects_unapproved_initial_alpha_tag(tag: str) -> None:
265-
with pytest.raises(CheckError, match="release tag must use an approved spelling"):
266-
require_canonical_tag(tag, "0.1.0a1")
287+
def test_release_version_cli_rejects_unapproved_initial_alpha_tag(
288+
releasable_documents: Path,
289+
tag: str,
290+
) -> None:
291+
version_script = _copy_version_checker(releasable_documents)
292+
result = subprocess.run(
293+
[sys.executable, str(version_script), "--tag", tag, "--require-changelog"],
294+
cwd=releasable_documents,
295+
text=True,
296+
check=False,
297+
capture_output=True,
298+
)
299+
300+
assert result.returncode != 0
301+
assert "release tag must use an approved spelling" in result.stderr

0 commit comments

Comments
 (0)