ci: run backend tests under cargo-nextest and cache deps with rust-cache

- Backend tests run with `cargo nextest run --profile ci`: one process
  per test, a 180s per-test timeout (src-tauri/.config/nextest.toml),
  and no fail-fast. The WSL2 nightly uses it too, still one test at a
  time and with the same selection as the old `--skip database::`, so a
  hung test is killed instead of eating the whole job.
- Integration tests shared one fixed test home, and each process wiped
  it on startup. Under nextest they ran concurrently and failed en
  masse, so tests/support.rs now picks a directory per
  NEXTEST_TEST_GLOBAL_SLOT. Plain `cargo test` keeps the old directory.
- Swatinem/rust-cache replaces the hand-rolled actions/cache step. It
  caches dependencies only, not the cc-switch crate that is rebuilt
  every run, and keys on OS, rustc version and Cargo.lock. The WSL2 CI
  job and the nightly share the `backend` key but only restore it, so
  their lib-only builds never save over the full Windows cache.
- Quote the $GITHUB_OUTPUT redirect that shellcheck flagged.
This commit is contained in:
Jason committed 2026-10-05 12:17:50 +08:00
1 parent ef633b5789
commit b544bc27c6
4 files changed
+57 -29

No files matched your search

+22 -18
View File
@@ -78,7 +78,7 @@ jobs:
- name: Get pnpm store directory
id: pnpm-store
shell: bash
run: echo "path=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
- name: Cache pnpm store
uses: actions/cache@v5
@@ -142,15 +142,18 @@ jobs:
sudo apt-get install -y --no-install-recommends libsoup-3.0-dev \
|| sudo apt-get install -y --no-install-recommends libsoup2.4-dev
- name: Cache Cargo registry and build
uses: actions/cache@v5
# 只缓存依赖:本仓库的 crate 每次都要重编,缓存它只会让缓存变大、恢复变慢。
# key 自带 OS、rustc 版本和 Cargo.lock;shared-key 让 WSL2 job 能读到 Windows 这份。
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
path: |
~/.cargo/registry
~/.cargo/git
src-tauri/target
key: ${{ runner.os }}-cargo-${{ hashFiles('src-tauri/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
workspaces: src-tauri -> target
shared-key: backend
- name: Install cargo-nextest
uses: taiki-e/install-action@e407f7bafb71fd004bc5c2da3032e5470cbb6ef0 # v2.87.24
with:
tool: cargo-nextest
- name: Create frontend dist placeholder
shell: bash
@@ -162,8 +165,10 @@ jobs:
- name: Clippy
run: cargo clippy --manifest-path src-tauri/Cargo.toml -- -D warnings
# 每个测试一个进程,单测超时见 src-tauri/.config/nextest.toml。doctest 目前只有两个
# ignored,nextest 不跑 doctest 也不漏。
- name: Run tests
run: cargo test --manifest-path src-tauri/Cargo.toml
run: cargo nextest run --manifest-path src-tauri/Cargo.toml --profile ci
backend-windows-wsl2:
name: Backend Checks (Windows + WSL2 home)
@@ -196,15 +201,14 @@ jobs:
distribution: Ubuntu-24.04
wsl-version: 2
- name: Cache Cargo registry and build
uses: actions/cache@v5
# 只恢复不保存:这里只编 lib 测试,若由它先存,同 key 的 Windows 缓存就只剩一小半。
# 完整缓存由 backend 矩阵的 Windows job 保存(同一个 shared-key)。
- name: Restore Rust dependencies
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
path: |
~/.cargo/registry
~/.cargo/git
src-tauri/target
key: ${{ runner.os }}-cargo-${{ hashFiles('src-tauri/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
workspaces: src-tauri -> target
shared-key: backend
save-if: false
- name: Create frontend dist placeholder
shell: bash
+16 -10
View File
@@ -9,7 +9,9 @@ name: WSL2 Nightly
# CC Switch skips Codex state DBs on WSL paths. So here
# `database::` tests are skipped by name, tests that build SQLite fixtures skip
# themselves (config::sqlite_unsupported_in_temp_dir), and integration tests,
# which all create the app database, are not run.
# which all create the app database, are not run. Tests run under cargo-nextest
# one at a time, so a hung test is killed by the per-test timeout in
# src-tauri/.config/nextest.toml instead of eating the whole job.
on:
schedule:
- cron: "23 18 * * *" # 02:23 Beijing time
@@ -46,15 +48,19 @@ jobs:
distribution: Ubuntu-24.04
wsl-version: 2
- name: Cache Cargo registry and build
uses: actions/cache@v5
# 只恢复不保存:夜间只编 lib 测试,若由它存进 main 的缓存,PR 的 Windows job 会精确命中
# 这份不完整的缓存。完整缓存由 ci.yml backend 矩阵的 Windows job 保存(同一个 shared-key)。
- name: Restore Rust dependencies
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
path: |
~/.cargo/registry
~/.cargo/git
src-tauri/target
key: ${{ runner.os }}-cargo-${{ hashFiles('src-tauri/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
workspaces: src-tauri -> target
shared-key: backend
save-if: false
- name: Install cargo-nextest
uses: taiki-e/install-action@e407f7bafb71fd004bc5c2da3032e5470cbb6ef0 # v2.87.24
with:
tool: cargo-nextest
- name: Create frontend dist placeholder
shell: bash
@@ -104,4 +110,4 @@ jobs:
run: |
$env:TEMP = $env:CC_SWITCH_WSL_TEST_TEMP
$env:TMP = $env:CC_SWITCH_WSL_TEST_TEMP
cargo test --lib --manifest-path src-tauri/Cargo.toml -- --test-threads=1 --skip database::
cargo nextest run --lib --manifest-path src-tauri/Cargo.toml --profile ci --test-threads 1 -E 'not test(/database::/)'