From a403c99d3f793fce7030e8c1b2c3a5eef0fc7dd0 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sun, 26 Mar 2023 17:28:35 +1100 Subject: [PATCH] Upgrade CI to use sccache v0.4.0 for caching (#934) Remove `mozilla-actions/sccache-action@v0.0.2` and instead use `taiki-ie/install-action` to install `sccache`, since we already use `taiki-e/install-action` for installing crates. This PR also refactor just-setup.yml and use pass `GITHUB_TOKEN` to `taiki-e/install-action` which uses `cargo-binstall` for installing `cargo-auditable` and `sccache`. Signed-off-by: Jiahao XU --- .github/actions/just-setup/action.yml | 38 ++++++++++++++++++++------- .github/workflows/ci.yml | 16 +++++++++++ .github/workflows/release-build.yml | 4 +++ 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/.github/actions/just-setup/action.yml b/.github/actions/just-setup/action.yml index 0d1405be..2da88d50 100644 --- a/.github/actions/just-setup/action.yml +++ b/.github/actions/just-setup/action.yml @@ -18,19 +18,30 @@ inputs: description: Suffix for cache key required: false default: "" + runs: using: composite steps: - - if: inputs.tools == '' - name: Install just + - name: Add just to tools to install + run: echo "tools=just" >>$GITHUB_ENV + shell: bash + + - if: inputs.buildcache + name: Add sccache to tools to install + run: echo "tools=$tools,sccache" >>$GITHUB_ENV + shell: bash + + - name: Add inputs.tools to tools to install + if: inputs.tools != '' + env: + inputs_tools: ${{ inputs.tools }} + run: echo "tools=$tools,$inputs_tools" >>$GITHUB_ENV + shell: bash + + - name: Install tools uses: taiki-e/install-action@v2 with: - tool: just - - if: inputs.tools != '' - name: Install just and tools - uses: taiki-e/install-action@v2 - with: - tool: just,${{ inputs.tools }} + tool: ${{ env.tools }} - if: inputs.indexcache name: Configure index cache @@ -55,9 +66,11 @@ runs: - if: inputs.buildcache name: Configure sccache - uses: mozilla-actions/sccache-action@v0.0.2 + uses: actions/github-script@v6 with: - version: "v0.4.0-pre.10" + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); - if: inputs.buildcache name: Export env for sccache to work @@ -66,3 +79,8 @@ runs: echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV + + - uses: webiny/action-post-run@3.0.0 + id: post-run-command + with: + run: sccache --show-stats diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2370a3c2..74d8e596 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,10 @@ jobs: - uses: ./.github/actions/just-setup with: cache-suffix: ${{ env.CARGO_BUILD_TARGET }} + env: + # just-setup use binstall to install sccache, + # which works better when we provide it with GITHUB_TOKEN. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: just ci-install-deps - run: just test @@ -78,6 +82,10 @@ jobs: - uses: ./.github/actions/just-setup with: cache-suffix: ${{ env.CARGO_BUILD_TARGET }} + env: + # just-setup use binstall to install sccache, + # which works better when we provide it with GITHUB_TOKEN. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: just ci-install-deps - run: just check @@ -92,6 +100,10 @@ jobs: - uses: ./.github/actions/just-setup with: cache-suffix: ${{ env.CARGO_BUILD_TARGET }} + env: + # just-setup use binstall to install sccache, + # which works better when we provide it with GITHUB_TOKEN. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: just check @@ -105,6 +117,10 @@ jobs: - uses: ./.github/actions/just-setup with: cache-suffix: ${{ env.CARGO_BUILD_TARGET }} + env: + # just-setup use binstall to install sccache, + # which works better when we provide it with GITHUB_TOKEN. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: just check diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 93ba0d59..0455d84d 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -45,6 +45,10 @@ jobs: with: cache-suffix: release-${{ matrix.t }} tools: cargo-auditable + env: + # just-setup use binstall to install sccache and cargo-auditable, + # which works better when we provide it with GITHUB_TOKEN. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: just toolchain rust-src - run: just ci-install-deps