|
| 1 | +"""Validate a release tag and the complete macOS distribution set locally.""" |
| 2 | + |
| 3 | +import argparse |
| 4 | +from email.parser import BytesParser |
| 5 | +from pathlib import Path |
| 6 | +import tarfile |
| 7 | +import tomllib |
| 8 | +import zipfile |
| 9 | + |
| 10 | +from check_artifact import check_sdist, check_wheel, require |
| 11 | + |
| 12 | + |
| 13 | +def main(): |
| 14 | + parser = argparse.ArgumentParser(description=__doc__) |
| 15 | + parser.add_argument("--tag", help="Git release tag, for example v0.1.0") |
| 16 | + parser.add_argument("--dist", type=Path, help="Directory containing four wheels and one source archive") |
| 17 | + args = parser.parse_args() |
| 18 | + root = Path(__file__).resolve().parents[1] |
| 19 | + version = tomllib.loads((root / "Cargo.toml").read_text())["package"]["version"] |
| 20 | + require(args.tag is None or args.tag == "v" + version, "release tag does not match Cargo.toml") |
| 21 | + require("\n## " + version + " (" in (root / "CHANGELOG.md").read_text(), "release changelog entry missing") |
| 22 | + if args.dist is not None: |
| 23 | + expected = {f"gixpython-{version}-{abi}-macosx_11_0_{arch}.whl" |
| 24 | + for abi in ("cp311-abi3", "cp314-cp314t") for arch in ("arm64", "x86_64")} |
| 25 | + expected.add(f"gixpython-{version}.tar.gz") |
| 26 | + require({path.name for path in args.dist.iterdir()} == expected, |
| 27 | + "release must contain exactly four macOS wheels and one matching source archive") |
| 28 | + stubs = {path.name for path in (root / "python/gix").glob("*.pyi")} |
| 29 | + for path in sorted(args.dist.iterdir()): |
| 30 | + if path.suffix == ".whl": |
| 31 | + with zipfile.ZipFile(path) as archive: |
| 32 | + metadata_name, = [name for name in archive.namelist() if name.endswith(".dist-info/METADATA")] |
| 33 | + metadata = BytesParser().parsebytes(archive.read(metadata_name)) |
| 34 | + wheel = BytesParser().parsebytes(archive.read(metadata_name.removesuffix("METADATA") + "WHEEL")) |
| 35 | + require(metadata["Version"] == version, "wheel metadata version does not match release") |
| 36 | + tag = path.name.removesuffix(".whl").split("-", 2)[2] |
| 37 | + require(wheel.get_all("Tag") == [tag], "wheel ABI/platform does not match release filename") |
| 38 | + check_wheel(path, stubs) |
| 39 | + else: |
| 40 | + with tarfile.open(path) as archive: |
| 41 | + metadata_name, = [name for name in archive.getnames() if name.count("/") == 1 and name.endswith("/PKG-INFO")] |
| 42 | + metadata = BytesParser().parsebytes(archive.extractfile(metadata_name).read()) |
| 43 | + require(metadata["Version"] == version, "source metadata version does not match release") |
| 44 | + check_sdist(path, stubs) |
| 45 | + print(f"Validated GixPython {version}" + (" release artifacts" if args.dist else " release metadata")) |
| 46 | + |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + main() |
0 commit comments