From 381a5bf260dfc261b0ef7cb2035245ca575767dd Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Wed, 17 Jan 2024 00:26:33 +0200 Subject: [PATCH] ci: try out the sccache for caching rust code --- .github/workflows/ci.yml | 90 ++++++++++--------- Justfile | 2 +- ...rage-wrapper.sh => coverage-wrapper-rustc} | 0 3 files changed, 47 insertions(+), 45 deletions(-) rename scripts/{rustc-coverage-wrapper.sh => coverage-wrapper-rustc} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4556e9d80ae..f1e687b4bfc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,11 +51,10 @@ jobs: tool: just,cargo-nextest,cargo-llvm-cov # Setup the dependency rust cache and llvm-cov - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 - with: - prefix-key: "0" # change this to invalidate CI cache - shared-key: "cargo_nextest-${{ matrix.cache_id }}" - save-if: "${{ github.event_name == 'merge_group' }}" # save the cache only from master CI + - uses: mozilla-actions/sccache-action@1e15924c00ed1446db9e44e8f02628488e7258ec + - run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV # Run the tests - run: just codecov "nextest-unit ${{ matrix.type }}" @@ -95,14 +94,14 @@ jobs: - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 with: tool: cargo-llvm-cov - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 - with: - prefix-key: "0" # change this to invalidate CI cache - shared-key: "cargo_nextest-linux" - save-if: "false" # use the cache from nextest, but don’t double-save + - uses: mozilla-actions/sccache-action@1e15924c00ed1446db9e44e8f02628488e7258ec + - run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV - run: pip3 install --user -r pytest/requirements.txt - run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV" - - run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV" + - run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/coverage-wrapper-rustc" >> "$GITHUB_ENV" + - run: echo "CARGO=1" >> "$GITHUB_ENV" - run: cargo build --locked --profile dev-release -p neard --bin neard - run: echo "CURRENT_NEARD=$PWD/target/dev-release/neard" >> "$GITHUB_ENV" - run: cd pytest && python3 tests/sanity/backward_compatible.py @@ -124,14 +123,14 @@ jobs: - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 with: tool: cargo-llvm-cov - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 - with: - prefix-key: "0" # change this to invalidate CI cache - shared-key: "cargo_nextest-linux" - save-if: "false" # use the cache from nextest, but don’t double-save + - uses: mozilla-actions/sccache-action@1e15924c00ed1446db9e44e8f02628488e7258ec + - run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV - run: pip3 install --user -r pytest/requirements.txt - run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV" - - run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV" + - run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/coverage-wrapper-rustc" >> "$GITHUB_ENV" + - run: echo "CARGO=1" >> "$GITHUB_ENV" - run: cargo build --locked --profile dev-release -p neard --bin neard - run: echo "CURRENT_NEARD=$PWD/target/dev-release/neard" >> "$GITHUB_ENV" - run: echo "NEAR_ROOT=$PWD" >> "$GITHUB_ENV" @@ -157,16 +156,16 @@ jobs: - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 with: tool: cargo-llvm-cov - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 - with: - prefix-key: "0" # change this to invalidate CI cache - shared-key: "cargo_nextest-linux" - save-if: "false" # use the cache from nextest, but don’t double-save + - uses: mozilla-actions/sccache-action@1e15924c00ed1446db9e44e8f02628488e7258ec + - run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV - run: pip3 install --user -r pytest/requirements.txt # This is the only job that uses `--features nightly` so we build this in-line instead of a # separate job like done with the regular neard. - run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV" - - run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV" + - run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/coverage-wrapper-rustc" >> "$GITHUB_ENV" + - run: echo "CARGO=1" >> "$GITHUB_ENV" - run: cargo build --profile dev-release -p neard --bin neard --features nightly # Note: We're not running spin_up_cluster.py for non-nightly # because spinning up non-nightly clusters is already covered @@ -192,14 +191,14 @@ jobs: - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 with: tool: cargo-llvm-cov - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 - with: - prefix-key: "0" # change this to invalidate CI cache - shared-key: "cargo_nextest-linux" - save-if: "false" # use the cache from nextest, but don’t double-save + - uses: mozilla-actions/sccache-action@1e15924c00ed1446db9e44e8f02628488e7258ec + - run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV - run: pip3 install --user -r pytest/requirements.txt - run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV" - - run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV" + - run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/coverage-wrapper-rustc" >> "$GITHUB_ENV" + - run: echo "CARGO=1" >> "$GITHUB_ENV" - run: cargo build --locked --profile dev-release -p neard --bin neard - run: echo "CURRENT_NEARD=$PWD/target/dev-release/neard" >> "$GITHUB_ENV" - run: python3 scripts/state/update_res.py check @@ -236,14 +235,14 @@ jobs: - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 with: tool: cargo-llvm-cov - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 - with: - prefix-key: "0" # change this to invalidate CI cache - shared-key: "cargo_nextest-linux" - save-if: "false" # use the cache from nextest, but don’t double-save + - uses: mozilla-actions/sccache-action@1e15924c00ed1446db9e44e8f02628488e7258ec + - run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV - run: pip3 install --user -r pytest/requirements.txt - run: cargo llvm-cov show-env | grep -v RUSTFLAGS | tr -d "'" >> "$GITHUB_ENV" - - run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/rustc-coverage-wrapper.sh" >> "$GITHUB_ENV" + - run: echo "RUSTC_WORKSPACE_WRAPPER=$PWD/scripts/coverage-wrapper-rustc" >> "$GITHUB_ENV" + - run: echo "CARGO=1" >> "$GITHUB_ENV" - run: cargo build --locked --profile dev-release -p neard --bin neard - run: echo "CURRENT_NEARD=$PWD/target/dev-release/neard" >> "$GITHUB_ENV" - run: cd pytest && python3 tests/sanity/upgradable.py @@ -258,9 +257,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 - with: - save-if: "${{ github.event_name == 'merge_group' }}" # save the cache only from master CI + - uses: mozilla-actions/sccache-action@1e15924c00ed1446db9e44e8f02628488e7258ec + - run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 with: tool: just @@ -293,9 +293,10 @@ jobs: - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 with: tool: just - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 - with: - save-if: "${{ github.event_name == 'merge_group' }}" # save the cache only from master CI + - uses: mozilla-actions/sccache-action@1e15924c00ed1446db9e44e8f02628488e7258ec + - run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV - run: just check-cargo-clippy check_cargo_deny: @@ -336,9 +337,10 @@ jobs: - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 with: tool: just,cargo-udeps - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 - with: - save-if: "${{ github.event_name == 'merge_group' }}" # save the cache only from master CI + - uses: mozilla-actions/sccache-action@1e15924c00ed1446db9e44e8f02628488e7258ec + - run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV - run: just check-cargo-udeps cargo_audit: diff --git a/Justfile b/Justfile index 963225910a5..d9423a349fb 100644 --- a/Justfile +++ b/Justfile @@ -94,7 +94,7 @@ codecov RULE: # TODO: remove the RUSTFLAGS hack, see also https://github.com/rust-lang/cargo/issues/13040 cargo llvm-cov show-env --export-prefix | grep -v RUSTFLAGS > env source ./env - export RUSTC_WORKSPACE_WRAPPER="{{ absolute_path("scripts/rustc-coverage-wrapper.sh") }}" + export RUSTC_WORKSPACE_WRAPPER="{{ absolute_path("scripts/coverage-wrapper-rustc") }}" {{ just_executable() }} {{ RULE }} cargo llvm-cov report --profile dev-release --codecov --output-path codecov.json # See https://github.com/taiki-e/cargo-llvm-cov/issues/292 diff --git a/scripts/rustc-coverage-wrapper.sh b/scripts/coverage-wrapper-rustc similarity index 100% rename from scripts/rustc-coverage-wrapper.sh rename to scripts/coverage-wrapper-rustc