4 Commits
7 changed files with 337 additions and 56 deletions

No files matched your search

+13 -5
View File
@@ -13,13 +13,21 @@ shipping a production signed Android release. The Windows ZIP includes the whole
Flutter Release directory and passes the PE dependency audit. Processing workers
and optional models are separate; these four repositories contain no worker bundle.
PR/main CI analyzes and tests the app, builds both platforms, and uploads
cutdex-release-packages including SHA256SUMS and a release manifest. It also saves
CI always analyzes and tests the app. Ordinary code PRs also compile both
platforms, but skip Windows packaging, artifact uploads and final assembly.
Documentation-only PRs skip platform compilation as well. PR changes to CI,
tooling, native platform configuration, package dependencies or app update code
run the complete pipeline. `ci_scope.py` compares the PR base and head using Git
history, including deleted files; a failed comparison fails code checks.
Main pushes and manual CI runs always execute the complete pipeline and upload
cutdex-release-packages including SHA256SUMS and a release manifest. They also save
cutdex-release-metadata containing only the manifest, checksums, Windows update
index and audit report. Platform, complete and metadata artifacts retain 30 days. Protect main
with `Gitea CI / Gitea CI passed (pull_request)`.
with `Gitea CI / Gitea CI passed (pull_request)`. This required check validates
every expected job and permits skipped jobs only when the selected scope
explicitly excludes them; failures, cancellations and unexpected skips fail it.
Windows compilation and packaging are separate jobs. Compilation saves the
Windows compilation and packaging are separate jobs. Full-pipeline compilation saves the
unpackaged Release directory as `cutdex-windows-app` for 30 days; packaging
downloads it and runs the existing PE audit and Velopack tools. Rerunning a failed
packaging job reuses this app without recompiling. Assembly and Release jobs
@@ -62,7 +70,7 @@ operator attention. Published Releases are never overwritten. The built-in
GITEA_TOKEN handles release writes and Actions artifact reads; no separate
release-write PAT is required. Do not commit credentials or keystores.
PR/main CI produces Actions artifacts without creating Releases. If a tag is pushed
Full-pipeline CI produces Actions artifacts without creating Releases. If a tag is pushed
before main CI succeeds, release preparation fails without creating a draft; retry
the Release workflow once CI has finished. This design overlaps platform uploads,
not main CI builds with Release uploads. There is no legacy whole-archive
+30 -1
View File
@@ -1,6 +1,22 @@
# CI build performance
The workflow runs checks first, then Android and Windows compilation concurrently.
The workflow runs checks first, then Android and Windows compilation concurrently
when compilation is required. Ordinary code PRs stop after compilation and native
SDK validation; they skip artifact transfers, Windows packaging and assembly.
Documentation-only PRs run checks without compiling either platform. Changes to
CI, tooling, native platform configuration, dependencies and app update code
force the full pipeline. Main pushes and manual CI runs always use the full
pipeline, preserving the exact-commit artifacts needed by Release.
Scope selection uses the complete PR base/head history in the quality checkout.
Other checkouts retain their default shallow fetch. Git comparisons include
deleted paths and disable rename detection, so moving a packaging file into docs
cannot hide its deletion. Unknown paths compile both platforms; empty PR diffs
run the full pipeline. Scope selection errors fail CI instead of skipping jobs.
The final required check requires success for selected jobs and `skipped` for
excluded jobs, and always requires successful code checks.
In the full pipeline,
Windows compilation saves `cutdex-windows-app`; an independent Windows job
downloads that app, audits it and creates Velopack packages. Packaging needs
neither Flutter dependencies nor another Windows compilation. The Android job
@@ -14,6 +30,19 @@ enabled for CI. Do not clear these caches between runs. Each job must have its o
checkout; do not share a Flutter `build/` or `.dart_tool/` directory between jobs.
With an ephemeral runner, these user directories must be persisted separately.
The local `prepare-flutter` action owns cache setup, Flutter version validation,
optional Java configuration and locked dependency resolution for the quality,
Android and Windows compilation jobs. `FLUTTER_VERSION` is declared once in the
CI workflow. The separate `prepare-windows-packaging` action owns the user .NET
installation and packaging tool setup, so packaging retries do not resolve
Flutter dependencies. Individual setup steps remain visible within each action.
Workflow-level environment variables contain only shared nonsecret settings.
The SDK token is limited to quality and platform compilation jobs. The fixed
Maven account name is set only on the Android build step, matching the SDK token
owner rather than the user who triggered CI. Assembly needs no SDK credentials;
Release credentials remain confined to the Release workflow's publishing jobs.
Build commands keep Flutter's default Pub preparation after the explicit locked
resolution. Do not use `--no-pub`: Flutter also regenerates release plugin
registrants in that preparation, removing dev-only plugins such as integration_test.
+40
View File
@@ -0,0 +1,40 @@
name: Prepare Flutter build environment
description: Configure persistent caches, verify Flutter and resolve locked dependencies.
inputs:
flutter-version:
description: Required Flutter framework version
required: true
configure-java:
description: Configure Flutter to use the runner's JAVA_HOME
default: 'false'
runs:
using: composite
steps:
- name: Configure persistent build caches
shell: pwsh
run: ./tool/gitea/prepare-build-cache.ps1
- name: Verify Flutter version
shell: pwsh
env:
REQUIRED_FLUTTER_VERSION: ${{ inputs.flutter-version }}
run: |
$ErrorActionPreference = 'Stop'
$output = flutter --version --machine
if ($LASTEXITCODE -ne 0) { throw 'Cannot read Flutter version.' }
$version = $output | ConvertFrom-Json
if ($version.frameworkVersion -ne $env:REQUIRED_FLUTTER_VERSION) {
throw "Flutter $env:REQUIRED_FLUTTER_VERSION required; found $($version.frameworkVersion)."
}
- name: Configure Flutter Java
if: ${{ inputs.configure-java == 'true' }}
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
if (-not $env:JAVA_HOME) { throw 'JAVA_HOME is required for Flutter JDK setup.' }
flutter config --jdk-dir=$env:JAVA_HOME
if ($LASTEXITCODE -ne 0) { throw 'Flutter JDK setup failed.' }
- name: Resolve locked Flutter dependencies
shell: pwsh
run: |
flutter pub get --enforce-lockfile
if ($LASTEXITCODE -ne 0) { throw 'Locked Flutter dependency resolution failed.' }
@@ -0,0 +1,20 @@
name: Prepare Windows packaging environment
description: Reuse the user .NET installation and pinned packaging tools independently of Flutter.
runs:
using: composite
steps:
- name: Configure user .NET installation
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$directory = Join-Path $env:LOCALAPPDATA 'Cutdex/ci-tools/dotnet'
[IO.Directory]::CreateDirectory($directory) | Out-Null
"DOTNET_INSTALL_DIR=$directory" | Out-File -LiteralPath $env:GITHUB_ENV -Encoding utf8 -Append
"DOTNET_ROOT=$directory" | Out-File -LiteralPath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Set up .NET SDK
uses: https://github.com/actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1
with:
dotnet-version: '10.0.x'
- name: Prepare pinned packaging tools
shell: pwsh
run: ./tool/gitea/prepare-package-tools.ps1
+65 -50
View File
@@ -13,6 +13,7 @@ concurrency:
cancel-in-progress: true
env:
PYTHONUTF8: '1'
FLUTTER_VERSION: '3.47.5'
CUTDEX_GITEA_INTERNAL_URL: http://127.0.0.1:3000
GIT_CONFIG_COUNT: '2'
GIT_CONFIG_KEY_0: core.autocrlf
@@ -23,8 +24,10 @@ jobs:
quality:
name: Check code and tests
runs-on: cutdex-windows-x64
outputs:
build-app: ${{ steps.scope.outputs.build-app }}
package-app: ${{ steps.scope.outputs.package-app }}
env:
GITEA_ACTOR: lingjhf
CUTDEX_GITEA_TOKEN: ${{ secrets.CUTDEX_GITEA_TOKEN }}
steps:
- name: Check out source
@@ -32,16 +35,21 @@ jobs:
with:
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- name: Configure persistent build caches
run: ./tool/gitea/prepare-build-cache.ps1
- name: Verify Flutter version and configure Java
fetch-depth: 0
- name: Select compilation and packaging scope
id: scope
env:
CI_EVENT_NAME: ${{ gitea.event_name }}
CI_PR_BASE_SHA: ${{ gitea.event.pull_request.base.sha }}
CI_PR_HEAD_SHA: ${{ gitea.event.pull_request.head.sha }}
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.' }
- name: Resolve locked Flutter dependencies
run: flutter pub get --enforce-lockfile
python tool/gitea/ci_scope.py
if ($LASTEXITCODE -ne 0) { throw 'CI scope selection failed.' }
- name: Prepare Flutter environment
uses: ./.gitea/actions/prepare-flutter
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
configure-java: 'true'
- name: Analyze Dart code
run: dart analyze --fatal-infos
- name: Run Flutter tests
@@ -56,9 +64,9 @@ jobs:
android:
name: Build Android APK
needs: quality
if: ${{ needs.quality.outputs.build-app == 'true' }}
runs-on: cutdex-windows-x64
env:
GITEA_ACTOR: lingjhf
CUTDEX_GITEA_TOKEN: ${{ secrets.CUTDEX_GITEA_TOKEN }}
steps:
- name: Check out source
@@ -66,24 +74,22 @@ jobs:
with:
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- name: Configure persistent build caches
run: ./tool/gitea/prepare-build-cache.ps1
- name: Verify Flutter version and configure Java
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.' }
- name: Resolve locked Flutter dependencies
run: flutter pub get --enforce-lockfile
- name: Prepare Flutter environment
uses: ./.gitea/actions/prepare-flutter
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
configure-java: 'true'
- name: Configure Gradle memory and build cache
run: |
$file = 'android/gradle.properties'
$properties = [IO.File]::ReadAllText($file).Replace('-Xmx8G', '-Xmx3G').Replace('MaxMetaspaceSize=4G', 'MaxMetaspaceSize=768m')
[IO.File]::WriteAllText($file, $properties + "`norg.gradle.workers.max=4`norg.gradle.caching=true`n")
- name: Build production Android APK
env:
GITEA_ACTOR: lingjhf
run: flutter build apk --release --flavor production --target-platform android-arm64,android-x64
- name: Upload Android CI artifact
if: ${{ needs.quality.outputs.package-app == 'true' }}
uses: ./.gitea/actions/upload-artifact
with:
name: cutdex-android-build
@@ -94,9 +100,9 @@ jobs:
windows-build:
name: Build Windows x64 app
needs: quality
if: ${{ needs.quality.outputs.build-app == 'true' }}
runs-on: cutdex-windows-x64
env:
GITEA_ACTOR: lingjhf
CUTDEX_GITEA_TOKEN: ${{ secrets.CUTDEX_GITEA_TOKEN }}
steps:
- name: Check out source
@@ -104,14 +110,10 @@ jobs:
with:
persist-credentials: false
github-server-url: ${{ env.CUTDEX_GITEA_INTERNAL_URL }}
- name: Configure persistent build caches
run: ./tool/gitea/prepare-build-cache.ps1
- name: Verify Flutter version
run: |
$version = flutter --version --machine | ConvertFrom-Json
if ($version.frameworkVersion -ne '3.47.5') { throw 'Flutter 3.47.5 required.' }
- name: Resolve locked Flutter dependencies
run: flutter pub get --enforce-lockfile
- name: Prepare Flutter environment
uses: ./.gitea/actions/prepare-flutter
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
- name: Build production Windows app
run: |
Remove-Item Env:CUTDEX_WINDOWS_PATH, Env:CUTDEX_WINDOWS_PACKAGE_PATH -ErrorAction SilentlyContinue
@@ -122,6 +124,7 @@ jobs:
python tool/windows/windows_updates.py verify-sdk
if ($LASTEXITCODE -ne 0) { throw 'Windows native SDK version validation failed.' }
- name: Save Windows app for independent packaging retries
if: ${{ needs.quality.outputs.package-app == 'true' }}
uses: ./.gitea/actions/upload-artifact
with:
name: cutdex-windows-app
@@ -137,7 +140,8 @@ jobs:
windows:
name: Audit and package Windows x64
needs: windows-build
needs: [quality, windows-build]
if: ${{ needs.quality.outputs.package-app == 'true' }}
runs-on: cutdex-windows-x64
steps:
- name: Check out source
@@ -152,18 +156,8 @@ jobs:
with:
name: cutdex-windows-app
path: build/windows/x64/production/runner/Release/
- name: Configure user .NET installation
run: |
$directory = Join-Path $env:LOCALAPPDATA 'Cutdex/ci-tools/dotnet'
[IO.Directory]::CreateDirectory($directory) | Out-Null
"DOTNET_INSTALL_DIR=$directory" | Out-File -LiteralPath $env:GITHUB_ENV -Encoding utf8 -Append
"DOTNET_ROOT=$directory" | Out-File -LiteralPath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Set up .NET SDK
uses: https://github.com/actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1
with:
dotnet-version: '10.0.x'
- name: Prepare pinned packaging tools
run: ./tool/gitea/prepare-package-tools.ps1
- name: Prepare Windows packaging environment
uses: ./.gitea/actions/prepare-windows-packaging
- name: Audit and package Windows release
run: |
& $env:PACKAGE_PYTHON tool/gitea/package-app.py --platform windows --vpk $env:VPK_PATH
@@ -178,11 +172,9 @@ jobs:
build:
name: Assemble and validate CI artifacts
needs: [android, windows]
needs: [quality, android, windows]
if: ${{ needs.quality.outputs.package-app == 'true' }}
runs-on: cutdex-windows-x64
env:
GITEA_ACTOR: lingjhf
CUTDEX_GITEA_TOKEN: ${{ secrets.CUTDEX_GITEA_TOKEN }}
steps:
- name: Check out source
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
@@ -224,11 +216,34 @@ jobs:
checks:
name: Gitea CI passed
if: always()
needs: build
needs: [quality, android, windows-build, windows, build]
runs-on: cutdex-windows-x64
steps:
- name: Verify CI result
env:
RESULT: ${{ needs.build.result }}
QUALITY_RESULT: ${{ needs.quality.result }}
BUILD_APP: ${{ needs.quality.outputs.build-app }}
PACKAGE_APP: ${{ needs.quality.outputs.package-app }}
# The local runner omits results for jobs excluded by their condition.
# Required jobs still fail below if this becomes 'skipped'.
ANDROID_RESULT: ${{ needs.android.result || 'skipped' }}
WINDOWS_BUILD_RESULT: ${{ needs.windows-build.result || 'skipped' }}
WINDOWS_PACKAGE_RESULT: ${{ needs.windows.result || 'skipped' }}
ASSEMBLY_RESULT: ${{ needs.build.result || 'skipped' }}
run: |
if ($env:RESULT -ne 'success') { throw "App build: $env:RESULT" }
if ($env:QUALITY_RESULT -ne 'success') { throw "Code checks: $env:QUALITY_RESULT" }
if ($env:BUILD_APP -notin @('true', 'false') -or $env:PACKAGE_APP -notin @('true', 'false')) {
throw 'Missing or invalid CI scope outputs.'
}
if ($env:PACKAGE_APP -eq 'true' -and $env:BUILD_APP -ne 'true') { throw 'Packaging requires compilation.' }
$compileResult = if ($env:BUILD_APP -eq 'true') { 'success' } else { 'skipped' }
$packageResult = if ($env:PACKAGE_APP -eq 'true') { 'success' } else { 'skipped' }
$jobs = @(
@{ Name = 'Android compilation'; Result = $env:ANDROID_RESULT; Expected = $compileResult },
@{ Name = 'Windows compilation'; Result = $env:WINDOWS_BUILD_RESULT; Expected = $compileResult },
@{ Name = 'Windows packaging'; Result = $env:WINDOWS_PACKAGE_RESULT; Expected = $packageResult },
@{ Name = 'Artifact assembly'; Result = $env:ASSEMBLY_RESULT; Expected = $packageResult }
)
foreach ($job in $jobs) {
if ($job.Result -ne $job.Expected) { throw "$($job.Name): $($job.Result), expected $($job.Expected)." }
}
+70
View File
@@ -0,0 +1,70 @@
"""Select PR compilation and packaging scope from the complete Git change set."""
import os
from pathlib import Path, PurePosixPath
import re
import subprocess
import sys
def packaging_change(path):
path = path.lower()
return (
path.startswith(('.gitea/', '.github/workflows/', '.github/actions/',
'tool/', 'android/', 'windows/',
'packages/cutdex_native/android/',
'packages/cutdex_native/windows/',
'lib/integrations/app_update',
'lib/features/settings/update'))
or PurePosixPath(path).name in {'pubspec.yaml', 'pubspec.lock', '.metadata'}
or (path.startswith('test/') and 'update' in path)
)
def documentation_change(path):
path = PurePosixPath(path.lower())
return (
str(path).startswith(('docs/', '.github/issue_template/'))
or str(path) == '.github/pull_request_template.md'
or (len(path.parts) == 1 and path.suffix in {'.md', '.rst'})
or (len(path.parts) == 1 and path.name in {'license', 'notice'})
or (str(path).startswith('packages/') and path.name == 'readme.md')
)
def select_scope(event, paths):
paths = list(paths)
if event != 'pull_request' or not paths or any(packaging_change(path) for path in paths):
return {'build-app': True, 'package-app': True}
return {'build-app': not all(documentation_change(path) for path in paths),
'package-app': False}
def changed_paths(base, head):
for sha in (base, head):
if not re.fullmatch(r'[0-9a-f]{40}', sha):
raise ValueError('PR base and head must be full Git commit SHAs')
result = subprocess.run(
['git', 'diff', '--name-only', '--no-renames', '-z', f'{base}...{head}'],
check=True, capture_output=True,
)
return result.stdout.decode('utf-8', errors='surrogateescape').rstrip('\0').split('\0') if result.stdout else []
def main():
event = os.environ['CI_EVENT_NAME']
paths = changed_paths(os.environ.get('CI_PR_BASE_SHA', ''),
os.environ.get('CI_PR_HEAD_SHA', '')) if event == 'pull_request' else []
scope = select_scope(event, paths)
with Path(os.environ['GITHUB_OUTPUT']).open('a', encoding='utf-8') as stream:
for name, enabled in scope.items():
stream.write(f'{name}={str(enabled).lower()}\n')
print(f"CI scope: compile={scope['build-app']}, package={scope['package-app']}")
if __name__ == '__main__':
try:
main()
except (KeyError, ValueError, subprocess.CalledProcessError) as error:
print(f'Cannot determine CI scope: {error}', file=sys.stderr)
sys.exit(1)
+99
View File
@@ -0,0 +1,99 @@
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
from unittest.mock import patch
from ci_scope import changed_paths, main, select_scope
class ScopeTests(unittest.TestCase):
def test_main_and_manual_runs_always_produce_release_artifacts(self):
for event in ('push', 'workflow_dispatch'):
with self.subTest(event=event):
self.assertEqual(select_scope(event, ['README.md']),
{'build-app': True, 'package-app': True})
def test_regular_code_pr_compiles_both_platforms_without_packaging(self):
self.assertEqual(select_scope('pull_request', ['lib/main.dart', 'test/app_test.dart']),
{'build-app': True, 'package-app': False})
def test_documentation_only_pr_skips_platform_jobs(self):
self.assertEqual(select_scope('pull_request', ['README.md', 'docs/setup.md',
'packages/cutdex_ui/README.md', '.github/PULL_REQUEST_TEMPLATE.md']),
{'build-app': False, 'package-app': False})
def test_documentation_does_not_hide_code_changes(self):
self.assertEqual(select_scope('pull_request', ['README.md', 'lib/main.dart']),
{'build-app': True, 'package-app': False})
def test_packaging_changes_force_full_validation(self):
for path in ('.gitea/workflows/ci.yml', '.gitea/actions/upload-artifact/action.yml',
'tool/gitea/ci_scope.py', 'tool/windows/windows_updates.py',
'windows/runner/main.cpp.in', 'android/app/build.gradle.kts',
'pubspec.yaml', 'pubspec.lock', 'packages/cutdex_ui/pubspec.yaml',
'packages/cutdex_native/windows/CMakeLists.txt',
'lib/integrations/app_update_bridge.dart',
'lib/features/settings/update_controller.dart', 'test/app_updates_test.dart'):
with self.subTest(path=path):
self.assertEqual(select_scope('pull_request', ['README.md', path]),
{'build-app': True, 'package-app': True})
def test_arbitrary_runtime_markdown_is_not_treated_as_documentation(self):
self.assertTrue(select_scope('pull_request', ['assets/help.md'])['build-app'])
def test_empty_change_set_is_conservative(self):
self.assertEqual(select_scope('pull_request', []),
{'build-app': True, 'package-app': True})
def test_invalid_or_missing_shas_are_rejected(self):
for base, head in (('', 'a' * 40), ('--help', 'b' * 40), ('a' * 40, 'bad')):
with self.subTest(base=base, head=head), self.assertRaises(ValueError):
changed_paths(base, head)
def test_failed_git_comparison_cannot_skip_builds(self):
with patch('ci_scope.subprocess.run', side_effect=subprocess.CalledProcessError(1, ['git'])):
with self.assertRaises(subprocess.CalledProcessError):
changed_paths('a' * 40, 'b' * 40)
def test_outputs_propagate_as_action_boolean_strings(self):
with tempfile.TemporaryDirectory() as directory:
output = Path(directory) / 'output'
with patch.dict(os.environ, {'CI_EVENT_NAME': 'pull_request',
'CI_PR_BASE_SHA': 'a' * 40, 'CI_PR_HEAD_SHA': 'b' * 40,
'GITHUB_OUTPUT': str(output)}), patch('ci_scope.changed_paths', return_value=['lib/main.dart']):
main()
self.assertEqual(output.read_text(), 'build-app=true\npackage-app=false\n')
def test_deleted_build_file_is_detected_when_renamed_into_docs(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
def git(*args):
return subprocess.check_output(['git', '-C', str(root), *args], text=True).strip()
git('init', '--quiet')
git('config', 'user.name', 'CI scope test')
git('config', 'user.email', 'ci-scope@example.invalid')
(root / 'tool').mkdir()
(root / 'tool/package.py').write_text('packaging input\n')
git('add', '.')
git('commit', '--quiet', '-m', 'base')
base = git('rev-parse', 'HEAD')
(root / 'docs').mkdir()
(root / 'tool/package.py').rename(root / 'docs/package.md')
git('add', '-A')
git('commit', '--quiet', '-m', 'move build file')
head = git('rev-parse', 'HEAD')
original = os.getcwd()
try:
os.chdir(root)
paths = changed_paths(base, head)
finally:
os.chdir(original)
self.assertIn('tool/package.py', paths)
self.assertEqual(select_scope('pull_request', paths),
{'build-app': True, 'package-app': True})
if __name__ == '__main__':
unittest.main()