ruen-ui/scripts/build_release.py

54 lines
2.5 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
"""Build a small first-party installer package; companion archives stay upstream."""
import argparse
import hashlib
import json
from pathlib import Path
import zipfile
ROOT = Path(__file__).resolve().parents[1]
VERSION = '2026.11.22.2-beta.1'
FILES = ['Ruen-Setup', 'Ruen-Setup.exe', 'Install-Ruen-UI.ps1', 'Install-Ruen-UI.cmd',
'Install-Ruen-UI-Russian.cmd', 'Install-Windows.cmd', 'Install-Russian.cmd',
'Optimize-Ruen-UI.ps1', 'dependencies.lock.json', 'README.md', 'LICENSE',
'KEYBINDINGS.txt', 'LAYOUT-AUDIT.txt']
def payload(root=ROOT):
files = [root / x for x in FILES]
for directory in ('RuenUI', 'Tools', 'docs'):
files += [p for p in (root / directory).rglob('*') if p.is_file() and p.suffix in ('.lua', '.toc', '.xml', '.ps1', '.py', '.c', '.def', '.md', '.json')]
data = {p.relative_to(root).as_posix(): p.read_bytes() for p in sorted(files)}
data = {name: (b.replace(b'\r\n', b'\n').replace(b'\n', b'\r\n') if name.endswith('.cmd') else b.replace(b'\r\n', b'\n') if not name.endswith('.exe') else b) for name, b in data.items()}
assert not any(p.is_symlink() for p in files), 'Linked package content'
assert all(len(b) < 2_000_000 for b in data.values()), 'Unexpected large payload'
return data
def manifest(data):
return json.dumps({'format': 1, 'version': VERSION, 'files': [
{'path': p, 'sha256': hashlib.sha256(b).hexdigest()} for p, b in sorted(data.items())
]}, indent=2).encode() + b'\n'
def build(destination):
data = payload(); data['manifest.json'] = manifest(data)
destination.mkdir(parents=True, exist_ok=True)
output = destination / ('Ruen-UI-' + VERSION + '.zip')
with zipfile.ZipFile(output, 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as z:
for name, content in sorted(data.items()):
entry = zipfile.ZipInfo('Ruen-UI/' + name, (2026, 11, 21, 0, 0, 0))
entry.compress_type = zipfile.ZIP_DEFLATED
entry.create_system = 3
entry.external_attr = (0o100755 if name == 'Ruen-Setup' else 0o100644) << 16
z.writestr(entry, content)
checksum = hashlib.sha256(output.read_bytes()).hexdigest()
(destination / 'SHA256SUMS.txt').write_text(checksum + ' ' + output.name + '\n')
print(output, output.stat().st_size, checksum)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('destination', type=Path)
build(parser.parse_args().destination)