refactor(windows): publish Velopack updates through Gitea Releases

This commit is contained in:
lingjhf committed 2026-10-06 12:56:31 +08:00
1 parent 826745b407
commit 1ef8edc8bc
17 files changed
+519 -87

No files matched your search

+43 -19
View File
@@ -1,19 +1,27 @@
"""Package the Windows Release directory and Android production APK."""
"""Package Android and audited Velopack Windows installation/update artifacts."""
import argparse
import hashlib
import json
from pathlib import Path
import re
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():
version = re.search(r'^version: (\S+)', (ROOT / 'pubspec.yaml').read_text(), re.M)[1].split('+')[0]
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'
output.mkdir(exist_ok=True)
# 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():
@@ -25,23 +33,39 @@ def main():
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')
sys.path.insert(0, str(ROOT / 'tool/windows'))
from check_windows_release import audit
unused_jni = windows / 'dartjni.dll'
if unused_jni.exists():
unused_jni.unlink()
report = audit(windows, require_processing=False)
(output / 'windows-dependency-audit.json').write_text(json.dumps(report, indent=2) + '\n')
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')
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))