Skip to content

Commit 9ca2d30

Browse files
committed
github-ci: cache Rust toolchain to avoid rustup.rs failures
Cache ~/.rustup and ~/.cargo/bin across all jobs that install Rust via rustup. On cache hit, the curl-to-rustup step is skipped entirely, avoiding failures when rustup.rs is unreachable. Cache keys are versioned per toolchain (e.g. rust-toolchain-1.85.0) so bumping a version automatically invalidates the cache. For jobs that derive the version from Cargo.toml.in, the key uses hashFiles() for the same effect.
1 parent e69c801 commit 9ca2d30

1 file changed

Lines changed: 132 additions & 8 deletions

File tree

.github/workflows/builds.yml

Lines changed: 132 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,20 @@ jobs:
4747
name: Prepare cbindgen
4848
runs-on: ubuntu-latest
4949
steps:
50-
- name: Cache ~/.cargo
50+
- name: Cache ~/.cargo and Rust toolchain
51+
id: cache-rust
5152
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
5253
with:
53-
path: ~/.cargo
54-
key: ${{ github.job }}-cargo
54+
path: |
55+
~/.cargo
56+
~/.rustup
57+
key: ${{ github.job }}-cargo-rust
5558
- name: Installing Rust
59+
if: steps.cache-rust.outputs.cache-hit != 'true'
5660
run: |
5761
curl https://sh.rustup.rs -sSf | sh -s -- -y
58-
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
5962
rustup target add x86_64-unknown-linux-musl
63+
- run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
6064
- name: Building static cbindgen for Linux
6165
run: |
6266
cargo install --target x86_64-unknown-linux-musl --debug cbindgen
@@ -424,6 +428,15 @@ jobs:
424428
path: ~/.cargo/registry
425429
key: cargo-registry
426430

431+
- name: Cache Rust toolchain
432+
id: cache-rust
433+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
434+
with:
435+
path: |
436+
~/.rustup
437+
~/.cargo/bin
438+
key: rust-toolchain-1.85.0
439+
427440
- name: Determine number of CPUs
428441
run: echo CPUS=$(nproc --all) >> $GITHUB_ENV
429442

@@ -466,10 +479,13 @@ jobs:
466479
sudo \
467480
which \
468481
zlib-devel
469-
- run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.85.0 -y
482+
- name: Install Rust
483+
if: steps.cache-rust.outputs.cache-hit != 'true'
484+
run: |
485+
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.85.0 -y
486+
rustup component add rustfmt
487+
rustup component add clippy
470488
- run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
471-
- run: rustup component add rustfmt
472-
- run: rustup component add clippy
473489

474490
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
475491
- run: git config --global --add safe.directory /__w/suricata/suricata
@@ -821,8 +837,19 @@ jobs:
821837
zlib-devel
822838
- run: |
823839
dnf clean all
840+
841+
- name: Cache Rust toolchain
842+
id: cache-rust
843+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
844+
with:
845+
path: |
846+
~/.rustup
847+
~/.cargo/bin
848+
key: rust-toolchain-1.86.0
849+
824850
# packaged Rust version has no profiler support built in, so get from rustup
825851
- name: Install Rust
852+
if: steps.cache-rust.outputs.cache-hit != 'true'
826853
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.86.0 -y
827854
- run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
828855
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
@@ -1482,9 +1509,19 @@ jobs:
14821509
with:
14831510
name: prep
14841511
path: prep
1512+
- name: Cache Rust toolchain
1513+
id: cache-rust
1514+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
1515+
with:
1516+
path: |
1517+
~/.rustup
1518+
~/.cargo/bin
1519+
key: rust-toolchain-1.85.1
1520+
14851521
# packaged Rust version is too old for coverage, so get from rustup. 1.85.1 matches
14861522
# LLVM 19
14871523
- name: Install Rust
1524+
if: steps.cache-rust.outputs.cache-hit != 'true'
14881525
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.85.1 -y
14891526
- uses: ./.github/actions/install-cbindgen
14901527
- run: ./autogen.sh
@@ -1624,8 +1661,19 @@ jobs:
16241661
curl \
16251662
time \
16261663
wget
1664+
1665+
- name: Cache Rust toolchain
1666+
id: cache-rust
1667+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
1668+
with:
1669+
path: |
1670+
~/.rustup
1671+
~/.cargo/bin
1672+
key: rust-toolchain-1.75.0
1673+
16271674
# specific version to match up to the llvm version in ubuntu below
16281675
- name: Install Rust
1676+
if: steps.cache-rust.outputs.cache-hit != 'true'
16291677
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.75.0 -y
16301678
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
16311679
- run: git config --global --add safe.directory /__w/suricata/suricata
@@ -1731,8 +1779,19 @@ jobs:
17311779
time \
17321780
wget \
17331781
dpdk-dev
1782+
1783+
- name: Cache Rust toolchain
1784+
id: cache-rust
1785+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
1786+
with:
1787+
path: |
1788+
~/.rustup
1789+
~/.cargo/bin
1790+
key: rust-toolchain-1.75.0
1791+
17341792
# specific version to match up to the llvm version in ubuntu below
17351793
- name: Install Rust
1794+
if: steps.cache-rust.outputs.cache-hit != 'true'
17361795
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.75.0 -y
17371796
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
17381797
- run: git config --global --add safe.directory /__w/suricata/suricata
@@ -1970,9 +2029,19 @@ jobs:
19702029
with:
19712030
name: prep
19722031
path: prep
2032+
- name: Cache Rust toolchain
2033+
id: cache-rust
2034+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
2035+
with:
2036+
path: |
2037+
~/.rustup
2038+
~/.cargo/bin
2039+
key: rust-toolchain-1.85.1
2040+
19732041
# packaged Rust version is too old for coverage, so get from rustup. 1.85.1 matches
19742042
# LLVM 19
19752043
- name: Install Rust
2044+
if: steps.cache-rust.outputs.cache-hit != 'true'
19762045
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.85.1 -y
19772046
- uses: ./.github/actions/install-cbindgen
19782047
- run: ./autogen.sh
@@ -2205,8 +2274,19 @@ jobs:
22052274
time \
22062275
wget \
22072276
dpdk-dev
2277+
2278+
- name: Cache Rust toolchain
2279+
id: cache-rust
2280+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
2281+
with:
2282+
path: |
2283+
~/.rustup
2284+
~/.cargo/bin
2285+
key: rust-toolchain-1.75.0
2286+
22082287
# packaged Rust version is too old for coverage, so get from rustup
22092288
- name: Install Rust
2289+
if: steps.cache-rust.outputs.cache-hit != 'true'
22102290
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.75.0 -y
22112291
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
22122292
- run: git config --global --add safe.directory /__w/suricata/suricata
@@ -2345,6 +2425,16 @@ jobs:
23452425
with:
23462426
path: ~/.cargo/registry
23472427
key: cargo-registry
2428+
2429+
- name: Cache Rust toolchain
2430+
id: cache-rust
2431+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
2432+
with:
2433+
path: |
2434+
~/.rustup
2435+
~/.cargo/bin
2436+
key: rust-toolchain-1.62.0
2437+
23482438
- name: Determine number of CPUs
23492439
run: echo CPUS=$(nproc --all) >> $GITHUB_ENV
23502440

@@ -2381,7 +2471,9 @@ jobs:
23812471
zlib1g \
23822472
zlib1g-dev \
23832473
dpdk-dev
2384-
- run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.62.0 -y
2474+
- name: Install Rust
2475+
if: steps.cache-rust.outputs.cache-hit != 'true'
2476+
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.62.0 -y
23852477
- run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
23862478
- name: Download suricata.tar.gz
23872479
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131
@@ -2852,7 +2944,18 @@ jobs:
28522944
with:
28532945
name: prep
28542946
path: prep
2947+
2948+
- name: Cache Rust toolchain
2949+
id: cache-rust
2950+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
2951+
with:
2952+
path: |
2953+
~/.rustup
2954+
~/.cargo/bin
2955+
key: rust-toolchain-msrv-${{ hashFiles('rust/Cargo.toml.in') }}
2956+
28552957
- name: Install Rust
2958+
if: steps.cache-rust.outputs.cache-hit != 'true'
28562959
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $(grep rust-version rust/Cargo.toml.in|sed 's/\"//g'|awk '{print $3}') -y
28572960
- run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
28582961
- uses: ./.github/actions/install-cbindgen
@@ -3114,7 +3217,18 @@ jobs:
31143217
with:
31153218
name: prep
31163219
path: prep
3220+
3221+
- name: Cache Rust toolchain
3222+
id: cache-rust
3223+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
3224+
with:
3225+
path: |
3226+
~/.rustup
3227+
~/.cargo/bin
3228+
key: rust-toolchain-msrv-${{ hashFiles('rust/Cargo.toml.in') }}
3229+
31173230
- name: Install Rust
3231+
if: steps.cache-rust.outputs.cache-hit != 'true'
31183232
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $(grep rust-version rust/Cargo.toml.in|sed 's/\"//g'|awk '{print $3}') -y
31193233
- run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
31203234
- uses: ./.github/actions/install-cbindgen
@@ -3146,6 +3260,15 @@ jobs:
31463260
path: ~/.cargo/registry
31473261
key: cargo-registry
31483262

3263+
- name: Cache Rust toolchain
3264+
id: cache-rust
3265+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb
3266+
with:
3267+
path: |
3268+
~/.rustup
3269+
~/.cargo/bin
3270+
key: rust-toolchain-${{ env.RUST_VERSION_KNOWN }}
3271+
31493272
- name: Determine number of CPUs
31503273
run: echo CPUS=$(nproc --all) >> $GITHUB_ENV
31513274

@@ -3185,6 +3308,7 @@ jobs:
31853308
libbpf-dev \
31863309
libelf-dev
31873310
- name: Install Rust
3311+
if: steps.cache-rust.outputs.cache-hit != 'true'
31883312
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $RUST_VERSION_KNOWN -y
31893313
- run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
31903314
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd

0 commit comments

Comments
 (0)