Attempt to improve sccacheability (#2010)

Attempt to speed up CI builds:
1. Disable incremental builds when using `sccache` (incremental can't be cached)
2. Set `--locked` on all invocations of cargo
3. Add `restore-keys` for Github cache action
This commit is contained in:
George Pollard 2022-06-15 09:49:57 +12:00 committed by GitHub
parent 447f1813b1
commit ab1e422d34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 17 deletions

View File

@ -12,7 +12,7 @@ env:
CARGO_TERM_COLOR: always
SCCACHE_DIR: ${{github.workspace}}/sccache/
SCCACHE_CACHE_SIZE: 1G
ACTIONS_CACHE_KEY_DATE: 2021-08-26-01
ACTIONS_CACHE_KEY_DATE: 2022-06-02-01
CI: true
jobs:
@ -40,6 +40,9 @@ jobs:
sccache
src/agent/target
key: agent-${{ runner.os }}-${{ hashFiles('src/agent/Cargo.lock') }}-${{ env.ACTIONS_CACHE_KEY_DATE }}
restore-keys: |
agent-${{ runner.os }}-${{ hashFiles('src/agent/Cargo.lock') }}-
agent-${{ runner.os }}-
- name: Linux Prereqs
run: |
sudo apt-get -y update
@ -203,6 +206,9 @@ jobs:
sccache
src/proxy-manager/target
key: proxy-${{ runner.os }}-${{ hashFiles('src/proxy-manager/Cargo.lock') }}-${{ env.ACTIONS_CACHE_KEY_DATE }}
restore-keys: |
proxy-${{ runner.os }}-${{ hashFiles('src/proxy-manager/Cargo.lock') }}-
proxy-${{ runner.os }}-
- run: src/ci/proxy.sh
- uses: actions/upload-artifact@v2.2.2
with:

View File

@ -9,22 +9,26 @@ exists() {
[ -e "$1" ]
}
# only set RUSTC_WRAPPER if sccache exists
if sccache --help; then
export RUSTC_WRAPPER=$(which sccache)
fi
# only set CARGO_INCREMENTAL on non-release builds
#
# This speeds up build time, but makes the resulting binaries slightly slower.
# https://doc.rust-lang.org/cargo/reference/profiles.html?highlight=incremental#incremental
if [ "${GITHUB_REF}" != "" ]; then
TAG_VERSION=${GITHUB_REF#refs/tags/}
if [ ${TAG_VERSION} == ${GITHUB_REF} ]; then
export CARGO_INCREMENTAL=1
SCCACHE=$(which sccache || echo '')
if [ ! -z "$SCCACHE" ]; then
# only set RUSTC_WRAPPER if sccache exists
export RUSTC_WRAPPER=$SCCACHE
# incremental interferes with (disables) sccache
export CARGO_INCREMENTAL=0
else
# only set CARGO_INCREMENTAL on non-release builds
#
# This speeds up build time, but makes the resulting binaries slightly slower.
# https://doc.rust-lang.org/cargo/reference/profiles.html?highlight=incremental#incremental
if [ "${GITHUB_REF}" != "" ]; then
TAG_VERSION=${GITHUB_REF#refs/tags/}
if [ ${TAG_VERSION} == ${GITHUB_REF} ]; then
export CARGO_INCREMENTAL=1
fi
fi
fi
mkdir -p artifacts/agent-$(uname)
cd src/agent
@ -51,16 +55,20 @@ cargo fmt -- --check
cargo audit --deny warnings --deny unmaintained --deny unsound --deny yanked --ignore RUSTSEC-2020-0016 --ignore RUSTSEC-2020-0036 --ignore RUSTSEC-2019-0036 --ignore RUSTSEC-2021-0065 --ignore RUSTSEC-2020-0159 --ignore RUSTSEC-2020-0071 --ignore RUSTSEC-2020-0077
cargo-license -j > data/licenses.json
cargo build --release --locked
cargo clippy --release --all-targets -- -D warnings
cargo clippy --release --locked --all-targets -- -D warnings
# export RUST_LOG=trace
export RUST_BACKTRACE=full
cargo test --release --workspace
cargo test --release --locked --workspace
# TODO: re-enable integration tests.
# cargo test --release --manifest-path ./onefuzz-task/Cargo.toml --features integration_test -- --nocapture
# TODO: once Salvo is integrated, this can get deleted
cargo build --release --manifest-path ./onefuzz-telemetry/Cargo.toml --all-features
cargo build --release --locked --manifest-path ./onefuzz-telemetry/Cargo.toml --all-features
if [ ! -z "$SCCACHE" ]; then
sccache --show-stats
fi
cp target/release/onefuzz-task* ../../artifacts/agent-$(uname)
cp target/release/onefuzz-agent* ../../artifacts/agent-$(uname)