name: CI
on:
pull_request:
push:
branches:
- "**"
tags:
- "v*"
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
ci:
name: Check, test, and package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Cache Cargo
uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --all --check
- name: Lint default feature set
run: cargo clippy --locked --all-targets -- -D warnings
- name: Test default feature set
run: cargo test --locked
- name: Lint Tokio async feature set
run: cargo clippy --locked --no-default-features --features tokio_async --all-targets -- -D warnings
- name: Test Tokio async feature set
run: cargo test --locked --no-default-features --features tokio_async
- name: Verify crate package
run: cargo package --locked
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: ci
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Cargo
uses: Swatinem/rust-cache@v2
- name: Check tag matches Cargo.toml version
shell: bash
run: |
package_version="$(cargo pkgid | sed -E 's/.*[#@]//')"
tag_version="${GITHUB_REF_NAME#v}"
if [ "$package_version" != "$tag_version" ]; then
echo "::error::Tag version $tag_version does not match Cargo.toml version $package_version"
exit 1
fi
- name: Publish crate
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked --token "$CARGO_REGISTRY_TOKEN"