name: Rust CI & Release
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
env:
CARGO_TERM_COLOR: always
jobs:
setup:
name: Set up Rust Toolchain
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-target-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-target-
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy, rustfmt
lint:
name: Run Linter (Clippy and Formatter)
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run cargo fmt (check formatting)
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Run cargo clippy (check linting)
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
test:
name: Run Tests
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --all
coverage:
name: Code Coverage
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install cargo-tarpaulin
uses: actions-rs/install@v0.1
with:
crate: cargo-tarpaulin
version: latest
- name: Generate code coverage
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: --out Html
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
release:
name: Automated Release Tagging and Publishing
needs: [test, lint, coverage]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Git for tagging
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git config --global url."https://${{ secrets.GH_TOKEN }}@github.com/".insteadOf "https://github.com/"
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Install cargo-release
run: cargo install cargo-release
- name: Run cargo release (bump, tag, publish)
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo release patch --no-confirm --publish --execute