31 lines
1.6 KiB
Python
31 lines
1.6 KiB
Python
"""Package only source/deployment/tests; never include keys, .env or runtime data."""
|
|
import hashlib
|
|
import json
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
output = root.parent / "海诺中继服务_0.1.0_源码部署包.zip"
|
|
allowed_dirs = {"relay", "scripts", "tests", "docs", "deploy"}
|
|
allowed_files = {"README.md", "pyproject.toml", "requirements.lock", "Dockerfile", "Dockerfile.offline", ".dockerignore",
|
|
".gitignore", "compose.yaml", "compose.acceptance.yaml", "compose.offline.yaml"}
|
|
items = []
|
|
for path in root.rglob("*"):
|
|
if not path.is_file():
|
|
continue
|
|
relative = path.relative_to(root)
|
|
if "__pycache__" in relative.parts or ".pytest_cache" in relative.parts:
|
|
continue
|
|
if relative.parts[0] not in allowed_dirs and relative.as_posix() not in allowed_files:
|
|
continue
|
|
items.append((relative, path))
|
|
manifest = {relative.as_posix(): hashlib.sha256(path.read_bytes()).hexdigest() for relative, path in sorted(items)}
|
|
(root / "SOURCE_MANIFEST.json").write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
with zipfile.ZipFile(output, "w", zipfile.ZIP_DEFLATED) as archive:
|
|
for relative, path in sorted(items):
|
|
archive.write(path, "hainuo-relay/" + relative.as_posix())
|
|
archive.write(root / "SOURCE_MANIFEST.json", "hainuo-relay/SOURCE_MANIFEST.json")
|
|
digest = hashlib.sha256(output.read_bytes()).hexdigest()
|
|
output.with_suffix(".zip.sha256").write_text(digest + "\n", encoding="ascii")
|
|
print(json.dumps({"archive": str(output), "files": len(items) + 1, "sha256": digest}, ensure_ascii=False))
|