53 lines
2.6 KiB
Python
53 lines
2.6 KiB
Python
"""Package the built Windows app as a portable release ZIP with checksums."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import zipfile
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--tag', required=True)
|
|
parser.add_argument('--app-directory', type=Path, default=root / 'out/FileBow-win32-x64')
|
|
args = parser.parse_args()
|
|
if not re.fullmatch(r'v\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?', args.tag):
|
|
parser.error('Expected a version tag such as v1.0.0-rc.1')
|
|
version = json.loads((root / 'package.json').read_text('utf-8'))['version']
|
|
if args.tag[1:].split('-')[0] != version:
|
|
parser.error('Release tag does not match package.json')
|
|
source = args.app_directory.resolve()
|
|
if not (source / 'FileBow.exe').is_file():
|
|
raise SystemExit('Run pnpm build first.')
|
|
if json.loads((source / 'resources/app/package.json').read_text('utf-8'))['version'] != version:
|
|
raise SystemExit('The built app version does not match package.json.')
|
|
for name in ['FEATURE_PARITY.md', 'VALIDATION.md']:
|
|
if (source / 'resources/app' / name).exists():
|
|
raise SystemExit('Internal notes found in the app. Rebuild before packaging.')
|
|
notes = root / 'docs/releases' / (args.tag + '.md')
|
|
if not notes.is_file():
|
|
raise SystemExit('Release notes are missing.')
|
|
output = root / 'out/releases' / args.tag
|
|
output.mkdir(parents=True, exist_ok=True)
|
|
name = f'FileBow-{args.tag[1:]}-win-x64'
|
|
archive = output / (name + '.zip')
|
|
commit = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root, text=True).strip()
|
|
metadata = {'tag': args.tag, 'appVersion': version, 'commit': commit, 'platform': 'win32', 'arch': 'x64'}
|
|
files = sorted(p for p in source.rglob('*') if p.is_file())
|
|
with zipfile.ZipFile(archive, 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=6) as bundle:
|
|
for file in files:
|
|
bundle.write(file, f'{name}/{file.relative_to(source).as_posix()}')
|
|
bundle.writestr(f'{name}/START-HERE.md', notes.read_text('utf-8'))
|
|
bundle.writestr(f'{name}/release.json', json.dumps(metadata, indent=2) + '\n')
|
|
with zipfile.ZipFile(archive) as bundle:
|
|
bad = bundle.testzip()
|
|
if bad:
|
|
raise SystemExit(f'ZIP integrity check failed: {bad}')
|
|
with archive.open('rb') as stream:
|
|
digest = hashlib.file_digest(stream, 'sha256').hexdigest()
|
|
(output / 'SHA256SUMS.txt').write_text(f'{digest} {archive.name}\n', encoding='ascii')
|
|
metadata.update(archive=archive.name, bytes=archive.stat().st_size, sha256=digest, fileCount=len(files)+2)
|
|
(output / 'release.json').write_text(json.dumps(metadata, indent=2)+'\n', encoding='utf-8')
|
|
print(json.dumps(metadata, indent=2))
|