Build Android and Windows packages and promote Gitea releases
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Windows x64 and Android (pull_request) Canceled after 1m49s

This commit is contained in:
lingjhf committed 2026-10-06 03:03:03 +08:00
1 parent 27e77fff39
commit 0f6097f58f
6 files changed
+257 -29

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
name: Gitea CI
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
defaults:
run:
shell: pwsh
concurrency:
group: app-${{ gitea.ref }}
cancel-in-progress: true
env:
PYTHONUTF8: '1'
GIT_CONFIG_COUNT: '2'
GIT_CONFIG_KEY_0: core.autocrlf
GIT_CONFIG_VALUE_0: 'false'
GIT_CONFIG_KEY_1: core.eol
GIT_CONFIG_VALUE_1: lf
jobs:
build:
name: Windows x64 and Android
runs-on: cutdex-windows-x64
env:
GITEA_ACTOR: lingjhf
CUTDEX_GITEA_TOKEN: ${{ secrets.CUTDEX_GITEA_TOKEN }}
steps:
- uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
- name: Verify toolchains
run: |
$version = flutter --version --machine | ConvertFrom-Json
if ($version.frameworkVersion -ne '3.47.5') { throw 'Flutter 3.47.5 required.' }
flutter config --jdk-dir=$env:JAVA_HOME
if ($LASTEXITCODE -ne 0) { throw 'Flutter JDK setup failed.' }
- run: flutter pub get --enforce-lockfile
- run: dart analyze --fatal-infos
- run: flutter test --reporter expanded
- run: flutter build apk --release --flavor production --target-platform android-arm64,android-x64
- run: flutter build windows --release --flavor production
- name: Package application
run: python tool/gitea/package-app.py
- name: Upload Android and Windows packages
uses: https://github.com/actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: cutdex-release-packages
path: dist/*
if-no-files-found: error
retention-days: 30
checks:
name: Gitea CI passed
if: always()
needs: build
runs-on: cutdex-windows-x64
steps:
- env:
RESULT: ${{ needs.build.result }}
run: |
if ($env:RESULT -ne 'success') { throw "App build: $env:RESULT" }
+32
View File
@@ -0,0 +1,32 @@
name: Gitea Release
on:
push:
tags: ['v*']
workflow_dispatch:
inputs:
tag:
description: Existing release tag matching pubspec version
required: true
permissions:
contents: write
concurrency:
group: cutdex-release
cancel-in-progress: false
jobs:
release:
runs-on: cutdex-windows-x64
steps:
- uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
ref: ${{ gitea.event.inputs.tag || gitea.ref_name }}
persist-credentials: false
- name: Publish validated Android and Windows packages
shell: pwsh
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GITEA_REPOSITORY: ${{ gitea.repository }}
RELEASE_TAG: ${{ gitea.event.inputs.tag || gitea.ref_name }}
run: |
$env:GITEA_SHA = git rev-parse HEAD
python tool/gitea/promote-release.py
if ($LASTEXITCODE -ne 0) { throw 'Release promotion failed.' }
+27 -27
View File
@@ -214,81 +214,81 @@ packages:
dependency: transitive dependency: transitive
description: description:
path: "packages/editor" path: "packages/editor"
ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
resolved-ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" resolved-ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
url: "git@github.com:lingjhf/cutdex_sdk.git" url: "ssh://git@git.orangraph.com:2222/lingjhf/cutdex_sdk.git"
source: git source: git
version: "0.1.0" version: "0.1.0"
cutdex_mcp: cutdex_mcp:
dependency: transitive dependency: transitive
description: description:
path: "packages/mcp" path: "packages/mcp"
ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
resolved-ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" resolved-ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
url: "git@github.com:lingjhf/cutdex_sdk.git" url: "ssh://git@git.orangraph.com:2222/lingjhf/cutdex_sdk.git"
source: git source: git
version: "0.1.0" version: "0.1.0"
cutdex_preview: cutdex_preview:
dependency: transitive dependency: transitive
description: description:
path: "packages/preview" path: "packages/preview"
ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
resolved-ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" resolved-ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
url: "git@github.com:lingjhf/cutdex_sdk.git" url: "ssh://git@git.orangraph.com:2222/lingjhf/cutdex_sdk.git"
source: git source: git
version: "0.1.0" version: "0.1.0"
cutdex_project: cutdex_project:
dependency: transitive dependency: transitive
description: description:
path: "packages/project" path: "packages/project"
ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
resolved-ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" resolved-ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
url: "git@github.com:lingjhf/cutdex_sdk.git" url: "ssh://git@git.orangraph.com:2222/lingjhf/cutdex_sdk.git"
source: git source: git
version: "0.1.0" version: "0.1.0"
cutdex_runtime: cutdex_runtime:
dependency: transitive dependency: transitive
description: description:
path: "packages/runtime" path: "packages/runtime"
ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
resolved-ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" resolved-ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
url: "git@github.com:lingjhf/cutdex_sdk.git" url: "ssh://git@git.orangraph.com:2222/lingjhf/cutdex_sdk.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
cutdex_sdk: cutdex_sdk:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: "v0.1.0" ref: be8f891
resolved-ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" resolved-ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
url: "git@github.com:lingjhf/cutdex_sdk.git" url: "ssh://git@git.orangraph.com:2222/lingjhf/cutdex_sdk.git"
source: git source: git
version: "0.1.0" version: "0.1.0"
cutdex_timeline: cutdex_timeline:
dependency: transitive dependency: transitive
description: description:
path: "packages/timeline" path: "packages/timeline"
ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
resolved-ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" resolved-ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
url: "git@github.com:lingjhf/cutdex_sdk.git" url: "ssh://git@git.orangraph.com:2222/lingjhf/cutdex_sdk.git"
source: git source: git
version: "0.2.0" version: "0.2.0"
cutdex_timeline_ui: cutdex_timeline_ui:
dependency: transitive dependency: transitive
description: description:
path: "packages/timeline_ui" path: "packages/timeline_ui"
ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
resolved-ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" resolved-ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
url: "git@github.com:lingjhf/cutdex_sdk.git" url: "ssh://git@git.orangraph.com:2222/lingjhf/cutdex_sdk.git"
source: git source: git
version: "0.1.0" version: "0.1.0"
cutdex_tools: cutdex_tools:
dependency: transitive dependency: transitive
description: description:
path: "packages/tools" path: "packages/tools"
ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
resolved-ref: "113eee1d63d546470db5d5d4f0d4aa0c312e7cac" resolved-ref: be8f89197d44c29cf6dff7eddbc50c1049886d08
url: "git@github.com:lingjhf/cutdex_sdk.git" url: "ssh://git@git.orangraph.com:2222/lingjhf/cutdex_sdk.git"
source: git source: git
version: "0.1.0" version: "0.1.0"
dart_style: dart_style:
+2 -2
View File
@@ -24,8 +24,8 @@ dependencies:
cutdex_sdk: cutdex_sdk:
git: git:
url: git@github.com:lingjhf/cutdex_sdk.git url: ssh://git@git.orangraph.com:2222/lingjhf/cutdex_sdk.git
ref: v0.1.0 ref: be8f891
cutdex_agent: cutdex_agent:
git: git:
url: https://github.com/cutdex-ai/cutdex_agent.git url: https://github.com/cutdex-ai/cutdex_agent.git
+41
View File
@@ -0,0 +1,41 @@
"""Package the Windows Release directory and Android production APK."""
import hashlib
import json
from pathlib import Path
import re
import shutil
import zipfile
ROOT = Path(__file__).resolve().parents[2]
def main():
version = re.search(r'^version: (\S+)', (ROOT / 'pubspec.yaml').read_text(), re.M)[1].split('+')[0]
output = ROOT / 'dist'
output.mkdir(exist_ok=True)
apk = ROOT / 'build/app/outputs/flutter-apk/app-production-release.apk'
windows = ROOT / 'build/windows/x64/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')
shutil.copyfile(apk, output / f'cutdex-{version}-android.apk')
package = output / f'cutdex-{version}-windows-x64.zip'
with zipfile.ZipFile(package, 'w', compression=zipfile.ZIP_DEFLATED) as archive:
for path in sorted(windows.rglob('*')):
if path.is_file() and path.suffix.lower() not in ('.pdb', '.lib', '.exp'):
archive.write(path, f'cutdex-{version}/' + path.relative_to(windows).as_posix())
files = sorted(output.glob('*.apk')) + sorted(output.glob('*.zip'))
manifest = {path.name: hashlib.file_digest(path.open('rb'), 'sha256').hexdigest() for path in files}
(output / 'SHA256SUMS').write_text(''.join(f'{digest} {name}\n' for name, digest in manifest.items()))
(output / 'release-manifest.json').write_text(json.dumps({'version': version, 'files': manifest, 'androidSigning': 'debug', 'processingWorkersBundled': False}, indent=2) + '\n')
print(json.dumps(manifest, indent=2))
if __name__ == '__main__':
main()
+94
View File
@@ -0,0 +1,94 @@
"""Promote packages from a successful main CI for the exact release commit."""
import hashlib
import io
import json
import os
from pathlib import Path
import re
import urllib.error
import urllib.parse
import urllib.request
import uuid
import zipfile
SERVER = 'https://git.orangraph.com'
REPO = os.environ['GITEA_REPOSITORY']
TOKEN = os.environ['GITEA_TOKEN']
BASE = f'{SERVER}/api/v1/repos/{REPO}'
def request(url, data=None, method=None, content_type='application/json'):
headers = {'Authorization': f'token {TOKEN}'}
if data is not None:
headers['Content-Type'] = content_type
if isinstance(data, dict):
data = json.dumps(data).encode()
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=300) as response:
body = response.read()
return json.loads(body) if 'application/json' in response.headers.get('Content-Type', '') else body
def download(asset):
url = urllib.parse.urlparse(asset['browser_download_url'])
if url.hostname != 'git.orangraph.com':
raise ValueError('Unexpected attachment host')
return request(urllib.parse.urlunparse(url._replace(scheme='https', netloc='git.orangraph.com')))
def main():
sha = os.environ['GITEA_SHA']
tag = os.environ['RELEASE_TAG']
version = re.search(r'^version: (\S+)', Path('pubspec.yaml').read_text(), re.M)[1].split('+')[0]
if tag != f'v{version}':
raise ValueError('Release tag must match pubspec version')
runs = request(f'{BASE}/actions/runs?limit=100')['workflow_runs']
matches = [run for run in runs if run['head_sha'] == sha and run['head_branch'] == 'main' and run['conclusion'] == 'success' and run['name'] == 'Gitea CI']
if not matches:
raise ValueError('No successful main CI for this exact commit; run CI before releasing')
run = max(matches, key=lambda item: item['id'])
artifacts = request(f"{BASE}/actions/runs/{run['id']}/artifacts")['artifacts']
found = [item for item in artifacts if item['name'] == 'cutdex-release-packages' and not item.get('expired', False)]
if len(found) != 1:
raise ValueError('Expected one validated application artifact')
data = request(f"{BASE}/actions/artifacts/{found[0]['id']}/zip")
with zipfile.ZipFile(io.BytesIO(data)) as archive:
contents = {item.filename: archive.read(item) for item in archive.infolist() if not item.is_dir()}
manifest = json.loads(contents['release-manifest.json'])
if manifest['version'] != version:
raise ValueError('Artifact version does not match release')
expected = {f'cutdex-{version}-android.apk', f'cutdex-{version}-windows-x64.zip'}
if set(manifest['files']) != expected:
raise ValueError('Release requires both Android and Windows packages')
for name, digest in manifest['files'].items():
if hashlib.sha256(contents[name]).hexdigest() != digest:
raise ValueError(f'Package checksum mismatch: {name}')
releases = request(f'{BASE}/releases?limit=100')
existing = [release for release in releases if release['tag_name'] == tag]
if existing:
release = existing[0]
if not release['draft']:
raise ValueError('Release already published; choose a new version')
else:
release = request(f'{BASE}/releases', {'tag_name': tag, 'target_commitish': sha, 'name': f'Cutdex {version}', 'draft': True, 'body': f'Windows x64 portable ZIP and Android ARM64/x86_64 APK. Android currently uses the project debug signing key. Processing workers and models are distributed separately. Verified CI run: {run["id"]}.'}, 'POST')
assets = request(f"{BASE}/releases/{release['id']}/assets")
for name, body in contents.items():
if '/' in name or '\\' in name:
raise ValueError('Unexpected artifact path')
prior = [asset for asset in assets if asset['name'] == name]
if prior:
downloaded = download(prior[0])
if downloaded != body:
raise ValueError(f'Refusing to replace Release asset: {name}')
continue
boundary = uuid.uuid4().hex
payload = (f'--{boundary}\r\nContent-Disposition: form-data; name="attachment"; filename="{name}"\r\nContent-Type: application/octet-stream\r\n\r\n'.encode() + body + f'\r\n--{boundary}--\r\n'.encode())
asset = request(f"{BASE}/releases/{release['id']}/assets?name={urllib.parse.quote(name)}", payload, 'POST', f'multipart/form-data; boundary={boundary}')
if download(asset) != body:
raise ValueError(f'Remote checksum verification failed: {name}')
request(f"{BASE}/releases/{release['id']}", {'draft': False}, 'PATCH')
print(f'{SERVER}/{REPO}/releases/tag/{tag}')
if __name__ == '__main__':
main()