Skip to content

Commit

Permalink
Use Composite Action to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
junderw committed Nov 11, 2023
1 parent 9d6e266 commit 7f828cd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 31 deletions.
50 changes: 50 additions & 0 deletions .github/actions/ci-rust-setup/action.yml
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') }}
43 changes: 12 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.70

0 comments on commit 7f828cd

Please sign in to comment.