name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 0.3.0)"
required: true
type: string
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
id-token: write
jobs:
release:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- name: Validate version format
run: |
if ! echo "${{ inputs.version }}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$'; then
echo "Error: Invalid version format '${{ inputs.version }}'. Expected semver (e.g. 0.3.0)"
exit 1
fi
- name: Bump version in Cargo.toml
run: sed -i 's/^version = ".*"/version = "${{ inputs.version }}"/' Cargo.toml
- name: Verify version was updated
run: grep -q "^version = \"${{ inputs.version }}\"" Cargo.toml
- name: Commit and push version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Cargo.toml
git commit -m "bump version to ${{ inputs.version }}"
git push
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: Publish to crates.io
run: cargo publish --allow-dirty --no-verify
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}