|
31 | 31 | jobs:
|
32 | 32 | build_test:
|
33 | 33 | runs-on: ubuntu-latest
|
| 34 | + # Generate and populate the global Cargo registry and cache first. Each |
| 35 | + # job in the matrix runs in parallel, so without populating the cache |
| 36 | + # first, most jobs would duplicate the work of downloading crates from |
| 37 | + # the internet. Populating the cache first ensures that this work only |
| 38 | + # happens once. |
| 39 | + needs: generate_cache |
34 | 40 |
|
35 | 41 | strategy:
|
36 | 42 | # By default, this is set to `true`, which means that a single CI job
|
|
78 | 84 | steps:
|
79 | 85 | - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
|
80 | 86 |
|
| 87 | + - uses: actions/cache@v3 |
| 88 | + with: |
| 89 | + path: | |
| 90 | + ~/.cargo/registry/index/ |
| 91 | + ~/.cargo/registry/cache/ |
| 92 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} |
| 93 | + |
81 | 94 | # We use toolchain descriptors ("msrv", "stable", and "nightly") in the
|
82 | 95 | # matrix. This step converts the current descriptor to a particular
|
83 | 96 | # toolchain version by looking up the corresponding key in `Cargo.toml`. It
|
@@ -358,3 +371,33 @@ jobs:
|
358 | 371 | | tee -a $GITHUB_STEP_SUMMARY >&2
|
359 | 372 | exit 1
|
360 | 373 | fi
|
| 374 | +
|
| 375 | + generate_cache: |
| 376 | + runs-on: ubuntu-latest |
| 377 | + name: Generate cache |
| 378 | + steps: |
| 379 | + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 |
| 380 | + |
| 381 | + - uses: actions/cache@v3 |
| 382 | + with: |
| 383 | + path: | |
| 384 | + ~/.cargo/registry/index/ |
| 385 | + ~/.cargo/registry/cache/ |
| 386 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} |
| 387 | + |
| 388 | + - name: Populate cache |
| 389 | + run: | |
| 390 | + # Ensure all dependencies are downloaded - both for our crates and for tools |
| 391 | + # we use in CI. We don't care about these tools succeeding for two reasons: |
| 392 | + # First, this entire job is best-effort since it's just a performance optimization. |
| 393 | + # Second, there may be failures due to issues other than failing to download |
| 394 | + # dependencies (e.g., `cargo metadata` called with a malformed `Cargo.toml`, |
| 395 | + # build failure in our own crate or in dependencies, etc). For those reasons, |
| 396 | + # we discard stderr and ignore status codes. |
| 397 | + # |
| 398 | + # For downloading our crates' dependencies in particular, note that there is |
| 399 | + # no support for doing this directly [1], so we just check all crates using --tests. |
| 400 | + # |
| 401 | + # [1] https://stackoverflow.com/a/42139535/836390 |
| 402 | + cargo check --workspace --tests &> /dev/null || true |
| 403 | + cargo metadata &> /dev/null || true |
0 commit comments