Recover releases from independently retried CI packaging (#15)
Gitea CI / Check code and tests (push) Failing after 11m29s
Gitea CI / Build Android APK (push) Skipped
Gitea CI / Build Windows x64 app (push) Skipped
Gitea CI / Audit and package Windows x64 (push) Skipped
Gitea CI / Assemble and validate CI artifacts (push) Skipped
Gitea CI / Gitea CI passed (push) Failing after 2s

This commit was merged in pull request #15.
This commit is contained in:
lingjhf committed 2026-10-11 20:52:05 +00:00
1 parent 06f1c26681
commit 8785eaf095
7 files changed
+185 -34

No files matched your search

+24 -5
View File
@@ -1,6 +1,7 @@
"""Upload platform builds to a commit-bound draft, then verify and publish it."""
import argparse
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
import hashlib
import importlib.util
import io
@@ -22,7 +23,7 @@ fingerprint = transport.fingerprint
def context():
base = f"{transport.SERVER}/api/v1/repos/{os.environ['GITEA_REPOSITORY']}"
sha, tag = os.environ['GITEA_SHA'], os.environ['RELEASE_TAG']
version, windows_version = app_versions('pubspec.yaml')
version, windows_version = app_versions(os.environ.get('RELEASE_PUBSPEC', 'pubspec.yaml'))
if tag != f'v{version}':
raise ValueError('Release tag must match pubspec version')
remote_tag = request(f'{base}/tags/{urllib.parse.quote(tag, safe="")}')
@@ -65,8 +66,25 @@ def ci_artifacts(base, run_id):
if not item.get('expired', False)]
def artifact_named(artifacts, name):
matches = [item for item in artifacts if item['name'] == name]
def artifact_named(artifacts, name, run, jobs):
producer = {'cutdex-android-build': 'Build Android APK',
'cutdex-windows-build': 'Audit and package Windows x64',
'cutdex-release-metadata': 'Assemble and validate CI artifacts'}[name]
producers = [job for job in jobs if job['name'] == producer
and job.get('conclusion') == 'success' and job.get('head_sha') == run['head_sha']]
if len(producers) != 1:
raise ValueError('Expected one successful artifact producer: ' + producer)
job = producers[0]
def timestamp(value):
return datetime.fromisoformat(value.replace('Z', '+00:00'))
started, completed = timestamp(job['started_at']), timestamp(job['completed_at'])
# Gitea retains old API rows after overwrite/rerun. Accept only the artifact
# uploaded within the current successful producer's interval; cloned jobs
# retain their original interval and therefore reuse their original bytes.
matches = [item for item in artifacts if item['name'] == name
and item.get('workflow_run', {}).get('id') == run['id']
and item['workflow_run'].get('head_sha') == run['head_sha']
and started <= timestamp(item['created_at']) <= completed]
if len(matches) != 1:
raise ValueError('Expected one unexpired CI artifact: ' + name)
return matches[0]
@@ -91,8 +109,9 @@ def prepare_ci(base, sha, tag, version, windows_version):
run_id = int(matches[0])
run = successful_ci(base, sha, run_id)
artifacts = ci_artifacts(base, run['id'])
verification = artifact_named(artifacts, 'cutdex-release-metadata')
selected = {platform: artifact_named(artifacts, f'cutdex-{platform}-build')
jobs = request(f"{base}/actions/runs/{run['id']}/jobs")['jobs']
verification = artifact_named(artifacts, 'cutdex-release-metadata', run, jobs)
selected = {platform: artifact_named(artifacts, f'cutdex-{platform}-build', run, jobs)
for platform in ('android', 'windows')}
release = prepare(base, sha, tag, version, windows_version, ci_run=run['id'])
if os.environ.get('GITHUB_OUTPUT'):