name: Cargo Release
on:
workflow_dispatch:
push:
tags:
- 'v*.*.*'
env:
CARGO_TERM_COLOR: always
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Read version from Cargo.toml
id: cargo_version
run: |
VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Verify tag matches Cargo.toml (tag)
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
CARGO_VERSION=${{ steps.cargo_version.outputs.version }}
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) doesn't match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
- name: Show release version
run: echo "Releasing version ${{ steps.cargo_version.outputs.version }}"
- name: Check documentation
run: cargo doc --no-deps --all-features
- name: Publish dry-run
run: cargo publish --dry-run
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}