Publish #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish | |
on: | |
push: | |
tags: | |
- v[0-9]+.* | |
jobs: | |
publish: | |
name: Publish to crates.io | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
- name: Cache dependencies | |
uses: Swatinem/rust-cache@v2 | |
- name: Run tests | |
run: cargo test | |
- name: Check version matches tag | |
run: | | |
PKG_VERSION=$(cargo pkgid | cut -d# -f2 | cut -d: -f2) | |
TAG_VERSION=${GITHUB_REF#refs/tags/v} | |
if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then | |
echo "Version mismatch: Tag version ($TAG_VERSION) doesn't match Cargo.toml version ($PKG_VERSION)" | |
exit 1 | |
fi | |
- name: Publish to crates.io | |
run: cargo publish | |
env: | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
generate_release_notes: true |