Skip to content

Instantly share code, notes, and snippets.

@nukopy
Created May 25, 2024 17:09
Show Gist options
  • Save nukopy/6cfa89c8c4b6d625c33755bebd092d06 to your computer and use it in GitHub Desktop.
Save nukopy/6cfa89c8c4b6d625c33755bebd092d06 to your computer and use it in GitHub Desktop.
CI workflow in Rust projects on GitHub Actions
name: CI
on:
push:
branches:
- main
paths-ignore:
- "**.md"
- ".gitignore"
pull_request:
types: [opened, synchronize, reopened]
paths-ignore:
- "**.md"
- ".gitignore"
env:
RUST_VERSION: 1.78.0
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUST_BACKTRACE: short
RUSTFLAGS: "-D warnings"
RUSTUP_MAX_RETRIES: 10
# support macOS 10.7 (Lion) and later
# MACOSX_DEPLOYMENT_TARGET: 10.7
jobs:
format:
name: Format with rustfmt
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Setup rustfmt
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Run format
run: cargo fmt --all -- --check
lint:
name: Lint with clippy
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Setup clippy
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Save / Restore cache
uses: Swatinem/rust-cache@v2
- name: Run lint
run: cargo clippy
# Ensure that the project could be successfully compiled
cargo_check:
name: Compile
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
# os: [ubuntu-latest, macOS-latest, windows-latest]
os: [ ubuntu-latest ]
rust: [ ${ { env.RUST_VERSION } } ]
needs: [format, lint]
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchains
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
- name: Save / Restore cache
uses: Swatinem/rust-cache@v2
- name: Run cargo check
run: cargo check --workspace --locked
# Run tests
test:
name: Test
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
# os: [ubuntu-latest, macOS-latest, windows-latest]
os: [ ubuntu-latest ]
rust: [ ${ { env.RUST_VERSION } } ]
needs: [cargo_check]
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchains
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Save / Restore cache
uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo test --verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment