"""Stage a locally signed APK for Git distribution and tag-triggered Forgejo releases.""" import hashlib, json, pathlib, shutil, subprocess ROOT=pathlib.Path(__file__).resolve().parents[1] version=dict(l.split('=',1) for l in (ROOT/'version.properties').read_text().splitlines() if '=' in l) apk=ROOT/'app/build/outputs/apk/release/app-release.apk' if not apk.exists():raise SystemExit('Run Build.ps1 -Release first.') out=ROOT/'distribution';out.mkdir(exist_ok=True) shutil.copyfile(apk,out/'Kaleido.apk') digest=hashlib.sha256(apk.read_bytes()).hexdigest() (out/'Kaleido.apk.sha256').write_text(digest+' Kaleido.apk\n') repo='https://git.elijahkuntz.com/Elijah/Kaleido' tag='v'+version['versionName'] manifest={'version':version['versionName'],'versionCode':int(version['versionCode']),'url':repo+'/raw/tag/'+tag+'/distribution/Kaleido.apk','checksumUrl':repo+'/raw/tag/'+tag+'/distribution/Kaleido.apk.sha256','notes':(ROOT/'CHANGELOG.md').read_text().split('\n## ')[1].split('\n## ')[0] if (ROOT/'CHANGELOG.md').exists() else ''} (out/'latest.json').write_text(json.dumps(manifest,indent=2)+'\n') print('Packaged',tag,'SHA-256',digest)