Files
cutdex/tool/gitea/package-app.py
T

74 lines
3.6 KiB
Python

"""Package Android and audited Velopack Windows installation/update artifacts."""
import argparse
import hashlib
import json
from pathlib import Path
import shutil
import sys
import tempfile
import zipfile
from release_artifacts import AUDIT, FEED, INSTALLER, PORTABLE, app_versions, checksum_lines, validate_artifact
ROOT = Path(__file__).resolve().parents[2]
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--vpk', type=Path, required=True, help='Pinned vpk executable or DLL')
args = parser.parse_args()
version, windows_version = app_versions(ROOT / 'pubspec.yaml')
output = ROOT / 'dist'
# Repeated builds must not accidentally upload a previous version's files.
if output.exists() and any(output.iterdir()):
raise ValueError('dist must be empty; use a clean release workspace')
apk = ROOT / 'build/app/outputs/flutter-apk/app-production-release.apk'
windows = ROOT / 'build/windows/x64/production/runner/Release'
if not apk.is_file() or not (windows / 'cutdex.exe').is_file():
raise ValueError('Both production builds are required')
with zipfile.ZipFile(apk) as archive:
names = archive.namelist()
for abi in ('arm64-v8a', 'x86_64'):
if f'lib/{abi}/libflutter.so' not in names:
raise ValueError(f'APK missing Flutter ABI: {abi}')
if any(name.startswith('lib/armeabi-v7a/') for name in names):
raise ValueError('APK must use supported 64-bit ABIs only')
sys.path.insert(0, str(ROOT / 'tool/windows'))
from check_windows_release import audit
from windows_updates import package_app
with tempfile.TemporaryDirectory(prefix='cutdex-release-') as directory:
temporary = Path(directory)
staged, releases = temporary / 'app', temporary / 'releases'
shutil.copytree(windows, staged,
ignore=shutil.ignore_patterns('processing', '*.pdb', '*.lib', '*.exp', 'dartjni.dll'))
report = audit(staged, require_processing=False)
checksums = {}
for path in sorted(staged.rglob('*')):
if path.is_file():
with path.open('rb') as stream:
checksums[path.relative_to(staged).as_posix()] = hashlib.file_digest(stream, 'sha256').hexdigest()
(staged / 'checksums.json').write_text(json.dumps(checksums), encoding='utf-8')
result = package_app(staged, releases, args.vpk, require_processing=False)
if result['version'] != windows_version:
raise ValueError('Built Windows version differs from pubspec')
contents = {f'cutdex-{version}-android.apk': apk.read_bytes(),
AUDIT: (json.dumps(report, indent=2) + '\n').encode()}
for path in releases.iterdir():
if path.name in {FEED, INSTALLER, PORTABLE} or path.suffix == '.nupkg':
contents[path.name] = path.read_bytes()
files = {name: hashlib.sha256(body).hexdigest() for name, body in contents.items()}
manifest = {'version': version, 'files': files, 'windowsUpdateVersion': windows_version,
'windowsPackageId': 'Cutdex', 'windowsChannel': 'win-x64',
'androidSigning': 'debug', 'processingWorkersBundled': False}
contents['SHA256SUMS'] = checksum_lines(files).encode()
contents['release-manifest.json'] = (json.dumps(manifest, indent=2) + '\n').encode()
validate_artifact(contents, version, windows_version)
output.mkdir(exist_ok=True)
for name, body in contents.items():
(output / name).write_bytes(body)
print(json.dumps(manifest, indent=2))
if __name__ == '__main__':
main()