refactor(build): 统一本地与 CI 构建入口及平台发布工具 (#9)
Gitea CI / Check code and tests (push) Successful in 7m38s
Gitea CI / Build Android APK (push) Successful in 6m20s
Gitea CI / Audit and package Windows x64 (push) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (push) Canceled after 0s
Gitea CI / Gitea CI passed (push) Canceled after 0s
Gitea CI / Build Windows x64 app (push) Canceled after 14m42s

This commit was merged in pull request #9.
This commit is contained in:
lingjhf committed 2026-10-06 16:14:42 +00:00
1 parent a13a54d5ec
commit 4a759d81a6
61 files changed
+1913 -388

No files matched your search

+8 -6
View File
@@ -3,10 +3,14 @@
Requires pefile on the build host. Models remain separate from the application.
"""
import argparse
import hashlib
import json
from pathlib import Path
import shutil
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from common.files import file_sha256
from common.process import cli
from check_windows_release import audit
@@ -27,8 +31,7 @@ def main():
path = (runtime / name).resolve()
if not path.is_relative_to(runtime):
raise ValueError(f'Invalid processing manifest path: {name}')
with path.open('rb') as stream:
actual = hashlib.file_digest(stream, 'sha256').hexdigest()
actual = file_sha256(path)
if actual.lower() != expected.lower():
raise ValueError(f'Processing checksum mismatch: {name}')
# Older Flutter builds can retain the unused JNI plugin from Android's
@@ -40,11 +43,10 @@ def main():
manifest = {}
for path in sorted(output.rglob('*')):
if path.is_file():
with path.open('rb') as stream:
manifest[path.relative_to(output).as_posix()] = hashlib.file_digest(stream, 'sha256').hexdigest()
manifest[path.relative_to(output).as_posix()] = file_sha256(path)
(output / 'checksums.json').write_text(json.dumps(manifest, indent=2) + '\n', encoding='utf-8')
print(f'Portable package staged: {output} ({len(manifest)} files)')
if __name__ == '__main__':
main()
sys.exit(cli(main))
+7 -5
View File
@@ -15,6 +15,9 @@ import sys
import threading
import time
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from project_tools import project_environment, tool_command
from windows_updates import ROOT, check_tool, pack_release, resolved_deskup, update_version, verify_sdk_version, vpk_command
@@ -38,7 +41,6 @@ class TestHandler(SimpleHTTPRequestHandler):
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--vpk', type=Path, required=True)
parser.add_argument('--flutter', default=shutil.which('flutter'))
parser.add_argument('--work', type=Path, default=ROOT / '.local/windows-update-test')
parser.add_argument('--port', type=int, default=8765)
parser.add_argument('--offline', action='store_true', help='Use already cached Flutter packages')
@@ -56,7 +58,7 @@ def main():
definitions = work / 'defines.json'
definitions.write_text(json.dumps({'CUTDEX_UPDATE_SMOKE_ROOT': work.as_posix(),
'CUTDEX_WINDOWS_UPDATE_URL': f'http://127.0.0.1:{args.port}'}), encoding='utf-8')
environment = dict(os.environ)
environment = project_environment()
# Isolate Flutter caches, generated runner files and output from live builds.
source = work / 'source'
source.mkdir()
@@ -74,13 +76,13 @@ def main():
entry = source / 'tool/testing/windows_update_smoke.dart'
entry.parent.mkdir(parents=True)
shutil.copyfile(ROOT / 'tool/testing/windows_update_smoke.dart', entry)
subprocess.run([args.flutter, 'pub', 'get'] + (['--offline'] if args.offline else []),
subprocess.run(tool_command('flutter', ['pub', 'get'] + (['--offline'] if args.offline else []), cwd=source),
cwd=source, env=environment, check=True)
# Keep test packages separate from the app's normal release output.
for build in [900001, 900002]:
subprocess.run([args.flutter, 'build', 'windows', '--no-pub', '--release', '--flavor', 'development',
subprocess.run(tool_command('flutter', ['build', 'windows', '--no-pub', '--release', '--flavor', 'development',
'--target', 'tool/testing/windows_update_smoke.dart', '--build-name', '1.0.0',
'--build-number', str(build), '--dart-define-from-file', str(definitions)],
'--build-number', str(build), '--dart-define-from-file', str(definitions)], cwd=source),
cwd=source, env=environment, check=True)
app = source / 'build/windows/x64/development/runner/Release'
release = work / ('baseline' if build == 900001 else 'public')
+3 -3
View File
@@ -21,7 +21,7 @@ class UpdatePublicationTests(unittest.TestCase):
def test_packaging_tool_check_does_not_resolve_flutter_dependencies(self):
from subprocess import CompletedProcess
with patch('windows_updates.resolved_deskup', side_effect=AssertionError('No Flutter config')), \
patch('windows_updates.subprocess.run', return_value=CompletedProcess([], 0, f'vpk {SDK_VERSION}', '')):
patch('windows_updates.run', return_value=CompletedProcess([], 0, f'vpk {SDK_VERSION}', '')):
check_tool(['vpk'])
def test_build_sdk_check_rejects_mismatched_and_missing_versions(self):
@@ -53,7 +53,7 @@ class UpdatePublicationTests(unittest.TestCase):
def test_missing_package_config_requests_pub_get(self):
with tempfile.TemporaryDirectory() as directory:
with patch('windows_updates.ROOT', Path(directory)):
with self.assertRaisesRegex(ValueError, 'flutter pub get'):
with self.assertRaisesRegex(ValueError, 'flutter_local.dart pub get'):
resolved_deskup()
def test_display_version_conversion_is_shared_and_ordered(self):
@@ -64,7 +64,7 @@ class UpdatePublicationTests(unittest.TestCase):
update_version(version, build)
def test_invalid_pack_version_never_starts_vpk(self):
with patch('windows_updates.subprocess.run') as run:
with patch('windows_updates.run') as run:
with self.assertRaises(ValueError):
pack_release(['vpk'], app=Path('app'), output=Path('release'),
package_id='Cutdex', version='1.0.0.42', title='Cutdex')
+19 -27
View File
@@ -1,27 +1,28 @@
"""Package audited Windows releases with Velopack, or serve a loopback test feed."""
import argparse
from functools import partial
import hashlib
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
import json
from pathlib import Path
import re
import subprocess
import sys
from urllib.parse import urljoin, urlparse
from urllib.request import url2pathname
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from common.files import file_sha256
from common.process import ROOT, cli, run
from check_windows_release import audit
from update_versions import numeric_version, update_version
ROOT = Path(__file__).resolve().parents[2]
SDK_VERSION = '1.2.161'
def resolved_deskup():
config = ROOT / '.dart_tool/package_config.json'
if not config.is_file():
raise ValueError('Run flutter pub get before using Windows update tools')
raise ValueError('Run fvm dart tool/flutter_local.dart pub get before using Windows update tools')
packages = json.loads(config.read_text(encoding='utf-8'))['packages']
package = next(item for item in packages if item['name'] == 'deskup')
uri = urlparse(urljoin(config.as_uri(), package['rootUri']))
@@ -48,7 +49,7 @@ def vpk_command(path):
def check_tool(command):
result = subprocess.run(command + ['--help'], capture_output=True, text=True,
result = run(command + ['--help'], cwd=Path.cwd(), capture_output=True, text=True,
encoding='utf-8', errors='replace', check=True, timeout=30)
if not re.search(rf'(?<![\d.]){re.escape(SDK_VERSION)}(?![\d.])', result.stdout + result.stderr):
raise ValueError(f'Use vpk {SDK_VERSION} to match the native SDK')
@@ -56,11 +57,11 @@ def check_tool(command):
def pack_release(command, *, app, output, package_id, version, title):
numeric_version(version)
subprocess.run(command + ['pack', '--packId', package_id, '--packVersion', version,
run(command + ['pack', '--packId', package_id, '--packVersion', version,
'--packDir', str(app), '--mainExe', 'cutdex.exe',
'--packTitle', title, '--runtime', 'win-x64',
'--channel', 'win-x64', '--outputDir', str(output),
'--delta', 'none'], check=True)
'--delta', 'none'], cwd=Path.cwd(), check=True)
def file_version(app):
@@ -103,9 +104,8 @@ def verify_manifest(app):
file = candidate.resolve()
if not file.is_relative_to(app) or candidate.is_symlink():
raise ValueError(f'Invalid manifest path: {name}')
with file.open('rb') as stream:
if hashlib.file_digest(stream, 'sha256').hexdigest().lower() != expected.lower():
raise ValueError(f'Release checksum mismatch: {name}')
if file_sha256(file).lower() != expected.lower():
raise ValueError(f'Release checksum mismatch: {name}')
def package_app(app, output, vpk, *, development=False, require_processing=True):
@@ -159,23 +159,15 @@ def main():
server.add_argument('--directory', type=Path, required=True)
server.add_argument('--port', type=int, default=8765)
args = parser.parse_args()
try:
if args.command == 'pack':
verify_sdk_version()
print(json.dumps(package_app(args.app, args.output, args.vpk,
development=args.development)))
elif args.command == 'verify-sdk':
print(f'Velopack SDK {verify_sdk_version()} verified')
else:
serve(args.directory, args.port)
except KeyboardInterrupt:
return
except (ValueError, OSError) as error:
print(str(error), file=sys.stderr)
raise SystemExit(1) from error
except subprocess.CalledProcessError as error:
raise SystemExit(error.returncode) from error
if args.command == 'pack':
verify_sdk_version()
print(json.dumps(package_app(args.app, args.output, args.vpk,
development=args.development)))
elif args.command == 'verify-sdk':
print(f'Velopack SDK {verify_sdk_version()} verified')
else:
serve(args.directory, args.port)
if __name__ == '__main__':
main()
sys.exit(cli(main))