Kaleido/scripts/publish_release.py
Elijah 6a53196748
All checks were successful
Validate and publish Kaleido / android (push) Successful in 2m23s
Release 0.1.5 with a reliable Settings update flow
The update button no longer disappears while downloading, so focus can't
be lost and the remote no longer jumps to Home from Settings. It shows
download progress, offers Install again after a cancelled installer, and
restores focus on return. Settings scrolls only as far as needed, shows
just the new version's notes above the buttons, and focused primary
buttons now stand apart from unfocused ones. Release bodies and the
manifest carry only that version's changelog section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 14:00:32 -07:00

31 lines
2.1 KiB
Python

"""Publish the checked-in, signed APK using Forgejo's repository-scoped CI token."""
import hashlib, json, os, pathlib, re, urllib.request, uuid
ROOT=pathlib.Path(__file__).resolve().parents[1]
API='https://git.elijahkuntz.com/api/v1/repos/Elijah/Kaleido'
token=os.environ['KALEIDO_RELEASE_TOKEN']
version=dict(l.split('=',1) for l in (ROOT/'version.properties').read_text().splitlines() if '=' in l)
tag='v'+version['versionName']
ref=os.environ.get('RELEASE_REF','')
assert ref=='refs/tags/'+tag,'Tag must match version.properties exactly'
out=ROOT/'distribution'
def notes():
"""Only this version's changelog section; the app shows the body as release notes."""
text=(ROOT/'CHANGELOG.md').read_text()
m=re.search(r'^## v?'+re.escape(version['versionName'])+r'[ \t]*$(.*?)(?=^## |\Z)',text,re.M|re.S)
return m.group(1).strip() if m else ''
assert hashlib.sha256((out/'Kaleido.apk').read_bytes()).hexdigest()==(out/'Kaleido.apk.sha256').read_text().split()[0]
def call(path,data=None,method=None,content='application/json'):
req=urllib.request.Request(API+path,data=data,method=method,headers={'Authorization':'token '+token,'Content-Type':content})
with urllib.request.urlopen(req,timeout=120) as response:return json.load(response)
try:release=call('/releases/tags/'+tag)
except urllib.error.HTTPError as e:
if e.code!=404:raise
release=call('/releases',json.dumps({'tag_name':tag,'name':'Kaleido '+version['versionName'],'body':notes(),'draft':True,'prerelease':False}).encode(),'POST')
existing={a['name']:a for a in release.get('assets',[])}
for name in ['Kaleido.apk','Kaleido.apk.sha256']:
if name in existing:continue
boundary='kaleido'+uuid.uuid4().hex
data=(f'--{boundary}\r\nContent-Disposition: form-data; name="attachment"; filename="{name}"\r\nContent-Type: application/octet-stream\r\n\r\n').encode()+(out/name).read_bytes()+f'\r\n--{boundary}--\r\n'.encode()
call(f'/releases/{release["id"]}/assets?name='+name,data,'POST','multipart/form-data; boundary='+boundary)
call('/releases/'+str(release['id']),json.dumps({'draft':False}).encode(),'PATCH')
print('Published',tag)