Files
shanhe-puzzle/scripts/package.py
T
codex-bot 4845826deb
Shanhe source and offline package checks / verify (pull_request) Failing after 5s
feat: sync Shanhe 2.2 source and add remote package verification
2026-11-01 17:13:46 +08:00

13 lines
865 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pathlib,zipfile,json,hashlib
root=pathlib.Path('dist');out=pathlib.Path('artifacts/shanhe-puzzle-xhs.zip')
files=sorted(p for p in root.rglob('*') if p.is_file())
if len(files)>200:raise SystemExit(f'ZIP文件数量超过200个上限: {len(files)}')
with zipfile.ZipFile(out,'w',zipfile.ZIP_DEFLATED,compresslevel=9) as z:
for p in files:z.write(p,p.relative_to(root).as_posix())
with zipfile.ZipFile(out) as z:
assert 'index.html' in z.namelist()
assert z.testzip() is None
assert len(z.infolist())<=200
print('离线 ZIP:',out.resolve(),' | ',round(out.stat().st_size/1024),'KB')
pathlib.Path('artifacts/package-report.json').write_text(json.dumps({'file':str(out),'bytes':out.stat().st_size,'fileCount':len(files),'fileLimit':200,'sha256':hashlib.sha256(out.read_bytes()).hexdigest(),'archiveIntegrity':'passed','rootEntry':'index.html'},indent=2))