diff --git a/.github/actions/setup-tools/action.yml b/.github/actions/setup-tools/action.yml new file mode 100644 index 00000000..f440764f --- /dev/null +++ b/.github/actions/setup-tools/action.yml @@ -0,0 +1,39 @@ +name: Setup tools (sccache / mold / nextest) + +# 工具缓存:sccache、mold、nextest 统一装到 ~/oxide-tools/bin,按固定 key 跨 run +# 持久缓存。首跑各 job 各装一次(冗余但一次性),之后每个 run 直接 restore、 +# 秒级。nextest 走官方预编译二进制直下,不依赖 main 分支安装脚本(脚本会被移动 +# 而 404)。sccache 与 mold 经 apt 装到 /usr/bin 后拷入 ~/oxide-tools/bin, +# 使缓存路径落在用户可写目录(/usr/bin 缓存受权限限制)。 +description: 恢复工具缓存;缺失时安装 sccache、mold、nextest 并存缓存 + +runs: + using: composite + steps: + - name: Restore tool cache + id: tool-cache + uses: actions/cache/restore@v4 + with: + path: ~/oxide-tools/bin + key: oxide-tools-ubuntu-v1 + + - name: Install tools (cache miss) + if: steps.tool-cache.outputs.cache-hit != 'true' + shell: bash + run: | + sudo apt-get update -y + sudo apt-get install -y sccache mold + mkdir -p "$HOME/oxide-tools/bin" + cp /usr/bin/sccache /usr/bin/mold "$HOME/oxide-tools/bin/" + curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C "$HOME/oxide-tools/bin" + + - name: Add tools to PATH + shell: bash + run: echo "$HOME/oxide-tools/bin" >> "$GITHUB_PATH" + + - name: Save tool cache + if: steps.tool-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ~/oxide-tools/bin + key: oxide-tools-ubuntu-v1 diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 5dee2448..89d41ffe 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -42,9 +42,6 @@ jobs: submodules: true - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - - name: Install sccache and mold - run: sudo apt-get update -y && sudo apt-get install -y sccache mold - - name: Install cargo-nextest - run: curl -sSf https://raw.githubusercontent.com/nextest-rs/nextest/main/scripts/install.sh | bash + - uses: ./.github/actions/setup-tools - name: Test run: cargo nextest run ${{ matrix.group.args }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3488d1e..97d99fb7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,8 +41,7 @@ jobs: with: components: clippy - uses: Swatinem/rust-cache@v2 - - name: Install sccache and mold - run: sudo apt-get update -y && sudo apt-get install -y sccache mold + - uses: ./.github/actions/setup-tools - name: Clippy run: cargo clippy --all-targets -- -D warnings @@ -55,8 +54,7 @@ jobs: submodules: true - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - - name: Install sccache and mold - run: sudo apt-get update -y && sudo apt-get install -y sccache mold + - uses: ./.github/actions/setup-tools - name: Build run: cargo build --verbose