Files
NeitzelFXDesigner/scripts/check-neitzellib-artifact.py
T

35 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Verify that the locally cached NeitzelLib release matches the tested artifact."""
import argparse
import hashlib
import json
import os
import subprocess
from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parent.parent
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--repository", type=Path, default=Path(os.environ.get("NEITZELLIB_MAVEN_REPOSITORY", Path.home() / ".m2/repository")))
parser.add_argument("--resolve", action="store_true", help="Fetch the published Maven baseline before checking it")
args = parser.parse_args()
manifest = json.loads((ROOT / "docs/runtime/neitzellib-baseline.json").read_text())
if args.resolve:
wrapper = ROOT / ("mvnw.cmd" if os.name == "nt" else "mvnw")
subprocess.run([str(wrapper), "-N", "-B", "-ntp",
f"-Dmaven.repo.local={args.repository.resolve()}",
"org.apache.maven.plugins:maven-dependency-plugin:3.6.1:get",
f"-Dartifact=de.neitzel.lib:fx-test:{manifest['minimumReleasedVersion']}"],
cwd=ROOT, check=True)
errors = []
for artifact in manifest["artifacts"]:
path = args.repository / artifact["repositoryPath"]
if not path.is_file():
errors.append(f"Missing: {path}")
elif hashlib.sha256(path.read_bytes()).hexdigest() != artifact["sha256"]:
errors.append(f"Different build: {path}")
if errors:
print("\n".join(errors), file=sys.stderr)
sys.exit("Runtime identity mismatch. See docs/runtime/neitzellib-baseline.md.")
print(f"PASS {len(manifest['artifacts'])} runtime artifacts match tested source {manifest['sourceRevision']}")