Skip to content

Commit

Permalink
CI: Improve GitHub actions (#669)
Browse files Browse the repository at this point in the history
Moves Rust & CI setup to an action so it can be reused. Splits
previously sequential build -> clippy -> test steps to individual jobs
so they can be executed in parallel.

The changes improve organization of the CI pipeline and reduce execution
time.

Relates to #48.
  • Loading branch information
Indy2222 authored Aug 8, 2023
1 parent 2da4df7 commit 8ed2249
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 44 deletions.
47 changes: 47 additions & 0 deletions .github/actions/rust/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Rust Setup

inputs:
name:
required: true
type: string
components:
required: false
type: string

runs:
using: 'composite'
steps:
- shell: bash
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y libasound2-dev libudev-dev
- shell: bash
run: "git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id"

- uses: actions/cache@v3
with:
path: .git/lfs
key: rust-lfs-${{ inputs.name }}-${{ hashFiles('.lfs-assets-id') }}-v1

- shell: bash
run: git lfs pull

- uses: dtolnay/rust-toolchain@stable
id: rust-toolchain
with:
components: ${{ inputs.components }}

- shell: bash
run: rustc --version && cargo --version

- uses: actions/cache@v3
id: rust-cache
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: rust-cargo-${{ inputs.name }}-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}-v1
79 changes: 35 additions & 44 deletions .github/workflows/rust.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rust
name: Test & Check

on:
push:
Expand All @@ -21,59 +21,50 @@ env:

jobs:
build:
name: Build & Test
name: Build
if: github.event.pull_request.draft == false
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Restore LFS cache
uses: actions/cache@v3
- name: Checkout
uses: actions/checkout@v3
- uses: ./.github/actions/rust
name: Setup
with:
path: .git/lfs
key: lfs-${{ runner.os }}-${{ hashFiles('.lfs-assets-id') }}-v1
- name: Git LFS Pull
run: git lfs pull
name: test-build
- name: Build
run: cargo build --verbose --all-targets --all-features --locked

- uses: dtolnay/rust-toolchain@stable
clippy:
name: Clippy
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./.github/actions/rust
name: Setup
with:
name: clippy
components: clippy

- name: Rust Cache
uses: actions/cache@v3
id: rust-cache
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: tests-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
tests-${{ runner.os }}-
- name: Install Linux Dependencies
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y libasound2-dev libudev-dev
- run: rustc --version && cargo --version && cargo clippy --version
- name: Build
run: cargo build --verbose --all-targets --all-features --locked
- name: Clippy
run: cargo clippy --all --all-targets --all-features --workspace -- --deny warnings

test:
name: Test
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./.github/actions/rust
name: Setup
with:
name: test
- name: Test
run: cargo test --verbose --all-features --workspace

format:
name: Test Formatting
name: Formatting
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
Expand All @@ -85,7 +76,7 @@ jobs:
- run: cargo +nightly fmt --all -- --check

udeps:
name: Check Unused Dependencies
name: Unused Deps
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
Expand All @@ -110,7 +101,7 @@ jobs:
run: cargo udeps

comments:
name: Check Code Comments
name: Code Comments
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down

0 comments on commit 8ed2249

Please sign in to comment.