Skip to content

Workflow file for this run

name: Publish release to Crates.io
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
on:
push:
tags:
- 'v*' # Only match version tags
env:
CARGO_TERM_COLOR: always
jobs:
build-test:
name: Build and test (${{ matrix.os }})
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: "build-cache"
- name: Build
run: cargo build --locked --verbose
- name: Run tests
run: cargo test --verbose
publish:
name: Publish to crates.io
needs: build-test
runs-on: ubuntu-latest
environment: crates.io
permissions:
contents: write # This is required for creating releases
issues: write # Optional: allows release notes to reference issues
pull-requests: write # Optional: allows release notes to reference PRs
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: "publish-cache"
- name: Extract version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ steps.get_version.outputs.VERSION }}
generate_release_notes: true
- name: Publish to crates.io
run: cargo publish --locked --verbose --token ${{ secrets.CARGO_REGISTRY_TOKEN }}