name: Publish to crates.io
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Release tag (e.g. v0.1.0)"
required: true
dry_run:
description: "Dry run (do not publish)"
type: boolean
default: false
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- name: Resolve tag and version
id: release
shell: bash
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
TAG="${{ github.event.release.tag_name }}"
else
TAG="${{ github.event.inputs.tag }}"
fi
VERSION="${TAG#v}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ steps.release.outputs.tag }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
key: publish
- name: Verify Cargo.toml version matches tag
shell: bash
run: |
CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 \
| jq -r '.packages[] | select(.name == "proses") | .version')
TAG_VERSION="${{ steps.release.outputs.version }}"
echo "Cargo.toml version : ${CARGO_VERSION}"
echo "Release tag version: ${TAG_VERSION}"
if [[ "${CARGO_VERSION}" != "${TAG_VERSION}" ]]; then
echo "::error::Version mismatch — bump version in Cargo.toml before releasing."
exit 1
fi
- name: Run tests
shell: bash
run: cargo test --locked
- name: Publish
shell: bash
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
if [[ "${{ github.event.inputs.dry_run }}" == "true" ]]; then
echo "Dry run — package will not be published."
cargo publish --locked --dry-run
else
cargo publish --locked
fi