From 33785acbbb3d2f16d4efe870843ca7ab760cc27f Mon Sep 17 00:00:00 2001 From: TRIP <1933142963@qq.com> Date: Sun, 8 Nov 2026 22:38:10 +0800 Subject: [PATCH 1/3] =?UTF-8?q?perf(ci):=20=E4=BC=98=E5=8C=96=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=B9=B6=E5=8F=91=E3=80=81=E8=B6=85=E6=97=B6=E8=BE=B9?= =?UTF-8?q?=E7=95=8C=E5=92=8C=E6=9E=84=E5=BB=BA=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions/cache-npm/action.yml | 13 +- .github/workflows/android-apk.yml | 31 ++- .github/workflows/check-linux-egui.yml | 8 + .github/workflows/ci.yml | 228 +++++++++++++++--- .github/workflows/release-harmony.yml | 2 + .github/workflows/release-tauri.yml | 58 +++-- docs/ci-trigger-and-cache-policy.md | 60 +++-- .../app/scripts/ci-changed-areas.test.mjs | 13 +- .../app/scripts/ci-performance.test.mjs | 159 ++++++++++++ .../app/scripts/frontend-test-runner.mjs | 24 +- .../app/scripts/frontend-test-runner.test.mjs | 49 +++- ...windows-hang-diagnostics-contract.test.mjs | 5 +- .../windows-msi-release-contract.test.mjs | 11 +- .../workflow-concurrency-contract.test.mjs | 32 ++- openless-all/app/tsconfig.json | 2 + 15 files changed, 586 insertions(+), 109 deletions(-) create mode 100644 openless-all/app/scripts/ci-performance.test.mjs diff --git a/.github/actions/cache-npm/action.yml b/.github/actions/cache-npm/action.yml index 9d545e0c0..b469cebc7 100644 --- a/.github/actions/cache-npm/action.yml +++ b/.github/actions/cache-npm/action.yml @@ -9,17 +9,26 @@ runs: run: | echo "path=$(npm config get cache)" >> "$GITHUB_OUTPUT" echo "arch=$(node -p process.arch)" >> "$GITHUB_OUTPUT" + # Prefer verified tarballs already in the download cache. Keep network + # retries bounded; npm ci still validates the lockfile and integrity. + echo 'NPM_CONFIG_PREFER_OFFLINE=true' >> "$GITHUB_ENV" + echo 'NPM_CONFIG_AUDIT=false' >> "$GITHUB_ENV" + echo 'NPM_CONFIG_FUND=false' >> "$GITHUB_ENV" + echo 'NPM_CONFIG_FETCH_RETRIES=2' >> "$GITHUB_ENV" + echo 'NPM_CONFIG_FETCH_TIMEOUT=60000' >> "$GITHUB_ENV" # Keep setup-node's existing key and path so the current beta cache remains # reusable. Cache lookup falls back to the PR base/default branch on a miss. - name: Restore npm outside beta builds - if: github.ref != 'refs/heads/beta' || (github.event_name != 'push' && github.event_name != 'workflow_dispatch') + if: github.ref != 'refs/heads/beta' || (github.event_name != 'push' && github.event_name != 'workflow_dispatch' && github.event_name != 'schedule') uses: actions/cache/restore@v4 with: path: ${{ steps.npm.outputs.path }} key: node-cache-${{ runner.os }}-${{ steps.npm.outputs.arch }}-npm-${{ hashFiles('openless-all/app/package-lock.json') }} + restore-keys: node-cache-${{ runner.os }}-${{ steps.npm.outputs.arch }}-npm- - name: Maintain npm cache on beta builds - if: github.ref == 'refs/heads/beta' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') + if: github.ref == 'refs/heads/beta' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') uses: actions/cache@v4 with: path: ${{ steps.npm.outputs.path }} key: node-cache-${{ runner.os }}-${{ steps.npm.outputs.arch }}-npm-${{ hashFiles('openless-all/app/package-lock.json') }} + restore-keys: node-cache-${{ runner.os }}-${{ steps.npm.outputs.arch }}-npm- diff --git a/.github/workflows/android-apk.yml b/.github/workflows/android-apk.yml index 89a32f624..06dba14d8 100644 --- a/.github/workflows/android-apk.yml +++ b/.github/workflows/android-apk.yml @@ -39,13 +39,15 @@ on: type: boolean default: false -# Repeated pushes of the same tag run only the newest; workflow_dispatch isolates by run_id to avoid mutual cancellation. +# Supersede equivalent manual builds; different ABI/profile/signing requests stay +# independent. Tag publication must finish once started. concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && github.run_id || github.ref }} - cancel-in-progress: ${{ github.event_name == 'push' }} + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}-${{ inputs.abis || 'aarch64' }}-${{ inputs.fast_profile || false }}-${{ inputs.signed_debug || false }} + cancel-in-progress: ${{ github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/heads/') }} jobs: plan: + timeout-minutes: 10 name: Plan Android ABI matrix permissions: contents: read @@ -148,6 +150,7 @@ jobs: echo "Resolved ABIs: $abi_list (fast_profile=$fast)" build-android-apk: + timeout-minutes: 90 name: Build Android (${{ matrix.abi }}) needs: plan # Publishing is `publish-android-release`. Branch and schedule builds only @@ -226,6 +229,7 @@ jobs: packages: platform-tools - name: Install NDK and accept SDK licenses + timeout-minutes: 15 shell: bash run: | set -euo pipefail @@ -249,8 +253,8 @@ jobs: - uses: actions/setup-node@v4 with: node-version: "22" - cache: npm - cache-dependency-path: openless-all/app/package-lock.json + - name: Cache npm from beta + uses: ./.github/actions/cache-npm - uses: dtolnay/rust-toolchain@stable with: @@ -265,13 +269,15 @@ jobs: shared-key: android-${{ matrix.abi }} workspaces: openless-all/app/src-tauri -> target cache-on-failure: true + save-if: ${{ github.ref == 'refs/heads/beta' && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }} - uses: gradle/actions/setup-gradle@v4 with: - # Keep Gradle caches for post-job save; do not wipe ~/.gradle before post. - cache-read-only: false + # Keep reusable baseline caches; avoid one large copy per release tag. + cache-read-only: ${{ github.ref != 'refs/heads/beta' || (github.event_name != 'schedule' && github.event_name != 'workflow_dispatch') }} - name: Install npm deps + timeout-minutes: 10 working-directory: openless-all/app run: npm ci @@ -318,6 +324,7 @@ jobs: run: node scripts/configure-android-release-signing.mjs - name: Prime Gradle wrapper + timeout-minutes: 10 working-directory: openless-all/app shell: bash run: | @@ -333,6 +340,7 @@ jobs: exit 1 - name: Build Android debug APK + timeout-minutes: 70 if: needs.plan.outputs.mode == 'debug' working-directory: openless-all/app env: @@ -343,6 +351,7 @@ jobs: run: npm run tauri:android:build:debug - name: Build Android release APK + timeout-minutes: 70 if: needs.plan.outputs.mode == 'release' working-directory: openless-all/app env: @@ -379,6 +388,7 @@ jobs: - name: Upload Android APK artifact uses: actions/upload-artifact@v4 with: + retention-days: 14 name: ${{ needs.plan.outputs.mode == 'release' && format('openless-android-release-{0}', matrix.gradle_abi) || format('openless-android-debug-{0}', matrix.gradle_abi) }} path: ${{ steps.apk.outputs.apk_path }} if-no-files-found: error @@ -413,6 +423,7 @@ jobs: fi publish-android-release: + timeout-minutes: 30 name: Publish Android release assets if: needs.plan.outputs.is_tag_release == 'true' needs: [plan, build-android-apk] @@ -431,10 +442,11 @@ jobs: - uses: actions/setup-node@v4 with: node-version: "22" - cache: npm - cache-dependency-path: openless-all/app/package-lock.json + - name: Cache npm from beta + uses: ./.github/actions/cache-npm - name: Install npm deps + timeout-minutes: 10 working-directory: openless-all/app run: npm ci @@ -532,6 +544,7 @@ jobs: - name: Upload Android updater manifests uses: actions/upload-artifact@v4 with: + retention-days: 14 name: openless-android-updater-manifests if-no-files-found: error path: | diff --git a/.github/workflows/check-linux-egui.yml b/.github/workflows/check-linux-egui.yml index b7ef94538..dae4161e7 100644 --- a/.github/workflows/check-linux-egui.yml +++ b/.github/workflows/check-linux-egui.yml @@ -68,6 +68,7 @@ jobs: if: inputs.scope != 'none' - name: Install native build and test dependencies + timeout-minutes: 10 if: inputs.scope != 'none' # Same list as the packaging job: the fcitx5 plugin build and the # `pwsh` contract scripts both live here now. @@ -103,6 +104,7 @@ jobs: test -s build/openless.conf - name: Test Core, Linux host, and platform boundaries + timeout-minutes: 40 if: inputs.scope != 'none' working-directory: openless-all/app run: | @@ -136,6 +138,7 @@ jobs: pwsh -NoProfile -File ./scripts/check-linux-public-surface.ps1 - name: Test remote input TLS identity and Unix key permissions + timeout-minutes: 20 if: inputs.scope != 'none' working-directory: openless-all/app run: cargo test --locked --manifest-path src-tauri/backend-tests/Cargo.toml --test remote_tls @@ -162,6 +165,7 @@ jobs: ref: ${{ inputs.checkout_ref || github.ref }} - name: Install native build and packaging dependencies + timeout-minutes: 10 if: inputs.scope != 'none' run: | sudo add-apt-repository -y universe || true @@ -235,11 +239,13 @@ jobs: appstreamcli validate --no-net openless-all/app/linux-egui/packaging/top.openless.OpenLess.metainfo.xml - name: Build Linux egui host + timeout-minutes: 40 if: inputs.scope != 'none' working-directory: openless-all/app run: cargo build --locked --release -p openless-linux-egui - name: Package deb and rpm without Tauri + timeout-minutes: 10 if: inputs.scope != 'none' working-directory: openless-all/app env: @@ -285,6 +291,7 @@ jobs: if: inputs.scope != 'none' && (github.event_name != 'push' || env.RELEASE_TAG != '') uses: actions/upload-artifact@v7 with: + retention-days: 14 name: openless-linux-egui-x86_64 path: openless-all/app/target/linux-egui-packages/* if-no-files-found: error @@ -293,6 +300,7 @@ jobs: if: inputs.scope != 'none' && (github.event_name != 'push' || env.RELEASE_TAG != '') uses: actions/upload-artifact@v7 with: + retention-days: 14 name: openless-linux-egui-direct-download path: ${{ runner.temp }}/openless-linux-egui-direct-download/* if-no-files-found: error diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1dfca882b..82730995b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,10 +29,11 @@ on: options: [macos-latest, macos-15-intel] default: macos-latest -# Cancel old runs when the same PR is pushed repeatedly; workflow_dispatch is isolated by run_id. +# Supersede a PR or an equivalent manual request. Keep different manual +# platform/runner selections independent, and preserve baseline push evidence. concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && github.run_id || github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}-${{ inputs.platform || 'all' }}-${{ inputs.macos_runner || 'macos-latest' }} + cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }} jobs: # 判定这次改动能不能影响到各平台门禁。只有“改动物理上够不到”的变更才会 @@ -50,8 +51,6 @@ jobs: frontend: ${{ steps.detect.outputs.frontend }} android: ${{ steps.detect.outputs.android }} capsule: ${{ steps.detect.outputs.capsule }} - # Validate the pinned minimum compiler whenever native sources can change. - msrv_needed: ${{ steps.detect.outputs.msrv }} steps: - uses: actions/checkout@v4 with: @@ -74,16 +73,21 @@ jobs: echo "$area=$decision" >> "$GITHUB_OUTPUT" done - ui-motion: - name: UI motion (Chromium + WebKit) + ui-motion-browsers: + name: UI motion / ${{ matrix.browser }} + strategy: + fail-fast: false + max-parallel: 2 + matrix: + browser: [chromium, webkit] needs: [changes] - # Browser-rendered surface only: 15 minutes of Playwright on a change that - # cannot alter what Chromium/WebKit paints is pure cost. + # One worker per browser keeps timing-sensitive tests isolated; the two + # engines run on separate runners instead of serialising ~15 minutes. if: (github.event_name != 'workflow_dispatch' || inputs.platform != 'macos') && needs.changes.outputs.frontend != 'false' runs-on: ubuntu-24.04 # A hung Chromium/WebKit process must not hold the runner after the step cap. - # Setup plus the 12 minute dependency cap and the 30 minute browser cap. - timeout-minutes: 50 + # Includes cold browser setup and leaves time to upload a failed trace. + timeout-minutes: 40 defaults: run: working-directory: openless-all/app @@ -111,7 +115,8 @@ jobs: with: path: ~/.cache/ms-playwright # Browser revisions follow Playwright, not unrelated npm lock changes. - key: playwright-v1-${{ runner.os }}-${{ runner.arch }}-ubuntu24-${{ steps.playwright_version.outputs.version }} + # Cache only this engine; the other matrix leg owns its own download. + key: playwright-v2-${{ runner.os }}-${{ runner.arch }}-ubuntu24-${{ matrix.browser }}-${{ steps.playwright_version.outputs.version }} - name: Install Playwright system dependencies # Browser libraries are about 114MB. Eight minutes dies while a trickling # mirror is still transferring fonts, before Playwright starts. @@ -125,28 +130,52 @@ jobs: while IFS= read -r -d '' apt_source; do sudo sed -i -E 's#https?://azure[.]archive[.]ubuntu[.]com/ubuntu#https://archive.ubuntu.com/ubuntu#g' "$apt_source" done < <(find /etc/apt -type f \( -name '*.list' -o -name '*.sources' -o -name 'apt-mirrors.txt' \) -print0) - npx playwright install-deps chromium webkit + npx playwright install-deps "${{ matrix.browser }}" - name: Install Playwright browsers on cache miss if: steps.playwright_cache.outputs.cache-hit != 'true' timeout-minutes: 10 - run: npx playwright install chromium webkit + run: npx playwright install "${{ matrix.browser }}" - name: Save Playwright browsers on beta builds if: steps.playwright_cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/beta' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') uses: actions/cache/save@v4 with: path: ~/.cache/ms-playwright key: ${{ steps.playwright_cache.outputs.cache-primary-key }} - - name: Run Chromium and WebKit UI motion checks - timeout-minutes: 30 - run: npm run test:ui-motion + - name: Run UI motion checks + timeout-minutes: 20 + run: npm run test:ui-motion -- --project=${{ matrix.browser }} - uses: actions/upload-artifact@v4 if: failure() with: - name: ui-motion-failure + retention-days: 7 + name: ui-motion-failure-${{ matrix.browser }} path: | openless-all/app/test-results/ openless-all/app/playwright-report/ + # Preserve the existing required-check name. A skipped browser matrix is only + # acceptable when the change classifier explicitly says it is out of scope. + ui-motion: + name: UI motion (Chromium + WebKit) + needs: [changes, ui-motion-browsers] + if: always() + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Require both browser results + env: + CHANGES_RESULT: ${{ needs.changes.result }} + FRONTEND: ${{ needs.changes.outputs.frontend }} + BROWSERS_RESULT: ${{ needs.ui-motion-browsers.result }} + MACOS_ONLY: ${{ github.event_name == 'workflow_dispatch' && inputs.platform == 'macos' }} + run: | + test "$CHANGES_RESULT" = success + if [ "$MACOS_ONLY" = true ] || [ "$FRONTEND" = false ]; then + test "$BROWSERS_RESULT" = skipped + else + test "$BROWSERS_RESULT" = success + fi + android-check: needs: [changes] # Android compiles its own Rust graph: a bundle-only change cannot break it. @@ -169,6 +198,7 @@ jobs: packages: platform-tools - name: Install NDK + timeout-minutes: 15 shell: bash run: | set -euo pipefail @@ -221,14 +251,17 @@ jobs: cache-read-only: ${{ github.ref != 'refs/heads/beta' || (github.event_name != 'push' && github.event_name != 'workflow_dispatch') }} - name: Install Linux check dependencies + timeout-minutes: 10 run: | sudo apt-get update sudo apt-get install -y build-essential curl file libpulse0 libssl-dev wget - name: Install frontend dependencies + timeout-minutes: 10 run: npm ci - name: Build frontend (tsc + vite) + timeout-minutes: 10 # generate_context! requires frontendDist (../dist) to exist on Android too. run: npm run build @@ -239,15 +272,18 @@ jobs: # build script finds them through SHERPA_ONNX_LIB_DIR and has no Android # prebuilt download of its own. - name: Prepare sherpa-onnx Android libraries + timeout-minutes: 10 run: echo "SHERPA_ONNX_LIB_DIR=$(node scripts/sherpa-onnx-android.mjs)" >> "$GITHUB_ENV" - name: Check Tauri backend (Android target) + timeout-minutes: 25 run: cargo check --locked --manifest-path src-tauri/Cargo.toml --target aarch64-linux-android - name: Initialize generated Android project run: npm run tauri -- android init --ci - name: Generate Tauri Gradle dependency scripts + timeout-minutes: 25 env: TAURI_ANDROID_PROJECT_PATH: ${{ github.workspace }}/openless-all/app/src-tauri/gen/android TAURI_ANDROID_PACKAGE_UNESCAPED: com.openless.app @@ -268,6 +304,7 @@ jobs: path: ${{ runner.temp }}/openless-cache/mobile-rime key: mobile-rime-ndk26-x86_64-${{ hashFiles('openless-all/app/scripts/build-mobile-rime.py', 'openless-all/app/mobile-ime/**') }} - name: Build and stage Rime for Android instrumentation tests + timeout-minutes: 20 env: OPENLESS_CACHE_ROOT: ${{ runner.temp }}/openless-cache run: python3 scripts/build-mobile-rime.py android --abi x86_64 --stage @@ -288,6 +325,7 @@ jobs: run: node scripts/patch-android-shizuku-deps.mjs - name: Run JVM credential tests and compile instrumentation tests + timeout-minutes: 15 # These tests are Kotlin-only. The Rust target is checked above; direct Gradle # rustBuild requires the live Tauri CLI RPC server used by `tauri android build`. run: >- @@ -328,6 +366,7 @@ jobs: key: android-emulator-v2-16555280-api35-google_apis-x86_64-${{ runner.os }}-${{ runner.arch }} - name: Prepare the pinned Android emulator and system image + timeout-minutes: 15 env: EMULATOR_CACHE_HIT: ${{ steps.emulator_cache.outputs.cache-hit }} shell: bash @@ -468,6 +507,7 @@ jobs: if: failure() uses: actions/upload-artifact@v4 with: + retention-days: 7 name: android-instrumentation-failure path: ${{ runner.temp }}/openless-android-emulator.log if-no-files-found: ignore @@ -499,6 +539,7 @@ jobs: - name: Cache npm from beta uses: ./.github/actions/cache-npm - run: npm ci + timeout-minutes: 10 - name: Shared IPC audit matches the code # The report is committed so the ArkTS coverage is reviewable; a stale # report hides commands that the Harmony host does not implement yet. @@ -536,6 +577,7 @@ jobs: # cache budget - and `actions/cache` wrote one copy per pull request # scope. Downloading is both cheaper and shorter than restoring it. - name: Build the HAP (compiles ArkTS and the Rust host) + timeout-minutes: 15 env: OPENLESS_HARMONY_CHANNEL: none run: | @@ -590,6 +632,7 @@ jobs: - name: Cache npm from beta uses: ./.github/actions/cache-npm - name: Install frontend dependencies + timeout-minutes: 10 run: npm ci - name: Check Windows prerequisites shell: pwsh @@ -606,6 +649,7 @@ jobs: } } - name: Build frontend + timeout-minutes: 10 run: npm run build - name: Run the platform-sensitive contracts # `process.platform` branches and the `windows-*` contracts only mean @@ -656,7 +700,7 @@ jobs: needs: [changes] # 失败即运行:只有判定脚本明确说“够不到”才跳过。 if: needs.changes.outputs.tauri != 'false' - name: ${{ matrix.label }} checks + name: ${{ matrix.label == 'Windows' && 'Windows stable checks' || 'macOS checks' }} strategy: # One platform failing must not block other platforms from getting verification results. fail-fast: false @@ -694,12 +738,7 @@ jobs: with: python-version: "3.x" - # macOS MSRV is checked in a separate parallel job; Windows keeps the original check order. - # Same rule as the macOS MSRV job: a second toolchain is only worth the - # install + full rebuild while the declared MSRV is behind stable. - - uses: dtolnay/rust-toolchain@1.99.0 - if: runner.os == 'Windows' && needs.changes.outputs.msrv_needed == 'true' - + # Pinned toolchains run in independent MSRV jobs with separate caches. - uses: dtolnay/rust-toolchain@stable - name: Configure macOS check profile @@ -713,7 +752,9 @@ jobs: # workflow restoring the same key can reuse this tree. Keep the two in # sync (scripts/ci-cache-sharing.test.mjs enforces it). shared-key: tauri-windows - workspaces: 'openless-all/app/src-tauri -> target' + workspaces: | + openless-all/app/src-tauri -> target + openless-all/app/src-tauri/backend-tests -> target save-if: ${{ github.ref == 'refs/heads/beta' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }} - name: Cache macOS stable dependencies @@ -738,6 +779,7 @@ jobs: run: ./scripts/prepare-windows-sherpa.ps1 - name: Install frontend dependencies + timeout-minutes: 10 run: npm ci - name: Check PowerShell scripts @@ -754,6 +796,7 @@ jobs: } - name: Build the frontend for the Tauri context + timeout-minutes: 10 # `tauri::generate_context!()` embeds `../dist` at compile time, so the # Rust compile below needs the frontend built even on Windows, where the # contract suite runs in its own job. @@ -761,6 +804,7 @@ jobs: run: npm run build - name: Build frontend and run frontend/contract tests + timeout-minutes: 10 # Windows runs the platform-sensitive subset in its own job: spawning 144 # node processes there costs ~3x the macOS time, and the rest of the suite # is already covered here. The frontend build it needs is the step above. @@ -768,6 +812,7 @@ jobs: run: npm test - name: Install pinned Codex CLI for sandbox contract + timeout-minutes: 5 if: runner.os == 'macOS' run: npm install --global @openai/codex@0.146.0 @@ -781,6 +826,7 @@ jobs: echo "CODEX_HOME=$codex_home" >> "$GITHUB_ENV" - name: Run Codex writable-roots sandbox contract + timeout-minutes: 15 if: runner.os == 'macOS' env: OPENLESS_CODEX_TEST_EXE: codex @@ -790,6 +836,7 @@ jobs: # check misses. Avoids a metadata-only check followed by another codegen pass over the same # dependency graph. - name: Run Rust backend unit tests + timeout-minutes: 30 if: runner.os != 'Windows' run: cargo test --locked --manifest-path src-tauri/Cargo.toml --lib --bins --timings @@ -803,13 +850,13 @@ jobs: # `--bins` keeps the binary coverage that the removed `cargo check` used to # provide: `cargo check` writes metadata, so the following codegen pass # recompiled the whole dependency graph anyway (measured: 6.4 min of it). - run: cargo test --locked --manifest-path src-tauri/Cargo.toml --lib --bins --no-run + run: cargo test --locked --manifest-path src-tauri/Cargo.toml --lib --bins --no-run --timings # Feature-on production cfg must compile too; standalone tests below actually run # the sink on Windows/macOS without optional Tauri runtime DLL entrypoints. - name: Compile opt-in Windows hang diagnostics host timeout-minutes: 25 - run: cargo check --locked --manifest-path src-tauri/Cargo.toml --features issue-1266-diagnostics + run: cargo check --locked --manifest-path src-tauri/Cargo.toml --features issue-1266-diagnostics --timings - name: Run isolated Windows hang diagnostics tests (off/on) timeout-minutes: 10 @@ -849,16 +896,6 @@ jobs: timeout-minutes: 20 run: cargo test --locked --manifest-path src-tauri/vendor/cpal/Cargo.toml --lib --test windows_lifecycle - - name: Check Tauri backend with Rust 1.99 MSRV - if: runner.os == 'Windows' && needs.changes.outputs.msrv_needed == 'true' - timeout-minutes: 30 - run: cargo +1.99.0 check --locked --manifest-path src-tauri/Cargo.toml - - - name: Compile backend tests with Rust 1.99 MSRV - if: runner.os == 'Windows' && needs.changes.outputs.msrv_needed == 'true' - timeout-minutes: 30 - run: cargo +1.99.0 test --locked --manifest-path src-tauri/backend-tests/Cargo.toml --no-run - - name: Build the Windows TSF input method # The TSF DLL has its own vcxproj and is not part of the Tauri build, so # nothing else in CI ever compiles it. A compile error here would @@ -904,6 +941,18 @@ jobs: fi echo "[ok] 全部 5 处版本号一致:$PKG" + - name: Upload Cargo timing evidence + if: always() + timeout-minutes: 5 + uses: actions/upload-artifact@v4 + with: + name: ci-cargo-${{ matrix.label }} + retention-days: 7 + if-no-files-found: ignore + path: | + openless-all/app/src-tauri/target/cargo-timings/*.html + openless-all/app/src-tauri/backend-tests/target/cargo-timings/*.html + macos-msrv: needs: [changes] # Run the declared minimum toolchain even when stable has the same version. @@ -937,8 +986,111 @@ jobs: openless-all/app/src-tauri -> target openless-all/app/src-tauri/backend-tests -> target - run: npm ci + timeout-minutes: 10 - run: npm run build + timeout-minutes: 10 - name: Check Tauri backend with Rust 1.99 MSRV + timeout-minutes: 30 run: cargo +1.99.0 check --locked --manifest-path src-tauri/Cargo.toml --timings - name: Compile backend tests with Rust 1.99 MSRV + timeout-minutes: 20 run: cargo +1.99.0 test --locked --manifest-path src-tauri/backend-tests/Cargo.toml --no-run --timings + + - name: Upload Cargo timing evidence + if: always() + timeout-minutes: 5 + uses: actions/upload-artifact@v4 + with: + name: ci-cargo-macos-msrv + retention-days: 7 + if-no-files-found: ignore + path: | + openless-all/app/src-tauri/target/cargo-timings/*.html + openless-all/app/src-tauri/backend-tests/target/cargo-timings/*.html + + windows-msrv: + # Measured 347–425 seconds when serialised behind Windows stable checks. + # Keep the pinned compiler and its fingerprints out of the stable job. + needs: [changes] + if: (github.event_name != 'workflow_dispatch' || inputs.platform != 'macos') && needs.changes.outputs.msrv != 'false' + name: Windows Rust 1.99 MSRV + runs-on: windows-latest + timeout-minutes: 60 + env: + CARGO_BUILD_JOBS: 2 + CARGO_PROFILE_TEST_DEBUG: 0 + CMAKE_BUILD_PARALLEL_LEVEL: 2 + defaults: + run: + working-directory: openless-all/app + steps: + - uses: actions/checkout@v4 + with: + submodules: false + - uses: actions/setup-node@v4 + with: + node-version: '22' + - name: Cache npm from beta + uses: ./.github/actions/cache-npm + - uses: dtolnay/rust-toolchain@1.99.0 + - uses: swatinem/rust-cache@v2 + with: + shared-key: windows-msrv + save-if: ${{ github.ref == 'refs/heads/beta' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }} + workspaces: | + openless-all/app/src-tauri -> target + openless-all/app/src-tauri/backend-tests -> target + - name: Prepare Windows Sherpa static libraries + timeout-minutes: 15 + shell: pwsh + run: ./scripts/prepare-windows-sherpa.ps1 + - run: npm ci + timeout-minutes: 10 + - run: npm run build + timeout-minutes: 10 + - name: Check Tauri backend with Rust 1.99 MSRV + timeout-minutes: 30 + run: cargo +1.99.0 check --locked --manifest-path src-tauri/Cargo.toml --timings + - name: Compile backend tests with Rust 1.99 MSRV + timeout-minutes: 20 + run: cargo +1.99.0 test --locked --manifest-path src-tauri/backend-tests/Cargo.toml --no-run --timings + + - name: Upload Cargo timing evidence + if: always() + timeout-minutes: 5 + uses: actions/upload-artifact@v4 + with: + name: ci-cargo-windows-msrv + retention-days: 7 + if-no-files-found: ignore + path: | + openless-all/app/src-tauri/target/cargo-timings/*.html + openless-all/app/src-tauri/backend-tests/target/cargo-timings/*.html + + windows-checks: + # Keep the existing Windows required check dependent on both compilers. + name: Windows checks + needs: [changes, cross-platform, windows-msrv] + if: always() && (github.event_name != 'workflow_dispatch' || inputs.platform != 'macos') + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Require stable and MSRV results + env: + CHANGES_RESULT: ${{ needs.changes.result }} + TAURI: ${{ needs.changes.outputs.tauri }} + MSRV: ${{ needs.changes.outputs.msrv }} + STABLE_RESULT: ${{ needs.cross-platform.result }} + MSRV_RESULT: ${{ needs.windows-msrv.result }} + run: | + test "$CHANGES_RESULT" = success + if [ "$TAURI" = false ]; then + test "$STABLE_RESULT" = skipped + else + test "$STABLE_RESULT" = success + fi + if [ "$MSRV" = false ]; then + test "$MSRV_RESULT" = skipped + else + test "$MSRV_RESULT" = success + fi diff --git a/.github/workflows/release-harmony.yml b/.github/workflows/release-harmony.yml index 6b0352f8d..d9101ff6f 100644 --- a/.github/workflows/release-harmony.yml +++ b/.github/workflows/release-harmony.yml @@ -129,6 +129,7 @@ jobs: uses: ./.github/actions/cache-npm - name: Install frontend dependencies + timeout-minutes: 10 working-directory: openless-all/app run: npm ci @@ -282,6 +283,7 @@ jobs: - name: Upload the HAP as a workflow artifact uses: actions/upload-artifact@v4 with: + retention-days: 14 name: openless-harmony-hap # `-signed` stays in the workflow artifacts for the store upload; the # repository never publishes it. diff --git a/.github/workflows/release-tauri.yml b/.github/workflows/release-tauri.yml index 4a1312535..c842b13db 100644 --- a/.github/workflows/release-tauri.yml +++ b/.github/workflows/release-tauri.yml @@ -46,12 +46,13 @@ on: required: false default: '' -# Manual branch builds share a ref group and cancel the older run so duplicate -# DMG builds do not stack. Tag publishes and draft repairs use a unique group +# Equivalent manual branch builds cancel the older run so duplicate DMG builds +# do not stack. Different platform/diagnostic requests stay independent. +# Tag publishes and draft repairs use a unique group # and are not cancelled: cancelling them would abort a release. concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && inputs.release_tag == '' && github.ref || format('{0}-{1}', github.ref, github.run_id) }} - cancel-in-progress: ${{ github.event_name == 'workflow_dispatch' && inputs.release_tag == '' }} + group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/heads/') && inputs.release_tag == '' && format('{0}-{1}-{2}', github.ref, inputs.platform, inputs.windows_hang_diagnostics) || format('{0}-{1}', github.ref, github.run_id) }} + cancel-in-progress: ${{ github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/heads/') && inputs.release_tag == '' }} jobs: build: @@ -117,8 +118,14 @@ jobs: - uses: actions/setup-node@v4 with: node-version: "22" - cache: npm - cache-dependency-path: 'openless-all/app/package-lock.json' + # Repairs check out historical tags that may predate the local action. + # Preserve their existing setup-node cache path instead of requiring + # newer workflow tooling to exist in the immutable tagged source. + cache: ${{ inputs.release_tag != '' && 'npm' || '' }} + cache-dependency-path: openless-all/app/package-lock.json + - name: Cache npm from beta + if: inputs.release_tag == '' + uses: ./.github/actions/cache-npm - name: Verify repair source CI and version if: inputs.release_tag != '' @@ -158,8 +165,9 @@ jobs: shared-key: tauri-windows workspaces: 'openless-all/app/src-tauri -> target' cache-on-failure: true - # Branch dispatches restore this shared tree and must not replace it. - save-if: ${{ github.ref == 'refs/heads/beta' || startsWith(github.ref, 'refs/tags/') }} + # Only beta can warm future tag builds. Per-tag copies cannot be + # restored by the next tag and evict reusable baseline dependencies. + save-if: ${{ github.ref == 'refs/heads/beta' && inputs.release_tag == '' }} - name: Cache macOS release dependencies if: startsWith(matrix.platform, 'macos') @@ -171,10 +179,11 @@ jobs: prefix-key: v0-rust-${{ matrix.rust-target }} shared-key: tauri-macos workspaces: 'openless-all/app/src-tauri -> target' - # Branch dispatches restore this shared tree and must not replace it. - save-if: ${{ github.ref == 'refs/heads/beta' || startsWith(github.ref, 'refs/tags/') }} + # Weekly beta builds maintain this tree; tags only restore it. + save-if: ${{ github.ref == 'refs/heads/beta' && inputs.release_tag == '' }} - name: Prepare Windows Sherpa static libraries + timeout-minutes: 15 if: matrix.platform == 'windows-latest' working-directory: 'openless-all/app' shell: pwsh @@ -288,6 +297,7 @@ jobs: if: always() && startsWith(matrix.platform, 'macos') uses: actions/upload-artifact@v4 with: + retention-days: 7 name: macos-cargo-timings-${{ matrix.updater-arch }} path: openless-all/app/src-tauri/target/cargo-timings/*.html if-no-files-found: ignore @@ -366,7 +376,8 @@ jobs: # and any bundler failure makes *all* bundles skip their .sig. MSI always hits ICE80, # so a single `tauri build` can never produce the NSIS .exe.sig. # Pass 1: NSIS alone — must succeed, producing *_x64-setup.exe(.sig) for the updater. - # Pass 2: MSI alone — allowed to fail; the Repair step re-links with light.exe. + # Pass 2: bundle MSI from the compiled executable; no second tsc/vite/Cargo pass. + # MSI bundling may fail; the Repair step re-links with light.exe. # Beta skips MSI: Windows Installer / WiX cannot represent non-numeric prerelease # identifiers like `1.2.3-Beta.1`; stable still produces MSI as usual. # MSI ProductVersion is numeric and 16-bit bounded. Keep the full app @@ -385,27 +396,29 @@ jobs: msi_config_exit=$? if [ "$msi_config_exit" -ne 0 ]; then exit "$msi_config_exit"; fi if [ -n "${TAURI_SIGNING_PRIVATE_KEY:-}" ]; then - npm run tauri -- build "${diagnostic_args[@]}" --bundles nsis --config '{"bundle":{"createUpdaterArtifacts":true}}' + npm run tauri -- build "${diagnostic_args[@]}" --bundles nsis --config '{"bundle":{"createUpdaterArtifacts":true}}' -- --locked --timings nsis_exit=$? + if [ "$nsis_exit" -ne 0 ]; then exit "$nsis_exit"; fi if [ "${OPENLESS_RELEASE_CHANNEL:-stable}" = "beta" ] || [ "$msi_supported" -eq 0 ]; then echo "OPENLESS_SKIP_WINDOWS_MSI=1" >> "$GITHUB_ENV" echo "[info] Skipping MSI bundle for unsupported prerelease/channel." msi_exit=0 else echo "OPENLESS_SKIP_WINDOWS_MSI=0" >> "$GITHUB_ENV" - npm run tauri -- build "${diagnostic_args[@]}" --bundles msi --config src-tauri/tauri.msi-version.json + npm run tauri -- bundle "${diagnostic_args[@]}" --bundles msi --config src-tauri/tauri.msi-version.json msi_exit=$? fi else - npm run tauri -- build "${diagnostic_args[@]}" --bundles nsis + npm run tauri -- build "${diagnostic_args[@]}" --bundles nsis -- --locked --timings nsis_exit=$? + if [ "$nsis_exit" -ne 0 ]; then exit "$nsis_exit"; fi if [ "${OPENLESS_RELEASE_CHANNEL:-stable}" = "beta" ] || [ "$msi_supported" -eq 0 ]; then echo "OPENLESS_SKIP_WINDOWS_MSI=1" >> "$GITHUB_ENV" echo "[info] Skipping MSI bundle for unsupported prerelease/channel." msi_exit=0 else echo "OPENLESS_SKIP_WINDOWS_MSI=0" >> "$GITHUB_ENV" - npm run tauri -- build "${diagnostic_args[@]}" --bundles msi --config src-tauri/tauri.msi-version.json + npm run tauri -- bundle "${diagnostic_args[@]}" --bundles msi --config src-tauri/tauri.msi-version.json msi_exit=$? fi fi @@ -418,6 +431,16 @@ jobs: # MSI failure does not block — the next Repair step re-links with light.exe (with -sice:ICE80). exit 0 + - name: Upload Windows Cargo timings + if: always() && matrix.platform == 'windows-latest' + timeout-minutes: 5 + uses: actions/upload-artifact@v4 + with: + name: windows-cargo-timings-x64 + retention-days: 7 + path: openless-all/app/src-tauri/target/cargo-timings/*.html + if-no-files-found: ignore + # ── If tauri fails at the wix link stage (candle produced wixobj, but light cannot find # the IME DLL because of cwd-relative wxs Source resolution), manually run light from # appRoot to re-link. Same surgery as the local windows-package-msvc.ps1 @@ -626,6 +649,7 @@ jobs: timeout-minutes: 10 uses: actions/upload-artifact@v4 with: + retention-days: 14 name: openless-download-alias-${{ matrix.updater-target }}-${{ matrix.updater-arch }} compression-level: 0 path: openless-all/app/src-tauri/target/release/downloads/* @@ -635,6 +659,7 @@ jobs: if: startsWith(matrix.platform, 'macos') uses: actions/upload-artifact@v4 with: + retention-days: 14 name: openless-macos-${{ matrix.updater-arch }} compression-level: 0 path: | @@ -645,6 +670,7 @@ jobs: if: startsWith(matrix.platform, 'macos') && env.TAURI_SIGNING_PRIVATE_KEY != '' uses: actions/upload-artifact@v4 with: + retention-days: 14 name: openless-macos-${{ matrix.updater-arch }}-updater compression-level: 0 path: | @@ -692,6 +718,7 @@ jobs: if: matrix.platform == 'windows-latest' uses: actions/upload-artifact@v4 with: + retention-days: 14 name: ${{ env.OPENLESS_HANG_DIAGNOSTICS == 'true' && 'openless-windows-x64-issue-1266-diagnostics' || 'openless-windows-x64' }} path: | openless-all/app/src-tauri/target/release/bundle/nsis/*.exe @@ -706,6 +733,7 @@ jobs: if: matrix.platform == 'windows-latest' && env.TAURI_SIGNING_PRIVATE_KEY != '' uses: actions/upload-artifact@v4 with: + retention-days: 14 name: openless-windows-x64-updater path: | openless-all/app/src-tauri/target/release/bundle/nsis/*.exe.sig diff --git a/docs/ci-trigger-and-cache-policy.md b/docs/ci-trigger-and-cache-policy.md index 544447d98..335ac64c2 100644 --- a/docs/ci-trigger-and-cache-policy.md +++ b/docs/ci-trigger-and-cache-policy.md @@ -1,18 +1,18 @@ # CI 触发范围与缓存配额 -状态:canonical;更新:2026-09-29。本文说明 CI 为什么在什么情况下跑哪些 job、缓存在 10 GB 预算内怎么分配,以及发版前怎么把耗时压下来。 +状态:canonical;更新:2026-11-08。本文说明 CI 为什么在什么情况下跑哪些 job、缓存在 10 GB 预算内怎么分配,以及发版前怎么把耗时压下来。 ## 1. 触发与门控 | 事件 | 行为 | |---|---| | `pull_request` → `main` / `beta` | 按改动范围门控:改动够不到的平台直接跳过(见下) | -| `push` → `main` / `beta` | 全量验证(合并后的基线必须有完整证据),不跳过任何 job;也是 Rust / Playwright 缓存的唯一写入方 | +| `push` → `main` / `beta` | 全量验证(合并后的基线必须有完整证据),不跳过任何 job;仅 beta 写入共享缓存,beta 手动/周期构建也可预热 | | `push` → 其他分支 | **不跑**。feature 分支由它的 PR 覆盖;两边都跑等于同一个 commit 交两遍完整矩阵(实测 42 次 run 里有 8 次是这种重复,每次 ~86 VM-min、峰值 12 台 VM) | | tag `v*-tauri` | 发布 Tauri 桌面与 Android;Linux 包不随标签自动发布 | | `workflow_dispatch` | 全量;`platform=macos` 只跑 macOS(仅 macOS 验证入口) | -同一 PR 连续推送会取消旧运行(`concurrency.cancel-in-progress`)。 +同一 PR 连续推送会取消旧运行(`concurrency.cancel-in-progress`)。CI 的相同 ref、platform、macos_runner 手动请求也会取消旧运行,不同参数独立运行。桌面手动构建按 ref、platform、诊断开关区分;Android 按 ref、ABI、profile、签名模式区分。标签发布(包括手动选择标签)和修复发布不会被新运行中途取消。 ### 改动范围判定 @@ -24,7 +24,7 @@ Rust 部分不靠手写路径表,而是走 Cargo 自己的包图:`cargo meta |---|---|---| | `tauri` | macOS / Windows 桌面检查 | 改动能到达 `openless`(含 vendor 路径依赖)或桌面专属的 `openless-native-capsule` | | `android` | Android cargo check | 改动能到达 `openless` 的 Android 闭包,或影响 Android 项目生成/构建的 npm manifest;纯 bundle-only 改动不单独触发 | -| `msrv` | macOS Rust 1.99 MSRV | 有任何 `.rs` / `Cargo.toml` / `Cargo.lock` / `rust-toolchain*` / `.github/**` | +| `msrv` | macOS / Windows Rust 1.99 MSRV | 有任何 `.rs` / `Cargo.toml` / `Cargo.lock` / `rust-toolchain*` / `.github/**` | | `linux` | Linux Core/egui 测试与 deb/rpm 打包链 | 改动能到达 `openless-linux-egui` 的闭包。Linux 宿主是原生 egui,不读前端 `dist/` | | `harmony` | 鸿蒙 ArkTS 契约、Rust host、HAP | 改动能到达 `openless-harmony-host` 的闭包,或动了它要打包的前端 bundle | | `frontend` | Chromium/WebKit UI 动效 | 只动浏览器会渲染的面:`src/**`、`e2e/**`、样式与 vite/playwright 配置;`app/assets/**` / `app/public/**` 按 native consumer 处理 | @@ -42,7 +42,7 @@ Rust 部分不靠手写路径表,而是走 Cargo 自己的包图:`cargo meta - `openless-core`、`src-tauri`、`src-tauri/backend-tests`、`linux-egui` 统一声明 `rust-version = "1.99"`,README 对外承诺该版本,因此必须有 CI 用真的 1.99 编译:MSRV 只会被“依赖升级抬高要求”或“自己用了更新的语言特性/API”打破,两者都只有在 1.99 下编译才会暴露。 该数字由依赖实际要求决定:`tauri 2.12` 要 1.90、`aes 0.9.3`/`uuid 1.28` 要 1.89,代码库选择跟随当前 stable(1.99)以保持单一数字,不再为旧工具链回退依赖。 - 工具链不同 ⇒ cargo fingerprint 全失效、产物与缓存不能共用。历史上 stable 与 MSRV 挤在同一个 job 里共用缓存,串行 29 分 59 秒(见 [`macos-build-performance.md`](macos-build-performance.md));拆成并行独立 job、缓存分开后是 stable 8m36s / MSRV 3m39s。 -- 平台专属依赖图不同,所以 macOS 与 Windows 各自验证:macOS 是 `keyring/apple-native`、MLX/qwen-asr;Windows 是 `keyring/windows-native`、TSF IME。 +- 平台专属依赖图不同,所以 macOS 与 Windows 各自验证:macOS 是 `keyring/apple-native`;Windows 是 `keyring/windows-native`、TSF IME。Windows MSRV 也在独立 job 中运行,避免 stable → MSRV 串行重编译和污染 stable 缓存。`Windows checks` 汇总两路结果,任一路失败、取消或意外跳过都会失败。 - Linux 宿主 `linux-egui` 与桌面侧同用 `rust-version = "1.99"`(egui 0.37 本身只要求 1.95),Linux 侧按 stable 验证。 ## 3. 缓存配额分配(10 GB / 仓库) @@ -55,7 +55,7 @@ GitHub 每仓库保留 10 GB 缓存,超出按 LRU 静默淘汰;淘汰后 job |---|---|---|---| | macOS stable | 0.87 GB | −11.4 min | 786 s/GB | | Linux egui | 0.75 GB(+ 旧前缀 1.28 GB 待回收) | −10.8 min | 864 s/GB | -| macOS Rust 1.99 MSRV | 0.72 GB | −13.1 min | 1102 s/GB(与 stable 同号时整个 job 跳过,见 §2) | +| macOS Rust 1.99 MSRV | 0.72 GB | −13.1 min | 1102 s/GB(即使 stable 同号也运行 pinned compiler,见 §2) | | Android | 0.85 GB | −2.4 min | 169 s/GB | | Windows | 1.57 GB | −4.6 min | 176 s/GB | | Harmony Rust host | 0.28 GB | −2–4 min | ~600 s/GB | @@ -64,27 +64,30 @@ GitHub 每仓库保留 10 GB 缓存,超出按 LRU 静默淘汰;淘汰后 job **不缓存鸿蒙命令行工具链**:解压后 7.1 GB,缓存条目 1.77 GB,而下载 2.1 GB 只要 ~18 s(108 MB/s)、解压 ~70 s。恢复缓存本身就要几十秒,还要占掉 18% 的配额,性价比为负。`prepare-harmony-sdk.sh` 按 SHA-256 固定校验和,每次重下反而是更可靠的选择。 -分配原则:**按平台配额 + 只有基线分支/tag/迭代中的 job 允许写。** +分配原则:**按平台配额,仅基线分支的 CI / 手动 / 周期构建写入共享缓存,PR 与 tag 只读。** | 归属 | 目标 | 谁写 | 谁读 | |---|---|---|---| -| Windows 依赖树 | ~1.6 GB | `push`(beta)、tag | 所有 PR、发版 | +| Windows 依赖树 | ~1.6 GB | beta 的 CI / 手动构建 / 周期构建 | 所有 PR、发版 | | macOS(stable 0.87 + MSRV 0.72) | ~1.6 GB | 同上 | 同上 | -| Linux(egui 0.75 + core) | ~1.7 GB | `push`、tag,**以及 PR 里的 `build-linux-egui`** | 同上 | -| Android(Rust 0.85 + Rime 0.40 + gradle 0.31) | ~1.6 GB | `push`、tag | PR | -| Harmony Rust host | 0.28 GB | `push`、tag | PR | -| Playwright 浏览器 | 0.37 GB | `push`、tag | PR | +| Linux(egui 0.75 + core) | ~1.7 GB | beta `push` / 手动运行 | 同上 | +| Android(Rust 0.85 + Rime 0.40 + gradle 0.31) | ~1.6 GB | beta 的 CI / 手动构建 / 周期构建 | PR、发版 | +| Harmony Rust host | 0.28 GB | beta `push` / 手动运行 | PR、发版 | +| Playwright 浏览器 | 0.37 GB | beta `push` / 手动运行 | PR | | 鸿蒙工具链 | **0(不缓存)** | — | — | -| 发版(tag 作用域) | ~1.0 GB | tag / 发版前预热 | — | +| 发版(tag 作用域) | 不再新增 | — | tag(从 beta 恢复) | | 余量 | ≥1.5 GB | — | — | 对应的机制: - 重量级 job 用 `save-if: ${{ github.ref == 'refs/heads/beta' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }}`:PR 只从基线分支恢复,不再各自复制一份 1.6 GB 依赖树(此前两个 PR 就占了 10.87 GB,把基线缓存挤掉)。 - **禁止 `uses: actions/cache@v4`**:它会在每次运行时自动保存,包括 `refs/pull//merge` 这种此后再也不会被恢复的作用域。鸿蒙工具链(1.77 GB)和 Rime NDK(0.40 GB)都这样泄漏过——两个 PR 推送就能把 beta 的依赖树挤掉。规则统一成 `actions/cache/restore@v4` 无条件恢复 + 独立的 `actions/cache/save@v4` 且 `if:` 限定 beta。 -- `playwright` 与 `mobile-rime` 使用 restore/save 拆分;`swatinem/rust-cache` 用 `save-if` 达到同样效果。 -- `build-linux-egui` 保留 PR 内自写并开 `cache-on-failure: true`:失败的运行也会把依赖缓存存下来,下一次迭代仍然热;同时关掉 dev/test debug info,缓存更小、链接更快。 +- `playwright` 与 `mobile-rime` 使用 restore/save 拆分;`swatinem/rust-cache` 用 `save-if` 达到同样效果。Playwright 按引擎与版本分键,每个 runner 只下载、恢复自己的浏览器;新键首次使用需要冷下载。 +- npm 复合 action 内允许 beta 门控的 `actions/cache@v4`,其他 ref 只用 `cache/restore`;周期构建也可以维护 beta 下载缓存。 +- 历史标签修复入口是兼容例外:标签可能早于 npm 复合 action,继续使用原有 `setup-node` npm 缓存;常规 tag 发布使用只读复合 action。 +- Linux 测试与打包各自使用独立缓存,PR 只读、beta 写入;dev/test 关闭 debug info。Windows MSRV 新增独立缓存族,实际体积需在 beta 首次写入后由维护作业重新核算,不能把上表历史余量视为保证。 - key 结构为 `v0-rust---<环境哈希>-`:环境哈希含工具链与 `CARGO_PROFILE_*`,所以 stable / MSRV / release 天然分开,不要用跨平台 `shared-key` 混合。 +- 相同 `shared-key` 只是必要条件:恢复仍要求工具链/环境哈希和缓存路径版本兼容。CI 的 dev/test 缓存不能保证让 release 热启动,发布配置依赖 beta 的周期构建预热;不能把共同前缀当作已命中的证据。 - 原生胶囊(`native-capsule` job)原本是一个 `pull_request`-only workflow:缓存写在 `refs/pull//merge`,这个作用域此后再不会被恢复,而 beta 上没有 job 产出同 key 的树,所以 PR 永远冷编译。现在它在 `ci.yml` 里,用 `shared-key: native-capsule` + beta 门控的 `save-if`,并且由 `capsule` 区域门控——常见 PR 完全不会为它拉起 runner。 曾试过把它并进 `cross-platform`(省两台 VM),实测否决:run 40510306688 里那三个命令在 Windows 关键路径上花了 43+53+21 s,比它省下的两台 runner 更贵。要合并先要确认那套 `ui,host` feature 在桌面 job 的缓存里是热的。 - `Cargo.lock` 变化时精确键失效,但 `restore-keys` 前缀回退会拿到同前缀的旧缓存,所以“锁变了”不等于“全冷”——前提是那份没被淘汰,这正是要守预算的原因。 @@ -115,7 +118,7 @@ GitHub 每仓库保留 10 GB 缓存,超出按 LRU 静默淘汰;淘汰后 job `Release Tauri (cross-platform)` 的基线是 ~32.7 分钟,关键路径是 macOS Intel 构建。原因是 tag 运行只能读默认分支(`beta`)的缓存,而基线分支跑的是 debug/test profile,不产生 `macos-release-v1` 前缀的 release 缓存,因此每个新 tag 都要从零编译 release 依赖。 -**发版前先预热**:把一个 `Release Tauri (cross-platform)` 运行 dispatch 到普通分支(上游历史上就在 `perf/macos-ci-build` 这样做过,单次 11–19 分钟),预热完成后再打 tag,可把发版压到 ~10 分钟量级。 +**发版前预热必须在默认分支 `beta` 上执行**:其他分支的缓存不能被未来的 tag 恢复。桌面每周 schedule 在 beta 维护 release 缓存;手动预热也选择 beta。Android 周期构建默认只维护 aarch64;需要全部 release ABI 时在 beta 手动选择 `abis=all`。Tag 和其他分支只读 Rust/Gradle/npm 缓存,避免一次性副本挤掉可复用的基线。缓存命中仍需编译应用本身,不承诺固定发版时长。 Linux 发版不受影响:`release-linux-egui.yml` 复用 CI 的同一个 `build-linux-egui` job(同名同 key),tag 运行能恢复基线分支的缓存。 @@ -124,3 +127,28 @@ Linux 发版不受影响:`release-linux-egui.yml` 复用 CI 的同一个 `buil - 改动范围门控只跳过“够不到”的平台;`push` 到 `main`/`beta` 始终全量,所以合并后仍有完整证据。 - `build-linux-egui` 在 `push` 时仍会构建 release 二进制(保持基线缓存里有 release 产物、并持续验证打包链),但不再上传 Action artifact;artifact 只在 PR 与 tag 运行产生。 - 所有 job 都设了 `timeout-minutes`,避免卡死的运行长时间占用并发与时间。 + + +## 8. 2026-11-08 检查与优化依据 + +基线:`c002b56c38d81bcd5044ddb22597a4e78ff2a88d`。以下是历史运行证据,不是本次修改后的远端性能结果: + +| 证据 | 观察 | 对应调整 | +|---|---|---| +| [CI 42485909147](https://github.com/Open-Less/openless/actions/runs/42485909147) | 浏览器串行执行 923 秒;整轮约 16.9 分钟 | Chromium / WebKit 两个 runner、各 1 worker,保留原 `UI motion (Chromium + WebKit)` 汇总检查 | +| [CI 42402206738](https://github.com/Open-Less/openless/actions/runs/42402206738) | Windows 1518 秒,其中 MSRV 两步 274 + 151 秒 | MSRV 并行独立缓存;stable 与 MSRV 均为必需结果 | +| [CI 42445115251](https://github.com/Open-Less/openless/actions/runs/42445115251) | Windows MSRV 两步 225 + 122 秒;浏览器分拆在该分支已有运行证据 | 不扩大平台/架构集合,仅拆开现有串行工作;保留两浏览器的失败证据 | +| [桌面构建 42073710377](https://github.com/Open-Less/openless/actions/runs/42073710377) | Intel macOS 构建 2078 秒、Windows 1092 秒 | 不降低 release 优化级别;Windows NSIS 编译后,MSI 使用 `tauri bundle`,复用同一二进制 | +| [macOS 构建 42263206938](https://github.com/Open-Less/openless/actions/runs/42263206938) | Rust 日志 `No cache found.`,编译约 14m52s | 限制一次性 tag 缓存写入,保留 beta 的周期预热 | + +超时证据:本次查询 `actions/runs?status=timed_out&per_page=10` 返回 0 条,不能据此认定历史故障都是超时。现有 Android APK 三个 job 未设上限,现补为计划 10 分钟、构建 90 分钟、发布 30 分钟;APK 构建步骤 70 分钟。浏览器单引擎步骤 20 分钟、job 40 分钟;下载、编译和测试等主要阶段各设步骤上限。这些是包含冷启动余量的防挂起边界,不是性能目标。前端脚本每文件最多 120 秒,打印文件名、耗时,超时返回 124;TypeScript 使用 `node --import tsx` 直接执行,减少启动进程,并避免超时只杀掉 tsx CLI 而留下测试子进程。Cargo `--timings` 与 Actions 步骤日志用于后续调整;进程被强杀时不保证生成完整 Cargo HTML。 + +npm 下载缓存使用锁文件精确键,缺失时按 OS/架构前缀恢复已有 tarball;仍执行 `npm ci` 校验锁文件和完整性。CI 优先使用本地下载缓存,并限制请求超时/重试。`node_modules` 不缓存。本仓库使用 npm 锁文件,没有新增 pnpm 流程。TypeScript 增量信息写入忽略的 `node_modules/.cache/tsc`,每次 Vite 仍重新打包。 + +本地复测:Linux、Node 24.22.1(远端 CI 仍使用 Node 22),三次均按 `npm run prebuild` → `tsc` → `vite build` 执行。关闭增量时 26.64 秒;删除增量信息后首次构建 27.75 秒;重复构建 13.96 秒,比非增量约少 48%。三次输出的全部 73 个文件 SHA-256 一致。收益针对重复构建,首次构建没有提速;该样本不代表 macOS/Windows 原生构建或 GitHub 整轮 CI 的加速比。 + +浏览器失败日志与 Cargo timings 保留 7 天;安装包和发布中转 Actions artifacts 保留 14 天。GitHub Release 已发布附件不受此期限影响。Android 相同 ref/ABI/profile/signing 的手动运行取消旧任务,tag 发布不被新运行中途取消。既有 PR 门控、完整平台集合与文档变更策略不变。 + +矩阵取舍:浏览器由一个串行 job 拆成两路,Windows MSRV 由 stable job 拆出,再增加两条轻量汇总检查以保留原必需检查名。单次全量 CI 的 runner 数会增加,目标是缩短关键路径;没有增加浏览器、平台或架构组合。实际墙钟收益仍受 GitHub runner 排队、冷缓存与新增缓存体积影响,需要合并后的同类运行对照,不能把各步骤节省相加作为整轮加速比。 + +本地验证:`npm test` 完成构建和全部 166 个测试文件;修改的工作流通过 actionlint;两种浏览器分别 `playwright test --list --project=…`,各发现 116 个测试。新增行为用例覆盖必需检查的失败/取消/跳过、挂起的 JS/TS 子进程、NSIS 失败中止和 MSI 二次打包。Windows 安装器实际打包、macOS 签名与 GitHub 多平台耗时仍需远端验证。 diff --git a/openless-all/app/scripts/ci-changed-areas.test.mjs b/openless-all/app/scripts/ci-changed-areas.test.mjs index 176f16461..f6e57e09c 100644 --- a/openless-all/app/scripts/ci-changed-areas.test.mjs +++ b/openless-all/app/scripts/ci-changed-areas.test.mjs @@ -288,15 +288,12 @@ check( workflow.includes("if: needs.changes.outputs.msrv != 'false' &&"), false, ); +// Windows runs the same pinned checks in parallel, with its own target cache. check( - 'changes job publishes the native-source gate for pinned toolchains', - workflow.includes('msrv_needed: ${{ steps.detect.outputs.msrv }}'), - true, -); -// The secondary platform uses the same native-source gate. -check( - 'windows msrv steps follow the source gate', - workflow.includes("if: runner.os == 'Windows' && needs.changes.outputs.msrv_needed == 'true'"), + 'windows msrv job follows the source gate', + /windows-msrv:[\s\S]*?inputs\.platform != 'macos'\) && needs\.changes\.outputs\.msrv != 'false'/.test( + workflow, + ), true, ); // `cargo check` immediately followed by `cargo test --no-run` compiles the graph diff --git a/openless-all/app/scripts/ci-performance.test.mjs b/openless-all/app/scripts/ci-performance.test.mjs new file mode 100644 index 000000000..34643a910 --- /dev/null +++ b/openless-all/app/scripts/ci-performance.test.mjs @@ -0,0 +1,159 @@ +import assert from 'node:assert/strict'; +import { spawnSync } from 'node:child_process'; +import { chmodSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { load } from 'js-yaml'; + +const workflow = (name) => + load(readFileSync(new URL(`../../../.github/workflows/${name}`, import.meta.url), 'utf8')); +const ci = workflow('ci.yml'); +const desktop = workflow('release-tauri.yml'); +const browserGate = ci.jobs['ui-motion'].steps[0].run; +const windowsGate = ci.jobs['windows-checks'].steps[0].run; +const runGate = (script, env) => + spawnSync('bash', ['-e', '-c', script], { + env: { ...process.env, ...env }, + encoding: 'utf8', + timeout: 5000, + }).status; + +// Exercise the actual shell gates: failure, cancellation and unexpected skips +// must not turn an existing required check green after parallelising its work. +for (const outcome of ['success', 'failure', 'cancelled', 'skipped']) { + assert.equal( + runGate(browserGate, { + CHANGES_RESULT: 'success', + FRONTEND: 'true', + MACOS_ONLY: 'false', + BROWSERS_RESULT: outcome, + }), + outcome === 'success' ? 0 : 1, + `browser gate: ${outcome}`, + ); + for (const compiler of ['STABLE_RESULT', 'MSRV_RESULT']) { + assert.equal( + runGate(windowsGate, { + CHANGES_RESULT: 'success', + TAURI: 'true', + MSRV: 'true', + STABLE_RESULT: 'success', + MSRV_RESULT: 'success', + [compiler]: outcome, + }), + outcome === 'success' ? 0 : 1, + `${compiler}: ${outcome}`, + ); + } +} +assert.equal( + runGate(browserGate, { + CHANGES_RESULT: 'success', + FRONTEND: 'false', + MACOS_ONLY: 'false', + BROWSERS_RESULT: 'skipped', + }), + 0, +); +assert.equal( + runGate(browserGate, { + CHANGES_RESULT: 'failure', + FRONTEND: '', + MACOS_ONLY: 'false', + BROWSERS_RESULT: 'skipped', + }), + 1, +); +assert.equal( + runGate(windowsGate, { + CHANGES_RESULT: 'success', + TAURI: 'false', + MSRV: 'false', + STABLE_RESULT: 'skipped', + MSRV_RESULT: 'skipped', + }), + 0, +); +assert.equal( + runGate(windowsGate, { + CHANGES_RESULT: 'success', + TAURI: 'false', + MSRV: 'true', + STABLE_RESULT: 'skipped', + MSRV_RESULT: 'success', + }), + 0, +); + +// Run the real Windows build shell with only npm stubbed. Check artifact-flow +// decisions, not the spelling of the commands: one compile, optional rebundle, +// and no MSI attempt after a failed NSIS build. +const buildWindows = desktop.jobs.build.steps.find((s) => s.name === 'Build (Windows)').run; +const scratch = mkdtempSync(join(tmpdir(), 'openless-installer-flow-')); +const shellPath = (value) => + process.platform === 'win32' + ? value.replaceAll('\\', '/').replace(/^([a-z]):/i, (_, drive) => '/' + drive.toLowerCase()) + : value; +try { + mkdirSync(join(scratch, 'src-tauri')); + mkdirSync(join(scratch, 'bin')); + const npm = join(scratch, 'bin/npm'); + writeFileSync( + npm, + `#!/usr/bin/env bash +printf '%s\\n' "$*" >> "$NPM_CALLS" +case "$*" in + *'-- build '*) exit "\${NSIS_EXIT:-0}" ;; + *'-- bundle '*) exit "\${MSI_EXIT:-0}" ;; + *) exit 99 ;; +esac +`, + ); + chmodSync(npm, 0o755); + for (const [name, version, channel, signed, nsis, msi, expectedCalls, expectedExit] of [ + ['stable-signed', '2.0.2', 'stable', true, 0, 0, 2, 0], + ['stable-unsigned', '2.0.2+build.123', 'stable', false, 0, 0, 2, 0], + ['beta-channel', '2.0.2', 'beta', true, 0, 0, 1, 0], + ['beta-version', '2.0.2-Beta.4', 'stable', false, 0, 0, 1, 0], + ['nsis-failure', '2.0.2', 'stable', true, 23, 0, 1, 23], + ['msi-repair', '2.0.2', 'stable', true, 0, 17, 2, 0], + ]) { + writeFileSync(join(scratch, 'src-tauri/tauri.conf.json'), JSON.stringify({ version })); + const callsPath = join(scratch, `${name}.calls`); + const envPath = join(scratch, `${name}.env`); + const result = spawnSync('bash', ['-c', 'export PATH="$TEST_BIN:$PATH"\n' + buildWindows], { + cwd: scratch, + encoding: 'utf8', + timeout: 10000, + env: { + ...process.env, + TEST_BIN: shellPath(join(scratch, 'bin')), + NPM_CALLS: shellPath(callsPath), + GITHUB_ENV: shellPath(envPath), + TAURI_SIGNING_PRIVATE_KEY: signed ? 'fixture' : '', + OPENLESS_HANG_DIAGNOSTICS: 'true', + OPENLESS_RELEASE_CHANNEL: channel, + NSIS_EXIT: String(nsis), + MSI_EXIT: String(msi), + }, + }); + assert.ifError(result.error); + assert.equal(result.status, expectedExit, name + ': ' + result.stdout + result.stderr); + const calls = readFileSync(callsPath, 'utf8').trim().split('\n'); + assert.equal(calls.length, expectedCalls, name); + assert.match(calls[0], /-- build --features issue-1266-diagnostics --bundles nsis/); + assert.match(calls[0], /-- --locked --timings$/); + if (expectedCalls === 2) { + assert.match(calls[1], /-- bundle --features issue-1266-diagnostics --bundles msi/); + assert.equal( + JSON.parse(readFileSync(join(scratch, 'src-tauri/tauri.msi-version.json'))).bundle.windows + .wix.version, + '2.0.2.0', + ); + assert.match(readFileSync(envPath, 'utf8'), new RegExp(`TAURI_BUILD_EXIT=${msi}`)); + } + } +} finally { + rmSync(scratch, { recursive: true, force: true }); +} +console.log('CI gates and Windows installer reuse/failure propagation passed'); diff --git a/openless-all/app/scripts/frontend-test-runner.mjs b/openless-all/app/scripts/frontend-test-runner.mjs index bce8a86f7..1ab9023ff 100644 --- a/openless-all/app/scripts/frontend-test-runner.mjs +++ b/openless-all/app/scripts/frontend-test-runner.mjs @@ -34,16 +34,24 @@ export function discoverTestFiles(appRoot = DEFAULT_APP_ROOT) { export function runTestFiles( testFiles, - { appRoot = DEFAULT_APP_ROOT, log = console.log, spawn = spawnSync, tsxCli } = {}, + { + appRoot = DEFAULT_APP_ROOT, + log = console.log, + spawn = spawnSync, + tsxImport, + timeout = 120_000, + } = {}, ) { - let resolvedTsxCli = tsxCli; + let resolvedTsxImport = tsxImport; for (const testFile of testFiles) { const absoluteTestFile = resolve(appRoot, testFile); let args; if (testFile.endsWith('.test.ts')) { - resolvedTsxCli ??= fileURLToPath(import.meta.resolve('tsx/cli')); - args = [resolvedTsxCli, absoluteTestFile]; + // Load TypeScript in the child itself. The tsx CLI spawns another Node + // process, adding startup cost and leaving it alive if the CLI times out. + resolvedTsxImport ??= import.meta.resolve('tsx'); + args = ['--import', resolvedTsxImport, absoluteTestFile]; } else if (testFile.endsWith('.mjs')) { args = [absoluteTestFile]; } else { @@ -52,12 +60,20 @@ export function runTestFiles( } log(`[frontend-tests] ${testFile}`); + const started = performance.now(); const result = spawn(process.execPath, args, { cwd: appRoot, env: process.env, stdio: 'inherit', + timeout, + killSignal: 'SIGKILL', }); + log(`[frontend-tests] ${testFile}: ${((performance.now() - started) / 1000).toFixed(1)}s`); if (result.error) { + if (result.error.code === 'ETIMEDOUT') { + log(`[frontend-tests] timed out after ${timeout}ms: ${testFile}`); + return 124; + } log(`[frontend-tests] failed to start ${testFile}: ${result.error.message}`); return 1; } diff --git a/openless-all/app/scripts/frontend-test-runner.test.mjs b/openless-all/app/scripts/frontend-test-runner.test.mjs index 577ad6d8d..b7a3a18d6 100644 --- a/openless-all/app/scripts/frontend-test-runner.test.mjs +++ b/openless-all/app/scripts/frontend-test-runner.test.mjs @@ -1,6 +1,8 @@ import assert from 'node:assert/strict'; import { resolve } from 'node:path'; import process from 'node:process'; +import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; import { discoverTestFiles, runTestFiles } from './frontend-test-runner.mjs'; @@ -34,19 +36,62 @@ const exitCode = runTestFiles( invocations.push({ command, args, options }); return { status: statuses[invocations.length - 1] }; }, - tsxCli: '/tools/tsx-cli.mjs', + tsxImport: 'file:///tools/tsx-loader.mjs', }, ); assert.equal(exitCode, 7, 'the aggregate runner must propagate a failing child status'); assert.equal(invocations.length, 2, 'the aggregate runner must stop after the first failure'); assert.deepEqual(invocations[0].args, [ - '/tools/tsx-cli.mjs', + '--import', + 'file:///tools/tsx-loader.mjs', resolve('/app', 'src/lib/passes.test.ts'), ]); assert.deepEqual(invocations[1].args, [resolve('/app', 'scripts/fails.test.mjs')]); assert.equal(invocations[0].command, process.execPath); assert.equal(invocations[1].command, process.execPath); assert.equal(invocations[0].options.stdio, 'inherit'); +assert.equal(invocations[0].options.timeout, 120_000); + +// Exercise a real child that never exits, including one that ignores SIGTERM. +const scratch = mkdtempSync(resolve(tmpdir(), 'openless-test-timeout-')); +try { + writeFileSync( + resolve(scratch, 'hang.mjs'), + "process.on('SIGTERM', () => {}); setInterval(() => {}, 1000);", + ); + const messages = []; + const started = performance.now(); + assert.equal( + runTestFiles(['hang.mjs'], { + appRoot: scratch, + timeout: 250, + log: (message) => messages.push(message), + }), + 124, + ); + assert.ok(performance.now() - started < 5000, 'a hung test must not hold the suite'); + assert.ok(messages.some((message) => /timed out after 250ms: hang.mjs/.test(message))); + + // A TypeScript child must also be killed, rather than orphaned behind the + // tsx CLI. A delayed write would expose a still-running grandchild. + const marker = resolve(scratch, 'orphan.txt'); + writeFileSync( + resolve(scratch, 'hang.test.ts'), + `import { writeFileSync } from 'node:fs'; +const marker: string = ${JSON.stringify(marker)}; +process.on('SIGTERM', () => {}); +setTimeout(() => writeFileSync(marker, 'orphan'), 2500); +setInterval(() => {}, 1000);`, + ); + assert.equal( + runTestFiles(['hang.test.ts'], { appRoot: scratch, timeout: 1500, log: () => {} }), + 124, + ); + await new Promise((done) => setTimeout(done, 3000)); + assert.equal(existsSync(marker), false, 'timing out must terminate the TypeScript test'); +} finally { + rmSync(scratch, { recursive: true, force: true }); +} console.log('frontend-test-runner.test.mjs passed'); diff --git a/openless-all/app/scripts/windows-hang-diagnostics-contract.test.mjs b/openless-all/app/scripts/windows-hang-diagnostics-contract.test.mjs index 6db8f47ef..d65265889 100644 --- a/openless-all/app/scripts/windows-hang-diagnostics-contract.test.mjs +++ b/openless-all/app/scripts/windows-hang-diagnostics-contract.test.mjs @@ -171,7 +171,10 @@ for (const fragment of [ assert.ok(gate.includes(fragment)); const build = steps.find((step) => step.name === 'Build (Windows)').run; assert.match(build, /diagnostic_args=\(--features issue-1266-diagnostics\)/); -assert.equal((build.match(/build "\$\{diagnostic_args\[@\]\}" --bundles/g) ?? []).length, 4); +// Signed and unsigned paths compile NSIS once, then reuse that executable for +// MSI. Both commands must retain the same diagnostics feature selection. +assert.equal((build.match(/build "\$\{diagnostic_args\[@\]\}" --bundles nsis/g) ?? []).length, 2); +assert.equal((build.match(/bundle "\$\{diagnostic_args\[@\]\}" --bundles msi/g) ?? []).length, 2); const verify = steps.find((step) => step.name === 'Verify Windows diagnostic symbols'); assert.match(verify.run, /windows-symbol-pair\.py/); const symbolTooling = steps.find((step) => step.name === 'Fetch symbol-pair verification tooling'); diff --git a/openless-all/app/scripts/windows-msi-release-contract.test.mjs b/openless-all/app/scripts/windows-msi-release-contract.test.mjs index 8d6a7a8ea..ed31307c7 100644 --- a/openless-all/app/scripts/windows-msi-release-contract.test.mjs +++ b/openless-all/app/scripts/windows-msi-release-contract.test.mjs @@ -35,6 +35,15 @@ assert.match( ); const checkout = steps.find((s) => s.uses === 'actions/checkout@v4'); assert.equal(checkout.with.ref, '${{ inputs.release_tag || github.sha }}'); +// Historical repair tags need not contain the newer repository-local action. +assert.equal( + steps.find((s) => s.uses === './.github/actions/cache-npm').if, + "inputs.release_tag == ''", +); +assert.equal( + steps.find((s) => s.uses === 'actions/setup-node@v4').with.cache, + "${{ inputs.release_tag != '' && 'npm' || '' }}", +); const guard = steps.find((s) => s.name === 'Validate targeted draft release repair'); assert.equal(guard.if, "inputs.release_tag != ''"); assert.match(guard.run, /permission.*admin/); @@ -80,7 +89,7 @@ for (const version of ['256.0.0', '1.256.0', '1.0.65536', 'invalid']) assert.equal( ( build.run.match( - /build "\$\{diagnostic_args\[@\]\}" --bundles msi --config src-tauri\/tauri.msi-version.json/g, + /bundle "\$\{diagnostic_args\[@\]\}" --bundles msi --config src-tauri\/tauri.msi-version.json/g, ) ?? [] ).length, 2, diff --git a/openless-all/app/scripts/workflow-concurrency-contract.test.mjs b/openless-all/app/scripts/workflow-concurrency-contract.test.mjs index 37ca2086b..ea96ac047 100644 --- a/openless-all/app/scripts/workflow-concurrency-contract.test.mjs +++ b/openless-all/app/scripts/workflow-concurrency-contract.test.mjs @@ -13,27 +13,29 @@ const workflows = { ), }; -const isolatedManualGroup = - "group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && github.run_id || github.ref }}"; const cancelSupersededTagPush = "cancel-in-progress: ${{ github.event_name == 'push' }}"; assert.ok( - workflows.android.includes(isolatedManualGroup), - 'Android release must isolate manual runs while grouping repeated pushes of the same tag', + workflows.android.includes( + "group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}-${{ inputs.abis || 'aarch64' }}-${{ inputs.fast_profile || false }}-${{ inputs.signed_debug || false }}", + ), + 'Android must group equivalent manual requests without mixing ABI, profile or signing modes', ); assert.ok( - workflows.android.includes(cancelSupersededTagPush), - 'Android release must cancel an older run when the same tag is pushed again', + workflows.android.includes( + "cancel-in-progress: ${{ github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/heads/') }}", + ), + 'Android may supersede manual branch builds, but never tag publishing (including manual tags)', ); assert.ok( workflows.tauriRelease.includes( - "group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && inputs.release_tag == '' && github.ref || format('{0}-{1}', github.ref, github.run_id) }}", + "group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/heads/') && inputs.release_tag == '' && format('{0}-{1}-{2}', github.ref, inputs.platform, inputs.windows_hang_diagnostics) || format('{0}-{1}', github.ref, github.run_id) }}", ), - 'manual Tauri branch builds for one ref must share a group so older DMG builds are cancelled', + 'equivalent Tauri branch builds share a group; different platform/diagnostic requests are independent', ); assert.ok( workflows.tauriRelease.includes( - "cancel-in-progress: ${{ github.event_name == 'workflow_dispatch' && inputs.release_tag == '' }}", + "cancel-in-progress: ${{ github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/heads/') && inputs.release_tag == '' }}", ), 'only manual Tauri branch builds cancel; tag publishes and draft repairs must keep running', ); @@ -43,12 +45,16 @@ assert.ok( ); assert.ok( - workflows.ci.includes(isolatedManualGroup), - 'PR CI must isolate manual runs while grouping pull-request and branch runs by ref', + workflows.ci.includes( + "group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}-${{ inputs.platform || 'all' }}-${{ inputs.macos_runner || 'macos-latest' }}", + ), + 'CI must group equivalent requests without mixing event, platform or runner selections', ); assert.ok( - workflows.ci.includes("cancel-in-progress: ${{ github.event_name == 'pull_request' }}"), - 'PR CI must cancel superseded pull-request runs without cancelling branch pushes', + workflows.ci.includes( + "cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}", + ), + 'CI must cancel superseded PR and manual checks without cancelling baseline branch pushes', ); assert.ok( diff --git a/openless-all/app/tsconfig.json b/openless-all/app/tsconfig.json index efdeec019..35c38ea53 100644 --- a/openless-all/app/tsconfig.json +++ b/openless-all/app/tsconfig.json @@ -10,6 +10,8 @@ "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, + "incremental": true, + "tsBuildInfoFile": "./node_modules/.cache/tsc/app.tsbuildinfo", "jsx": "react-jsx", "strict": true, "noUnusedLocals": true, From 982c1ac801e1c8b115b7563d2bb8ad4c232f75ca Mon Sep 17 00:00:00 2001 From: TRIP <1933142963@qq.com> Date: Sun, 8 Nov 2026 23:09:21 +0800 Subject: [PATCH 2/3] perf(ci): reuse Cargo outputs for diagnostics and backend tests --- .github/workflows/ci.yml | 17 +-- docs/ci-trigger-and-cache-policy.md | 12 +- .../app/scripts/ci-performance.test.mjs | 111 +++++++++++++++++- ...windows-hang-diagnostics-contract.test.mjs | 6 +- 4 files changed, 135 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82730995b..a84024a5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -748,13 +748,11 @@ jobs: - uses: swatinem/rust-cache@v2 if: runner.os == 'Windows' with: - # `shared-key` replaces the job name in the cache prefix, so the release - # workflow restoring the same key can reuse this tree. Keep the two in - # sync (scripts/ci-cache-sharing.test.mjs enforces it). + # Keep the baseline's target path/cache version. The standalone backend + # suite below uses this same directory; Cargo fingerprints isolate any + # dependency versions/features that differ between the two manifests. shared-key: tauri-windows - workspaces: | - openless-all/app/src-tauri -> target - openless-all/app/src-tauri/backend-tests -> target + workspaces: 'openless-all/app/src-tauri -> target' save-if: ${{ github.ref == 'refs/heads/beta' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }} - name: Cache macOS stable dependencies @@ -856,7 +854,10 @@ jobs: # the sink on Windows/macOS without optional Tauri runtime DLL entrypoints. - name: Compile opt-in Windows hang diagnostics host timeout-minutes: 25 - run: cargo check --locked --manifest-path src-tauri/Cargo.toml --features issue-1266-diagnostics --timings + # `check` rebuilt the graph in dev mode after `test` (194s on Windows). + # Build real production lib/bin targets with the preceding test profile: + # dependencies are reusable, while cfg(not(test)) and linking stay checked. + run: cargo build --locked --manifest-path src-tauri/Cargo.toml --profile test --lib --bins --features issue-1266-diagnostics --timings - name: Run isolated Windows hang diagnostics tests (off/on) timeout-minutes: 10 @@ -881,7 +882,7 @@ jobs: # compile coverage from the step above. if: runner.os == 'Windows' timeout-minutes: 20 - run: cargo test --locked --manifest-path src-tauri/backend-tests/Cargo.toml + run: cargo test --locked --manifest-path src-tauri/backend-tests/Cargo.toml --target-dir src-tauri/target --timings - name: Run native recorder module tests (Windows) # Exercise the production recorder module without hardware, Tauri, MLX, or ASR submodules. diff --git a/docs/ci-trigger-and-cache-policy.md b/docs/ci-trigger-and-cache-policy.md index 335ac64c2..819e331b4 100644 --- a/docs/ci-trigger-and-cache-policy.md +++ b/docs/ci-trigger-and-cache-policy.md @@ -151,4 +151,14 @@ npm 下载缓存使用锁文件精确键,缺失时按 OS/架构前缀恢复已 矩阵取舍:浏览器由一个串行 job 拆成两路,Windows MSRV 由 stable job 拆出,再增加两条轻量汇总检查以保留原必需检查名。单次全量 CI 的 runner 数会增加,目标是缩短关键路径;没有增加浏览器、平台或架构组合。实际墙钟收益仍受 GitHub runner 排队、冷缓存与新增缓存体积影响,需要合并后的同类运行对照,不能把各步骤节省相加作为整轮加速比。 -本地验证:`npm test` 完成构建和全部 166 个测试文件;修改的工作流通过 actionlint;两种浏览器分别 `playwright test --list --project=…`,各发现 116 个测试。新增行为用例覆盖必需检查的失败/取消/跳过、挂起的 JS/TS 子进程、NSIS 失败中止和 MSI 二次打包。Windows 安装器实际打包、macOS 签名与 GitHub 多平台耗时仍需远端验证。 +本地验证:`npm test` 完成构建和全部 166 个测试文件;修改的工作流通过 actionlint;两种浏览器分别 `playwright test --list --project=…`,各发现 116 个测试。新增行为用例覆盖必需检查的失败/取消/跳过、挂起的 JS/TS 子进程、NSIS 失败中止和 MSI 二次打包。Windows 安装器实际打包、macOS 签名仍需远端验证;多平台首轮 CI 结果见下一节。 + +## 9. 第二轮:减少 Windows 重复编译 + +[首轮 CI 42490834011](https://github.com/Open-Less/openless/actions/runs/42490834011) 全部通过,执行窗口(首个 job 开始到最后一个 job 结束)为 14 分 28 秒。父提交的完整 CI 为 21 分 14 秒,缩短 31.9%;这不包含前者 3 秒、后者 24 分 03 秒的首次调度等待。首轮各 runner 时长合计为 94 分 20 秒,较基线 82 分 40 秒增加 14.1%,因此继续优化重复工作。 + +Windows stable 首轮为 13 分 36 秒,其中默认 host 测试编译 287 秒,随后诊断 feature 的 `cargo check` 又花 194 秒。日志显示前者使用 `test` profile(无 debug info),后者切到 `dev` profile(有 debug info)并重新检查整张依赖图。诊断检查改为 `cargo build --profile test --lib --bins`,使用前一步的依赖产物,同时实际编译、链接 feature-on 的生产 lib/bin;`cfg(not(test))` 仍生效,独立诊断运行测试也保留。 + +独立 backend 测试此前使用自己的 target,首轮另花 101 秒。它与 Tauri 锁文件的 394 个条目中有 393 个相同;现在 Windows stable 的这一步使用 `--target-dir src-tauri/target`,让 Cargo 复用版本、features、profile 均匹配的依赖,其余仍独立编译。缓存也恢复为原有单一 target 路径,避免为同一依赖图存两份目录;MSRV 仍保留独立工具链缓存。 + +`ci-performance.test.mjs` 用两个离线 Cargo 测试包执行实际工作流命令,确认共享依赖在两步中均为 `fresh`,诊断命令产出非测试二进制,并用故意损坏的 feature-on 生产代码确认它会失败。第二轮不增加 runner、不减少现有测试;实际节省需等待新的远端运行,不能直接将 194 秒和 101 秒全计作收益。 diff --git a/openless-all/app/scripts/ci-performance.test.mjs b/openless-all/app/scripts/ci-performance.test.mjs index 34643a910..76c26a59b 100644 --- a/openless-all/app/scripts/ci-performance.test.mjs +++ b/openless-all/app/scripts/ci-performance.test.mjs @@ -85,6 +85,115 @@ assert.equal( 0, ); +// Exercise the actual CI Cargo commands against two tiny offline packages. +// Switching the diagnostics compile back to `check` or giving backend tests +// their own target directory must lose the dependency reuse this change needs. +const cargoScratch = mkdtempSync(join(tmpdir(), 'openless-cargo-reuse-')); +try { + for (const path of ['host/src', 'shared/src', 'backend/src']) { + mkdirSync(join(cargoScratch, path), { recursive: true }); + } + writeFileSync( + join(cargoScratch, 'host/Cargo.toml'), + `[package] +name = "ci-profile-host" +version = "0.1.0" +edition = "2021" +[features] +issue-1266-diagnostics = [] +[dependencies] +ci-shared = { path = "../shared" } +`, + ); + writeFileSync( + join(cargoScratch, 'shared/Cargo.toml'), + '[package]\nname = "ci-shared"\nversion = "0.1.0"\nedition = "2021"\n', + ); + writeFileSync(join(cargoScratch, 'shared/src/lib.rs'), 'pub fn value() -> u32 { 42 }'); + writeFileSync( + join(cargoScratch, 'host/src/lib.rs'), + 'pub fn run() -> u32 { ci_shared::value() }', + ); + writeFileSync( + join(cargoScratch, 'host/src/main.rs'), + 'fn main() { assert_eq!(ci_profile_host::run(), 42); }', + ); + writeFileSync( + join(cargoScratch, 'backend/Cargo.toml'), + '[package]\nname = "ci-backend-tests"\nversion = "0.1.0"\nedition = "2021"\n' + + '[dependencies]\nci-shared = { path = "../shared" }\n', + ); + writeFileSync( + join(cargoScratch, 'backend/src/lib.rs'), + '#[test] fn shared_contract() { assert_eq!(ci_shared::value(), 42); }', + ); + const cargoEnv = { ...process.env, CARGO_PROFILE_TEST_DEBUG: '0' }; + delete cargoEnv.CARGO_TARGET_DIR; + const cargo = (args) => + spawnSync('cargo', [...args, '--offline'], { + cwd: cargoScratch, + env: cargoEnv, + encoding: 'utf8', + timeout: 30_000, + }); + const expectSuccess = (result) => { + assert.ifError(result.error); + assert.equal(result.status, 0, result.stdout + result.stderr); + return result; + }; + expectSuccess( + cargo(['test', '--manifest-path', 'host/Cargo.toml', '--lib', '--bins', '--no-run']), + ); + expectSuccess(cargo(['generate-lockfile', '--manifest-path', 'backend/Cargo.toml'])); + const ciArgs = (stepName) => + ci.jobs['cross-platform'].steps + .find((step) => step.name === stepName) + .run.trim() + .split(/\s+/) + .slice(1) + .map((arg) => + arg === 'src-tauri/Cargo.toml' + ? join(cargoScratch, 'host/Cargo.toml') + : arg === 'src-tauri/backend-tests/Cargo.toml' + ? join(cargoScratch, 'backend/Cargo.toml') + : arg === 'src-tauri/target' + ? join(cargoScratch, 'host/target') + : arg, + ); + const diagnosticsArgs = ciArgs('Compile opt-in Windows hang diagnostics host'); + for (const args of [diagnosticsArgs, ciArgs('Run Rust-only backend unit tests (Windows)')]) { + const result = expectSuccess(cargo([...args, '--message-format=json'])); + const artifacts = result.stdout + .split('\n') + .filter((line) => line.startsWith('{')) + .map((line) => JSON.parse(line)) + .filter((record) => record.reason === 'compiler-artifact'); + assert.equal( + artifacts.find((record) => record.target.name === 'ci_shared')?.fresh, + true, + `${args.join(' ')} must reuse the previously compiled dependency`, + ); + if (args === diagnosticsArgs) { + assert.ok( + artifacts.some((record) => record.target.kind.includes('bin') && !record.profile.test), + 'diagnostics must link the production binary, not only a test harness', + ); + } + } + writeFileSync( + join(cargoScratch, 'host/src/lib.rs'), + '#[cfg(all(feature = "issue-1266-diagnostics", not(test)))]\n' + + 'compile_error!("production diagnostics checked");\n' + + 'pub fn run() -> u32 { ci_shared::value() }', + ); + const broken = cargo(diagnosticsArgs); + assert.ifError(broken.error); + assert.notEqual(broken.status, 0); + assert.match(broken.stderr, /production diagnostics checked/); +} finally { + rmSync(cargoScratch, { recursive: true, force: true }); +} + // Run the real Windows build shell with only npm stubbed. Check artifact-flow // decisions, not the spelling of the commands: one compile, optional rebundle, // and no MSI attempt after a failed NSIS build. @@ -156,4 +265,4 @@ esac } finally { rmSync(scratch, { recursive: true, force: true }); } -console.log('CI gates and Windows installer reuse/failure propagation passed'); +console.log('CI gates, Cargo reuse and Windows installer failure propagation passed'); diff --git a/openless-all/app/scripts/windows-hang-diagnostics-contract.test.mjs b/openless-all/app/scripts/windows-hang-diagnostics-contract.test.mjs index d65265889..a75b9d52a 100644 --- a/openless-all/app/scripts/windows-hang-diagnostics-contract.test.mjs +++ b/openless-all/app/scripts/windows-hang-diagnostics-contract.test.mjs @@ -153,7 +153,11 @@ assert.match(lib, /observe_issue1266_lifecycle\(&event\);\s*match event/); const ciSteps = Object.values(ci.jobs).flatMap((job) => job.steps ?? []); assert.ok(ciSteps.some((step) => /test-windows-hang-diagnostics\.py/.test(step.run ?? ''))); assert.ok( - ciSteps.some((step) => /cargo check.*--features issue-1266-diagnostics/.test(step.run ?? '')), + ciSteps.some((step) => + /cargo build.*--profile test --lib --bins --features issue-1266-diagnostics/.test( + step.run ?? '', + ), + ), ); const steps = release.jobs.build.steps; assert.equal(release.on.workflow_dispatch.inputs.windows_hang_diagnostics.default, false); From e4237527a305cae587f141b30609ccfc59ea1639 Mon Sep 17 00:00:00 2001 From: TRIP <1933142963@qq.com> Date: Sun, 8 Nov 2026 23:14:06 +0800 Subject: [PATCH 3/3] test(ci): canonicalize Cargo fixture paths on macOS --- openless-all/app/scripts/ci-performance.test.mjs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/openless-all/app/scripts/ci-performance.test.mjs b/openless-all/app/scripts/ci-performance.test.mjs index 76c26a59b..35d7672db 100644 --- a/openless-all/app/scripts/ci-performance.test.mjs +++ b/openless-all/app/scripts/ci-performance.test.mjs @@ -1,6 +1,14 @@ import assert from 'node:assert/strict'; import { spawnSync } from 'node:child_process'; -import { chmodSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { + chmodSync, + mkdtempSync, + mkdirSync, + readFileSync, + realpathSync, + rmSync, + writeFileSync, +} from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { load } from 'js-yaml'; @@ -88,7 +96,9 @@ assert.equal( // Exercise the actual CI Cargo commands against two tiny offline packages. // Switching the diagnostics compile back to `check` or giving backend tests // their own target directory must lose the dependency reuse this change needs. -const cargoScratch = mkdtempSync(join(tmpdir(), 'openless-cargo-reuse-')); +// macOS exposes /private/var through /var. Use one canonical path for relative +// and absolute manifests so Cargo does not fingerprint two names for one source. +const cargoScratch = realpathSync(mkdtempSync(join(tmpdir(), 'openless-cargo-reuse-'))); try { for (const path of ['host/src', 'shared/src', 'backend/src']) { mkdirSync(join(cargoScratch, path), { recursive: true });