ci: publish accepted releases to PyPI in one click

This commit is contained in:
Xubin Ren committed 2026-11-21 20:11:34 +08:00
1 parent 5f1df63d4e
commit 0dc8679edc
6 files changed
+142 -160

No files matched your search

+16 -17
View File
@@ -7,7 +7,7 @@ from scripts import prepare_pypi_release
@pytest.fixture
def approved_release(tmp_path, monkeypatch):
def accepted_release(tmp_path):
source = tmp_path / "release"
source.mkdir()
artifacts = []
@@ -15,26 +15,27 @@ def approved_release(tmp_path, monkeypatch):
data = filename.encode()
(source / filename).write_bytes(data)
artifacts.append(ReleaseArtifact(filename=filename, size=len(data), sha256=hashlib.sha256(data).hexdigest()))
manifest = ReleaseManifest(version="1.2.3", source_commit="a" * 40, candidate_commit="b" * 40,
manifest = ReleaseManifest(version="1.2.3", source_commit="b" * 40, candidate_commit="b" * 40,
requires_python=">=3.11", artifacts=artifacts)
(source / "release-manifest.json").write_text(manifest.model_dump_json())
(source / "release-manifest.json.sigstore.json").write_bytes(b"proof")
monkeypatch.setattr(prepare_pypi_release, "verify_release_approval", lambda payload, proof: None)
return source, tmp_path / "output"
payload = manifest.model_dump_json()
(source / "release-manifest.json").write_text(payload)
accepted = tmp_path / "accepted-manifest.json"
accepted.write_text(payload)
return source, tmp_path / "output", accepted
def test_stages_only_matching_pypi_distributions(approved_release):
source, output = approved_release
prepare_pypi_release.stage_release(source, output, version="1.2.3", tag_commit="b" * 40)
def test_stages_only_matching_pypi_distributions(accepted_release):
source, output, accepted = accepted_release
prepare_pypi_release.stage_release(source, output, accepted_manifest=accepted, version="1.2.3", tag_commit="b" * 40)
assert {path.name for path in output.iterdir()} == {
name for name in release_filenames("1.2.3") if name.endswith((".whl", ".tar.gz"))
}
assert all(path.read_bytes() == (source / path.name).read_bytes() for path in output.iterdir())
@pytest.mark.parametrize("failure", ["changed", "missing_archive", "wrong_tag", "invalid_signature", "preview"])
def test_refuses_unapproved_or_incomplete_release(approved_release, monkeypatch, failure):
source, output = approved_release
@pytest.mark.parametrize("failure", ["changed", "missing_archive", "wrong_tag", "different_manifest", "preview"])
def test_refuses_unaccepted_or_incomplete_release(accepted_release, failure):
source, output, accepted = accepted_release
version, commit = "1.2.3", "b" * 40
archive = next(source.glob("nanobot-tui-*.zip"))
if failure == "changed":
@@ -44,12 +45,10 @@ def test_refuses_unapproved_or_incomplete_release(approved_release, monkeypatch,
archive.unlink()
elif failure == "wrong_tag":
commit = "c" * 40
elif failure == "invalid_signature":
def reject(payload, proof):
raise ValueError("invalid signature")
monkeypatch.setattr(prepare_pypi_release, "verify_release_approval", reject)
elif failure == "different_manifest":
(source / "release-manifest.json").write_bytes(accepted.read_bytes() + b"\n")
else:
version = "1.2.3.dev1"
with pytest.raises(ValueError):
prepare_pypi_release.stage_release(source, output, version=version, tag_commit=commit)
prepare_pypi_release.stage_release(source, output, accepted_manifest=accepted, version=version, tag_commit=commit)
assert not output.exists()