* Speed up index fetches on CI Use the `sparse` protocol from Rust 1.68.0 which should shave a minute or two off most steps on CI. * Update nightly toolchains in CI prtest:full * Fix date
93 lines
3.7 KiB
YAML
93 lines
3.7 KiB
YAML
name: 'Install Rust toolchain'
|
|
description: 'Install a rust toolchain and cache the crates index'
|
|
|
|
inputs:
|
|
toolchain:
|
|
description: 'Default toolchan to install'
|
|
required: false
|
|
default: 'stable'
|
|
lockfiles:
|
|
description: 'Path glob for Cargo.lock files to use as cache keys'
|
|
required: false
|
|
default: '**/Cargo.lock'
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
|
|
- name: Install Rust
|
|
shell: bash
|
|
run: |
|
|
rustup set profile minimal
|
|
rustup update "${{ inputs.toolchain }}" --no-self-update
|
|
rustup default "${{ inputs.toolchain }}"
|
|
|
|
# Save disk space by avoiding incremental compilation. Also turn down
|
|
# debuginfo from 2 to 1 to help save disk space.
|
|
cat >> "$GITHUB_ENV" <<EOF
|
|
CARGO_INCREMENTAL=0
|
|
CARGO_PROFILE_DEV_DEBUG=1
|
|
CARGO_PROFILE_TEST_DEBUG=1
|
|
EOF
|
|
|
|
# Deny warnings on CI to keep our code warning-free as it lands in-tree.
|
|
# Don't do this on nightly though, since there's a fair amount of
|
|
# warning churn there.
|
|
if [[ "${{ inputs.toolchain }}" != nightly* ]]; then
|
|
echo RUSTFLAGS="-D warnings" >> "$GITHUB_ENV"
|
|
fi
|
|
|
|
if [[ "${{ runner.os }}" = "macOS" ]]; then
|
|
cat >> "$GITHUB_ENV" <<EOF
|
|
CARGO_PROFILE_DEV_SPLIT_DEBUGINFO=unpacked
|
|
CARGO_PROFILE_TEST_SPLIT_DEBUGINFO=unpacked
|
|
EOF
|
|
fi
|
|
|
|
# Use a more efficient method for fetching the crates.io-index than
|
|
# the (currently) default git-based index.
|
|
cat >> "$GITHUB_ENV" <<EOF
|
|
CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
|
|
EOF
|
|
|
|
- name: Choose registry cache key
|
|
shell: bash
|
|
# Update the registry index cache at most once per day. actions/cache
|
|
# won't write changes back to the cache if the cache key already exists,
|
|
# so this means every job may have to re-download the index entries which
|
|
# are new since the last time the cache key changed. Changing the cache
|
|
# key relatively frequently keeps the amount of duplicated work down. But
|
|
# changing it too frequently means we might hit the 10GB quota too
|
|
# quickly, which would cause GitHub to evict other caches we still want.
|
|
run: echo CARGO_REGISTRY_CACHE_KEY=$(date +%Y%m%d) >> $GITHUB_ENV
|
|
|
|
- name: Cache Cargo registry index
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.cargo/registry/index/
|
|
key: cargo-registry-${{ env.CARGO_REGISTRY_CACHE_KEY }}
|
|
# Any older registry-index cache is still valid. It's a git clone, so
|
|
# cargo only has to pull down the changes since the index was cached.
|
|
restore-keys: cargo-registry-
|
|
|
|
- name: Cache crate sources for dependencies
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/cache/
|
|
~/.cargo/git/db/
|
|
key: cargo-crates-${{ inputs.lockfiles }}-${{ hashFiles(inputs.lockfiles) }}
|
|
# If Cargo.lock has changed, we probably will need to get the source
|
|
# code for some crates we don't already have. But any crates we have
|
|
# source cached for are still valid. The only problem is nothing
|
|
# removes old crate sources from the cache, so using `restore-keys`
|
|
# this way may use more of our GitHub cache quota than we'd like.
|
|
#
|
|
# Also, scope this cache by which Cargo.lock we're building from.
|
|
# Otherwise, whichever job writes the cache first will get its
|
|
# dependencies cached, and that cache will be used as the basis for the
|
|
# next job, even though odds are pretty good the cache is useless.
|
|
restore-keys: cargo-crates-${{ inputs.lockfiles }}-
|
|
|
|
# TODO: on cache miss, after cargo has updated the registry index, run `git gc`
|