name: Publish to crates.io
on:
workflow_run:
workflows: ["Test"]
branches: [master]
types:
- completed
push:
tags:
- "v*"
jobs:
publish:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Generate Cargo.lock if missing
run: cargo generate-lockfile
- run: |
PKGID=$(cargo pkgid)
VERSION=${PKGID##*:}
echo "Checking if version $VERSION is already published"
if cargo search --limit 1 "$(grep '^name' Cargo.toml | cut -d'"' -f2)" | grep -q "$VERSION"; then
echo "Version $VERSION is already published on crates.io. Aborting."
exit 1
fi
echo "Publishing version $VERSION"
cargo publish --locked --token ${{ secrets.CARGO_REGISTRY_TOKEN }}