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

@@ -0,0 +1,46 @@
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
@unittest.skipUnless(shutil.which('cmake'), 'CMake required')
class UpdateConfigurationTests(unittest.TestCase):
def configuration(self, flavor, **overrides):
environment = {name: value for name, value in os.environ.items()
if not name.startswith('CUTDEX_WINDOWS_UPDATE_') and name != 'CUTDEX_UPDATE_TEST_HTTP'}
environment.update(overrides)
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
script = root / 'config.cmake'
script.write_text(f'set(FLUTTER_APP_FLAVOR "{flavor}")\n'
'function(configure_updates)\n'
f'include("{ROOT.as_posix()}/windows/runner/update_configuration.cmake")\n'
'endfunction()\nconfigure_updates()\n'
f'file(WRITE "{root.as_posix()}/result.txt" '
'"${DESKUP_WINDOWS_UPDATE_SOURCE}|${DESKUP_WINDOWS_UPDATE_URL}|${DESKUP_UPDATE_PACKAGE_ID}|${DESKUP_ALLOW_LOCAL_HTTP}|${DESKUP_GITEA_INCLUDE_PRERELEASES}")\n')
result = subprocess.run(['cmake', '-P', str(script)], env=environment,
capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
return (root / 'result.txt').read_text().split('|')
def test_production_always_uses_public_gitea_repository(self):
values = self.configuration('production', CUTDEX_WINDOWS_UPDATE_SOURCE='web',
CUTDEX_WINDOWS_UPDATE_URL='http://127.0.0.1:9999', CUTDEX_UPDATE_TEST_HTTP='1')
self.assertEqual(values, ['gitea', 'https://git.orangraph.com/lingjhf/cutdex', 'Cutdex', '0', 'OFF'])
def test_development_has_no_implicit_production_feed(self):
self.assertEqual(self.configuration('development'), ['gitea', '', 'Cutdex.Dev', '0', 'OFF'])
def test_development_supports_explicit_loopback_web_test_feed(self):
self.assertEqual(self.configuration('development', CUTDEX_WINDOWS_UPDATE_SOURCE='web',
CUTDEX_WINDOWS_UPDATE_URL='http://127.0.0.1:8765', CUTDEX_UPDATE_TEST_HTTP='1'),
['web', 'http://127.0.0.1:8765', 'Cutdex.Dev', '1', 'OFF'])
if __name__ == '__main__':
unittest.main()
+10 -2
View File
@@ -54,6 +54,7 @@ def main():
definitions = work / 'defines.json'
definitions.write_text(json.dumps({'CUTDEX_UPDATE_SMOKE_ROOT': work.as_posix()}), encoding='utf-8')
environment = dict(os.environ, CUTDEX_WINDOWS_UPDATE_URL=f'http://127.0.0.1:{args.port}',
CUTDEX_WINDOWS_UPDATE_SOURCE='web',
CUTDEX_UPDATE_TEST_HTTP='1')
# Isolate Flutter caches, generated runner files and output from live builds.
source = work / 'source'
@@ -61,11 +62,14 @@ def main():
for name in ['windows']:
shutil.copytree(ROOT / name, source / name,
ignore=shutil.ignore_patterns('ephemeral', 'build', '__pycache__'))
configuration = source / 'windows/runner/update_configuration.cmake'
configuration.write_text(configuration.read_text().replace(
r'Software\\\\Cutdex\\\\', r'Software\\\\Cutdex\\\\UpdateSmoke\\\\'))
# Exercise the real Runner/update bridge with a small Flutter test entry.
# Media processing is covered separately and need not be rebuilt here.
(source / 'pubspec.yaml').write_text(
'name: cutdex_update_smoke\nversion: 1.0.0+1\n'
'environment:\n sdk: ^3.13.2\n'
'environment:\n sdk: ^3.13.4\n'
'dependencies:\n flutter:\n sdk: flutter\n'
f' deskup: {DESKUP_VERSION}\n'
'flutter:\n uses-material-design: true\n', encoding='utf-8')
@@ -103,7 +107,11 @@ def verify_update(work, port):
app = work / 'installed/Cutdex update test.exe'
process = None
try:
process = subprocess.Popen([str(app)], cwd=app.parent, creationflags=subprocess.CREATE_NO_WINDOW)
# The loopback fixture must not depend on a developer's HTTP proxy.
environment = {name: value for name, value in os.environ.items()
if name.lower() not in ('http_proxy', 'https_proxy', 'all_proxy')}
process = subprocess.Popen([str(app)], cwd=app.parent, env=environment,
creationflags=subprocess.CREATE_NO_WINDOW)
deadline = time.monotonic() + 240
while time.monotonic() < deadline:
if (work / 'failure.json').exists():
+18
View File
@@ -0,0 +1,18 @@
"""Windows update version ordering, independent of Flutter package resolution."""
import re
def update_version(display_version, build):
version = display_version + '-build.' + str(int(build))
numeric_version(version)
return version
def numeric_version(version):
number = r'(0|[1-9]\d*)'
match = re.fullmatch(rf'{number}\.{number}\.{number}(?:-build\.{number})?', version)
if not match:
raise ValueError('Windows update versions must use major.minor.patch-build.number')
major, minor, patch, build = match.groups()
# SemVer +build metadata does not participate in precedence.
return (int(major), int(minor), int(patch), int(build is None), int(build or 0))
+12 -27
View File
@@ -12,6 +12,7 @@ from urllib.parse import urljoin, urlparse
from urllib.request import url2pathname
from check_windows_release import audit
from update_versions import numeric_version, update_version
ROOT = Path(__file__).resolve().parents[2]
def resolved_deskup():
@@ -58,12 +59,6 @@ def pack_release(command, *, app, output, package_id, version, title):
'--delta', 'none'], check=True)
def update_version(display_version, build):
version = display_version + '-build.' + str(int(build))
numeric_version(version)
return version
def file_version(app):
import pefile
with pefile.PE(str(app / 'cutdex.exe')) as pe:
@@ -78,17 +73,6 @@ def file_version(app):
raise ValueError('Missing Flutter display version and build number in PE resources')
def numeric_version(version):
number = r'(0|[1-9]\d*)'
match = re.fullmatch(rf'{number}\.{number}\.{number}(?:-build\.{number})?', version)
if not match:
raise ValueError('Windows update versions must use major.minor.patch-build.number')
major, minor, patch, build = match.groups()
# SemVer build metadata (+number) does not participate in precedence.
# A numeric prerelease component does, and stable versions rank above it.
return (int(major), int(minor), int(patch), int(build is None), int(build or 0))
def validate_previous(output, package_id, version):
candidate = numeric_version(version)
for feed in output.glob('releases.*.json'):
@@ -120,28 +104,28 @@ def verify_manifest(app):
raise ValueError(f'Release checksum mismatch: {name}')
def package(args):
app, output = args.app.resolve(), args.output.resolve()
def package_app(app, output, vpk, *, development=False, require_processing=True):
app, output = Path(app).resolve(), Path(output).resolve()
if output == app or output.is_relative_to(app) or app.is_relative_to(output):
raise ValueError('Release output must be outside the staged app')
audit(app)
audit(app, require_processing=require_processing)
verify_manifest(app)
sdk_dll = app / 'velopack_libc.dll'
if not sdk_dll.is_file():
raise ValueError('Rebuild the app with the Velopack integration before packaging')
command = vpk_command(args.vpk)
command = vpk_command(vpk)
check_tool(command)
version = file_version(app)
package_id = 'Cutdex.Dev' if args.development else 'Cutdex'
# The expected identity is compiled into the runner and must match the package.
package_id = 'Cutdex.Dev' if development else 'Cutdex'
# deskup compiles the identity into the plugin, rather than the runner.
identity = package_id.encode('ascii') + b'\0'
if identity not in (app / 'cutdex.exe').read_bytes():
if identity not in (app / 'deskup_plugin.dll').read_bytes():
raise ValueError('Package identity does not match the Flutter build flavor')
validate_previous(output, package_id, version)
output.mkdir(parents=True, exist_ok=True)
pack_release(command, app=app, output=output, package_id=package_id, version=version,
title='Cutdex Dev' if args.development else 'Cutdex')
print(json.dumps({'version': version, 'packageId': package_id, 'output': str(output)}))
title='Cutdex Dev' if development else 'Cutdex')
return {'version': version, 'packageId': package_id, 'output': str(output)}
def serve(directory, port):
@@ -168,7 +152,8 @@ def main():
args = parser.parse_args()
try:
if args.command == 'pack':
package(args)
print(json.dumps(package_app(args.app, args.output, args.vpk,
development=args.development)))
else:
serve(args.directory, args.port)
except KeyboardInterrupt: