name: Main
on: [push, pull_request]
jobs:
clippy:
name: Check for common code mistakes
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v3.0.2
-
uses: actions-rs/toolchain@v1.0.6
with:
toolchain: stable
-
uses: Swatinem/rust-cache@v1.3.0
-
name: Run clippy
run: cargo clippy -- -D warnings
fmt:
name: Check code format
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v3.0.2
-
uses: actions-rs/toolchain@v1.0.6
with:
toolchain: stable
-
uses: Swatinem/rust-cache@v1.3.0
-
name: Run rustfmt
run: cargo fmt --all -- --check
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
args:
- --release
- --release --all-features
steps:
-
uses: actions/checkout@v3.0.2
-
uses: actions-rs/toolchain@v1.0.6
with:
profile: minimal
toolchain: stable
-
uses: Swatinem/rust-cache@v1.3.0
-
name: Run tests
run: cargo test ${{ matrix.args }}
cargo-deny:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.0.2
- uses: EmbarkStudios/cargo-deny-action@v1.2.15
create-release-pr:
name: Conditionally create release PR
needs: [clippy, cargo-deny, test]
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
permissions:
contents: write
pull-requests: write
steps:
-
name: Create a release Pull Request
uses: google-github-actions/release-please-action@v3.2.1
with:
release-type: rust
command: release-pr
bump-minor-pre-major: true
publish:
name: Conditionally publish to crates.io
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
permissions:
contents: write
pull-requests: write
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
steps:
-
uses: google-github-actions/release-please-action@v3.2.1
id: release
with:
release-type: rust
command: github-release
-
uses: actions/checkout@v3.0.2
if: ${{ steps.release.outputs.release_created }}
-
name: Tag major and minor versions in Git
if: ${{ steps.release.outputs.release_created }}
uses: jacobsvante/tag-major-minor-action@v0
with:
major: ${{ steps.release.outputs.major }}
minor: ${{ steps.release.outputs.minor }}
-
name: Make cargo command available
if: ${{ steps.release.outputs.release_created }}
uses: actions-rs/toolchain@v1.0.6
with:
toolchain: stable
-
uses: Swatinem/rust-cache@v1.3.0
- if: ${{ steps.release.outputs.release_created }}
run: cargo publish