name: Publish to crates.io
on:
push:
tags:
- "v*.*.*"
jobs:
publish:
runs-on: ubuntu-latest
if: "! contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v3
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Install Dependencies
run: rustup component add clippy rustfmt
- name: Validate Cargo.toml Version
id: version_check
run: |
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
CARGO_VERSION=$(grep ^version Cargo.toml | sed 's/version = "\(.*\)"/\1/')
echo "tag_version=${TAG_VERSION}" >> $GITHUB_OUTPUT
echo "cargo_version=${CARGO_VERSION}" >> $GITHUB_OUTPUT
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Tag version ($TAG_VERSION) and Cargo.toml version ($CARGO_VERSION) do not match."
exit 1
fi
- name: Build
run: cargo build --verbose
- name: Run Tests
run: cargo test --all --verbose
- name: Lint
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Format Check
run: cargo fmt --all -- --check
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish --verbose