ci: 编译缓存接入远端后端并补取消超时与权限

This commit is contained in:
2026-10-10 12:08:30 +00:00
parent c009cc17ac
commit 1979278d36
3 changed files with 61 additions and 40 deletions
+11 -5
View File
@@ -2,11 +2,16 @@ name: CI Test
# 可复用工作流:主 ci.yml 的 test job 经 workflow_call 调用本文件。外观上主 CI
# 只有一个 test job(全过才绿),点进去才看到内部 matrix(os × group)并行图。
# 产物复用:rust-cache 按「OS + Cargo.lock」键在仓库级共享,本 workflow 的 test
# job 能 restore 主 ci.yml build job 存的 target/ 缓存(跨 workflow 边界有效)。
# 产物复用:test 依赖主 workflow 的 build job 先把 workspace 编译一遍并写入
# sccache(GitHub Actions 缓存后端),各分区随后经 sccache 命中已编产物,只补编
# 自己的 test harness;rust-cache 负责依赖源码与 registry 的缓存。
on:
workflow_call:
env:
# 与主 ci.yml 一致:sccache 走 GitHub Actions 缓存后端,编译产物跨 run 复用。
SCCACHE_GHA_ENABLED: "true"
jobs:
test:
name: Test (${{ matrix.os }} / ${{ matrix.group.name }})
@@ -36,6 +41,7 @@ jobs:
args: "-p oxide_kernel -p oxide_regalloc -p oxide_cfg -p oxide_bytecode -p oxide_engine -p oxide_compiler -p oxide_parser -p oxide_log -p oxide_ir -p oxide_code_cache"
# === END AUTO-GENERATED ===
runs-on: ${{ matrix.os }}
timeout-minutes: 40
steps:
- uses: actions/checkout@v7
with:
@@ -43,9 +49,9 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
# 与 ci.yml 的 build job 同键:复用 build 的 target/ 缓存,只补编
# test harness。自定义键避免按 profile 自动分键(build/test 各一)
# 导致 test 恢复陈旧缓存、重链接时走默认 ld 报 cannot find ld。
# 与 ci.yml build job 同名后缀的稳定键;rust-cache 自动键附 job 名,
# 故与 build 仍是两份独立缓存,跨 job 的 workspace 产物复用由 sccache
# 承担(见本文件头注释)。
key: oxide-target-ubuntu-v1
- uses: ./.github/actions/setup-tools
- name: Test
+31 -12
View File
@@ -6,22 +6,37 @@ on:
pull_request:
branches: [main]
# 同一 PR 的新推送取消上一轮未完成的 run:一轮 CI 数十分钟,过期 run 继续跑纯浪费
# runner 分钟,且其状态已无意义。main 分支的推送不取消,保留每个提交的完整记录。
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
# 最小权限:CI 只读仓库内容,不需要写 token。
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
# sccache 走 GitHub Actions 缓存后端:编译产物跨 run 复用。本地磁盘缓存无后端、
# 每个 job 用完即弃,跨 run 零命中,等于白装。须在 sccache 服务启动前设置。
SCCACHE_GHA_ENABLED: "true"
# job 拓扑:fmt / clippy / build 三者并行独立;test 依赖 build(needs),在
# build 编译完成后启动,复用 build 的产物(经共享 rust-cache 传递 target/),
# 只补编 test harness、不重编整个 workspace。各 job 单独状态,一个挂了不阻塞
# 无关者,GitHub 界面一眼看出哪个红。clippy 走 check 模式、产物与 build 不同,
# 无法复用 build 产物,故保持独立并行。
# job 拓扑:fmt / clippy / build 三者并行独立;test 依赖 build(needs),在 build
# 编译完成后启动。build 先编译 workspace 依赖,并把每个编译单元写进 sccache
# (GitHub Actions 缓存后端);test 各分区随后经 sccache 命中这些已编产物,只需
# 补编自己的 test harness,不重编整个 workspace。各 job 单独状态,一个挂了不阻塞
# 无关者,GitHub 界面一眼看出哪个红。
#
# sccache 与 mold:.cargo/config.toml 全局引用(rustc-wrapper 与 -fuse-ld=mold),
# 凡跑 rustc 的 job(clippy/build/test)必须先装,否则构建直接失败。fmt 只跑
# rustfmt、不跑 rustc,无需安装。
# sccache 与 mold:.cargo/config.toml 全局引用 rustc-wrapper=sccache,凡跑 rustc
# 的 job(clippy/build/test)都要经 setup-tools 装好 sccache,否则构建直接失败;
# mold 由 setup-tools 从工作副本剥掉,CI 链接统一走默认 ld。fmt 只跑 rustfmt、
# 不跑 rustc,无需 setup-tools。
jobs:
fmt:
name: Format
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
@@ -33,6 +48,7 @@ jobs:
clippy:
name: Clippy
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
with:
@@ -48,6 +64,7 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
with:
@@ -55,16 +72,18 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
# 与 ci-test.yml 的 test job 同键:test 复用 build 的 target/ 缓存,
# 只补编 test harness、不重编整个 workspace。自定义键避免按 profile
# 自动分键(build/test 各一)导致 test 恢复陈旧缓存。
# 稳定键后缀:让 build 的依赖产物缓存跨 run 固定在同一命名空间。
# rust-cache 的自动键会附 job 名,故 build 与 test 仍是两份独立缓存;
# 且它只缓存依赖、不缓存 workspace 自身,workspace 产物的跨 job 复用
# 由 sccache 承担。
key: oxide-target-ubuntu-v1
- uses: ./.github/actions/setup-tools
- name: Build
run: cargo build --verbose
# test 是单一 job:经 workflow_call 调用 ci-test.yml,外观上主 CI 只有一个 test
# (全过才绿),点进去才见内部 matrix(os × group)并行图。needs build 复用产物。
# (全过才绿),点进去才见内部 matrix(os × group)并行图。build 先编 workspace
# 并填充 sccache,test 经 sccache 命中已编产物。
test:
name: Test
needs: [build]