name: Publish
on:
workflow_dispatch:
inputs:
dry_run:
description: "Run publish checks without uploading to crates.io"
required: true
default: true
type: boolean
permissions:
contents: read
jobs:
publish:
name: Publish crate
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Check
run: cargo check --locked
- name: Test
run: cargo test --locked
- name: Package
run: cargo package --locked
- name: Publish dry run
if: ${{ inputs.dry_run }}
run: cargo publish --locked --dry-run
- name: Check crates.io token
if: ${{ !inputs.dry_run }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
if [ -z "${CARGO_REGISTRY_TOKEN}" ]; then
echo "CARGO_REGISTRY_TOKEN is not configured."
exit 1
fi
- name: Publish to crates.io
if: ${{ !inputs.dry_run }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked