name: Publish crate
on:
workflow_dispatch:
inputs:
ref:
description: Commit containing the package to publish
required: true
type: string
version:
description: Expected crate version
required: true
type: string
permissions:
contents: read
jobs:
publish:
runs-on: ubuntu-22.04
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATE_TOKEN }}
steps:
- name: Verify crates.io token
run: test -n "$CARGO_REGISTRY_TOKEN"
- name: Checkout package
uses: actions/checkout@v6
with:
ref: ${{ inputs.ref }}
persist-credentials: false
submodules: recursive
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Publish crate
shell: bash
run: |
set -euo pipefail
version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "lucy-cli") | .version')"
if [[ "$version" != "${{ inputs.version }}" ]]; then
echo "expected lucy-cli ${{ inputs.version }}, found ${version}" >&2
exit 1
fi
if cargo info --registry crates-io "lucy-cli@${version}" >/dev/null 2>&1; then
echo "lucy-cli ${version} is already published"
else
cargo publish --locked
fi