Files
anidev-design-system/scripts/package-release.py
T

45 lines
2.3 KiB
Python

"""Archive already-built, self-contained deliverables; no publishing or installation."""
import json
import hashlib
import shutil
from pathlib import Path
from zipfile import ZipFile, ZIP_DEFLATED
root = Path(__file__).resolve().parent.parent
version = json.loads((root / "package.json").read_text(encoding="utf-8"))["version"]
dist = root / "dist"
for source, name, prefix in [
(dist / "package", f"anidev-design-system-{version}.zip", "anidev-design-system"),
(dist / "skills/anidev-design-system", f"anidev-skill-{version}.zip", "anidev-design-system"),
(dist / "starter", f"anidev-panel-{version}.zip", "anidev-panel"),
]:
entry = "SKILL.md" if "skill" in name else ("index.html" if "panel" in name else "package.json")
if not (source / entry).is_file():
raise SystemExit("Run npm run build:package first")
files = sorted(source.rglob("*"))
target = dist / name
with ZipFile(target, "w", ZIP_DEFLATED) as archive:
for file in files:
if file.is_symlink():
raise SystemExit(f"Symlink in release input: {file}")
if file.is_file():
archive.write(file, (Path(prefix) / file.relative_to(source)).as_posix())
with ZipFile(target) as archive:
if archive.testzip() is not None:
raise SystemExit(f"Invalid archive: {target}")
print(f"{target.name}: {len(archive.namelist())} files, CRC valid")
icons = root / "icons/anidev-dock-icons.zip"
with ZipFile(icons) as archive:
if archive.testzip() is not None:
raise SystemExit("Invalid icon archive")
shutil.copyfile(icons, dist / f"anidev-icons-{version}.zip")
names = [f"anidev-{part}-{version}.zip" for part in ("design-system", "panel", "skill", "icons")]
artifacts = []
for name in names:
file = dist / name
artifacts.append({"name": name, "bytes": file.stat().st_size, "sha256": hashlib.sha256(file.read_bytes()).hexdigest()})
(dist / "SHA256SUMS.txt").write_text("".join(f"{item['sha256']} {item['name']}\n" for item in artifacts), encoding="utf-8")
(dist / "release-manifest.json").write_text(json.dumps({"version": version, "channel": "stable", "artifacts": artifacts}, indent=2) + "\n", encoding="utf-8")
print(f"Prepared {len(artifacts)} release archives, SHA256SUMS.txt and release-manifest.json")