Skip to content

Commit

Permalink
🚦 Add composite action for caching cargo installs
Browse files Browse the repository at this point in the history
The `cargo install` commands are taking quite a while due to it
producing long build-times. This adds a caching mechanism to keep the
dependencies between builds so that installation times don't have to
suffer.
  • Loading branch information
bitwizeshift committed Dec 10, 2023
1 parent d370c2e commit 36119cc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .github/actions/cargo-install/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: cargo-install
description: "Performs a cargo install for the specified component, with caching"

inputs:
target:
required: true
description: "The component to install"

runs:
using: "composite"
steps:
- name: Cache installation
id: cargo-install
uses: actions/cache@v3
with:
path: .cargo/bin/${{ inputs.target }}
key: cargo-install-${{ inputs.target }}

- name: Update git submodules
if: steps.cargo-install.outputs.cache-hit != 'true'
shell: bash
run: |
mkdir -p .cargo/bin
cargo install --locked ${{ inputs.target }} --root ./.cargo
- name: Update PATH
shell: bash
run: |
echo "$(pwd)/.cargo/bin" >> "${GITHUB_PATH}"
22 changes: 18 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ jobs:
- name: Install toolchain
uses: ./.github/actions/rust-toolchain

- name: Install cargo-deny and cargo-about
run: cargo install --locked cargo-deny cargo-about
- name: Install cargo-deny
uses: ./.github/actions/cargo-install
with:
target: cargo-deny

- name: Install cargo-about
uses: ./.github/actions/cargo-install
with:
target: cargo-about

- name: Check cargo-deny
run: cargo deny check
Expand Down Expand Up @@ -98,8 +105,15 @@ jobs:
with:
components: clippy

- name: Install required cargo
run: cargo install clippy-sarif sarif-fmt
- name: Install clippy-sarif
uses: ./.github/actions/cargo-install
with:
target: clippy-sarif

- name: Install sarif-fmt
uses: ./.github/actions/cargo-install
with:
target: sarif-fmt

- name: Check clippy
continue-on-error: true
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ jobs:
rust: nightly

- name: Install mdbook
run: |
cargo install --locked mdbook
uses: ./.github/actions/cargo-install
with:
target: mdbook

- name: Install cargo-about
uses: ./.github/actions/cargo-install
with:
target: cargo-about

- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/Cargo.lock
/.cargo

0 comments on commit 36119cc

Please sign in to comment.