Skip to content

Commit 031c39f

Browse files
committed
ci: add cargo caching in ci builds
1 parent c10195d commit 031c39f

File tree

7 files changed

+85
-7
lines changed

7 files changed

+85
-7
lines changed

.github/actions/setup-api-tools/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: 'Setup API Tools'
22
description: 'Setup Rust, Bun, and Python dependencies for API tools'
33

44
runs:
5-
using: 'composite'
5+
using: "composite"
66
steps:
7-
- uses: dtolnay/rust-toolchain@master
7+
- uses: ./.github/actions/setup-rust
88
with:
99
toolchain: 1.85.0
1010
components: rustfmt
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: "Setup Rust"
2+
description: "Install a Rust toolchain and configure Cargo caching"
3+
4+
inputs:
5+
toolchain:
6+
description: "Rust toolchain specifier to install"
7+
required: false
8+
default: "1.85.0"
9+
components:
10+
description: "Comma-separated list of rustup components to install"
11+
required: false
12+
default: ""
13+
targets:
14+
description: "Comma-separated list of additional targets to install"
15+
required: false
16+
default: ""
17+
extra-cache-key:
18+
description: "Suffix appended to the cache key to partition caches (e.g. per matrix entry)"
19+
required: false
20+
default: ""
21+
cache-target-dir:
22+
description: "Directory containing build artifacts to cache"
23+
required: false
24+
default: "target"
25+
skip-cache:
26+
description: "Skip configuring the Cargo cache when set to true"
27+
required: false
28+
default: "false"
29+
30+
runs:
31+
using: "composite"
32+
steps:
33+
- name: Install Rust toolchain
34+
id: toolchain
35+
uses: dtolnay/rust-toolchain@master
36+
with:
37+
toolchain: ${{ inputs.toolchain }}
38+
components: ${{ inputs.components }}
39+
targets: ${{ inputs.targets }}
40+
41+
- name: Compose cache key prefix
42+
id: cachekey
43+
if: ${{ inputs.skip-cache != 'true' }}
44+
shell: bash
45+
env:
46+
EXTRA_KEY: ${{ inputs['extra-cache-key'] }}
47+
run: |
48+
prefix="${{ runner.os }}"
49+
if [ -n "$EXTRA_KEY" ]; then
50+
prefix="$prefix-$EXTRA_KEY"
51+
fi
52+
echo "prefix=$prefix" >> "$GITHUB_OUTPUT"
53+
54+
- name: Cache Cargo directories
55+
if: ${{ inputs.skip-cache != 'true' }}
56+
uses: actions/cache@v4
57+
with:
58+
path: |
59+
~/.cargo/registry
60+
~/.cargo/git
61+
${{ inputs['cache-target-dir'] }}
62+
key: ${{ steps.cachekey.outputs.prefix }}-${{ steps.toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}
63+
restore-keys: |
64+
${{ steps.cachekey.outputs.prefix }}-${{ steps.toolchain.outputs.cachekey }}-
65+
${{ steps.cachekey.outputs.prefix }}-

.github/workflows/ci_cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@v4
2424
with:
2525
ref: ${{ github.ref }}
26-
- uses: dtolnay/rust-toolchain@master
26+
- uses: ./.github/actions/setup-rust
2727
with:
2828
toolchain: 1.85.0
2929
components: clippy, rustfmt

.github/workflows/deploy_docs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ jobs:
2020
uses: actions/checkout@v4
2121

2222
- name: Setup Rust
23-
uses: dtolnay/rust-toolchain@stable
23+
uses: ./.github/actions/setup-rust
24+
with:
25+
toolchain: stable
2426

2527
- name: Build documentation
2628
run: cargo run --bin build-docs --manifest-path docs/Cargo.toml

.github/workflows/polytest_validate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
steps:
2424
- uses: actions/checkout@v4
25-
- uses: dtolnay/rust-toolchain@master
25+
- uses: ./.github/actions/setup-rust
2626
with:
2727
toolchain: 1.85.0
2828
- name: Polytest Validate

.github/workflows/python_uniffi_ci_cd.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ jobs:
5252
ref: ${{ github.ref }}
5353
token: ${{ steps.app_token.outputs.token }}
5454
if: inputs.release
55+
- if: inputs.release
56+
uses: ./.github/actions/setup-rust
57+
with:
58+
toolchain: 1.85.0
5559
- uses: oven-sh/setup-bun@v2
5660
if: inputs.release
5761
with:
@@ -115,7 +119,7 @@ jobs:
115119
- uses: actions/checkout@v4
116120
with:
117121
ref: ${{ github.ref }}
118-
- uses: dtolnay/rust-toolchain@master
122+
- uses: ./.github/actions/setup-rust
119123
with:
120124
toolchain: 1.85.0
121125
targets: ${{ matrix.target.name }}
@@ -183,6 +187,10 @@ jobs:
183187
- uses: actions/checkout@v4
184188
with:
185189
ref: ${{ github.ref }}
190+
- uses: ./.github/actions/setup-rust
191+
with:
192+
toolchain: 1.85.0
193+
extra-cache-key: ${{ matrix.arch }}-${{ matrix.libc }}
186194

187195
- name: Set up QEMU
188196
if: matrix.arch != 'aarch64' && matrix.arch != 'x86_64'
@@ -220,6 +228,9 @@ jobs:
220228
env:
221229
RUN: |
222230
cd /workspace/${{ env.PACKAGE_DIR }}
231+
mkdir -p /workspace/.cargo
232+
export CARGO_HOME=/workspace/.cargo
233+
export CARGO_TARGET_DIR=/workspace/target
223234
poetry env use python${{ env.PYTHON_VERSION }}
224235
cargo pkg ${{ inputs.crate }} py
225236
run: docker exec build-container bash -c "$RUN"

.github/workflows/swift_ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
runs-on: macos-latest
2828
steps:
2929
- uses: actions/checkout@v4
30-
- uses: dtolnay/rust-toolchain@master
30+
- uses: ./.github/actions/setup-rust
3131
with:
3232
toolchain: 1.85.0
3333
targets: aarch64-apple-ios, x86_64-apple-ios, aarch64-apple-ios-sim, x86_64-apple-ios, aarch64-apple-ios-macabi, x86_64-apple-ios-macabi, aarch64-apple-darwin, x86_64-apple-darwin

0 commit comments

Comments
 (0)