ci: publish accepted releases to PyPI in one click
This commit is contained in:
1 parent
5f1df63d4e
commit
0dc8679edc
6 files changed
+142
-160
No files matched your search
@@ -1,4 +1,4 @@
|
||||
"""Stage only the publicly available files covered by an approved release manifest."""
|
||||
"""Stage published PyPI packages only when they match the accepted CI manifest."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -8,23 +8,21 @@ import re
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from nanobot.release_trust import verify_release_approval
|
||||
from nanobot.releases import ReleaseManifest
|
||||
|
||||
|
||||
def stage_release(release_dir: Path, output: Path, *, version: str, tag_commit: str) -> None:
|
||||
def stage_release(release_dir: Path, output: Path, *, accepted_manifest: Path, version: str, tag_commit: str) -> None:
|
||||
if not re.fullmatch(r"\d+\.\d+\.\d+", version):
|
||||
raise ValueError("Only final stable versions may be published to PyPI")
|
||||
manifest_path = release_dir / "release-manifest.json"
|
||||
proof_path = release_dir / "release-manifest.json.sigstore.json"
|
||||
for path, limit in ((manifest_path, 64 * 1024), (proof_path, 256 * 1024)):
|
||||
if path.is_symlink() or not path.is_file() or path.stat().st_size > limit:
|
||||
raise ValueError(f"Missing or invalid approval file: {path.name}")
|
||||
payload, proof = manifest_path.read_bytes(), proof_path.read_bytes()
|
||||
verify_release_approval(payload, proof)
|
||||
if manifest_path.is_symlink() or not manifest_path.is_file() or manifest_path.stat().st_size > 64 * 1024:
|
||||
raise ValueError("Missing or invalid release manifest")
|
||||
payload = manifest_path.read_bytes()
|
||||
if payload != accepted_manifest.read_bytes():
|
||||
raise ValueError("Public release manifest differs from the accepted CI manifest")
|
||||
manifest = ReleaseManifest.model_validate_json(payload)
|
||||
if manifest.version != version or manifest.candidate_commit != tag_commit:
|
||||
raise ValueError("Signed release identity does not match the version and tag")
|
||||
if manifest.version != version or manifest.source_commit != tag_commit or manifest.candidate_commit != tag_commit:
|
||||
raise ValueError("Accepted stable release identity does not match the version and tag")
|
||||
|
||||
for item in manifest.artifacts:
|
||||
path = release_dir / item.filename
|
||||
@@ -39,17 +37,19 @@ def stage_release(release_dir: Path, output: Path, *, version: str, tag_commit:
|
||||
for item in manifest.artifacts:
|
||||
if item.filename.endswith((".whl", ".tar.gz")):
|
||||
shutil.copyfile(release_dir / item.filename, output / item.filename)
|
||||
print(f"Staged signed release {version}: five wheels and one source distribution")
|
||||
print(f"Staged accepted release {version}: five wheels and one source distribution")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--release-dir", type=Path, required=True)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
parser.add_argument("--accepted-manifest", type=Path, required=True)
|
||||
parser.add_argument("--version", required=True)
|
||||
parser.add_argument("--tag-commit", required=True)
|
||||
args = parser.parse_args()
|
||||
stage_release(args.release_dir, args.output, version=args.version, tag_commit=args.tag_commit)
|
||||
stage_release(args.release_dir, args.output, accepted_manifest=args.accepted_manifest,
|
||||
version=args.version, tag_commit=args.tag_commit)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user