-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Composite Action to reduce duplication
- Loading branch information
Showing
3 changed files
with
63 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: CI Rust Setup | ||
description: 'Sets up the environment for Rust jobs during CI workflow' | ||
|
||
inputs: | ||
cache-name: | ||
description: 'Name of cache artifacts (same name is same cache key) empty to disable cache' | ||
required: false | ||
targets: | ||
description: 'A comma separated list of extra targets you want to install' | ||
required: false | ||
components: | ||
description: 'A comma separated list of extra components you want to install' | ||
required: false | ||
toolchain: | ||
description: 'The toolchain to use. If not specified, the rust-toolchain file will be used' | ||
required: false | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Get toolchain from input OR rust-toolchain file | ||
id: gettoolchain | ||
shell: bash | ||
run: |- | ||
RUST_TOOLCHAIN="${{ inputs.toolchain }}" | ||
if [ ! -f rust-toolchain ] && [ -z "${RUST_TOOLCHAIN}" ]; then | ||
echo "***ERROR*** NEED toolchain INPUT OR rust-toolchain FILE IN ROOT OF REPOSITORY" >&2 | ||
exit 1 | ||
fi | ||
if [ -z "${RUST_TOOLCHAIN}" ]; then | ||
RUST_TOOLCHAIN="$(cat rust-toolchain)" | ||
fi | ||
echo "toolchain=\"${RUST_TOOLCHAIN}\"" >> $GITHUB_OUTPUT | ||
- name: Install ${{ steps.gettoolchain.outputs.toolchain }} Rust toolchain | ||
id: toolchain | ||
# Commit date is Sep 19, 2023 | ||
uses: dtolnay/rust-toolchain@439cf607258077187679211f12aa6f19af4a0af7 | ||
with: | ||
toolchain: ${{ steps.gettoolchain.outputs.toolchain }} | ||
targets: ${{ inputs.targets }} | ||
components: ${{ inputs.components }} | ||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
if: inputs.cache-name != '' | ||
with: | ||
path: | | ||
~/.cargo/registry | ||
~/.cargo/git | ||
target | ||
key: ${{ runner.os }}-cargo-${{ inputs.cache-name }}-${{ steps.toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,25 +13,19 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- id: toolchain | ||
uses: dtolnay/[email protected] | ||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
- name: Setup Rust | ||
uses: './.github/actions/ci-rust-setup' | ||
with: | ||
path: | | ||
~/.cargo/registry | ||
~/.cargo/git | ||
target | ||
key: ${{ runner.os }}-cargo-${{ steps.toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }} | ||
cache-name: dev | ||
- run: cargo check --all-features | ||
|
||
fmt: | ||
name: Formatter | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- id: toolchain | ||
uses: dtolnay/rust-[email protected] | ||
- name: Setup Rust | ||
uses: './.github/actions/ci-rust-setup' | ||
with: | ||
components: rustfmt | ||
- run: cargo fmt --all -- --check | ||
|
@@ -41,16 +35,10 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- id: toolchain | ||
uses: dtolnay/[email protected] | ||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: # test cache key is different (adding test cfg is a re-compile) | ||
path: | | ||
~/.cargo/registry | ||
~/.cargo/git | ||
target | ||
key: ${{ runner.os }}-cargo-test-${{ steps.toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }} | ||
- name: Setup Rust | ||
uses: './.github/actions/ci-rust-setup' | ||
with: | ||
cache-name: test | ||
- run: cargo test --lib --all-features | ||
|
||
clippy: | ||
|
@@ -67,17 +55,10 @@ jobs: | |
] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- id: toolchain | ||
uses: dtolnay/rust-[email protected] | ||
- name: Setup Rust | ||
uses: './.github/actions/ci-rust-setup' | ||
with: | ||
cache-name: dev | ||
components: clippy | ||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cargo/registry | ||
~/.cargo/git | ||
target | ||
key: ${{ runner.os }}-cargo-${{ steps.toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }} | ||
- name: Clippy with Features = ${{ matrix.features }} | ||
run: cargo clippy ${{ matrix.features }} -- -D warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.70 |