name: Publish
on:
push:
tags:
- 'v*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: |
TAG="${GITHUB_REF#refs/tags/v}"
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*= *"\(.*\)".*/\1/')
if [ "$TAG" != "$CARGO_VERSION" ]; then
echo "ERROR: git tag v$TAG does not match Cargo.toml version $CARGO_VERSION"
exit 1
fi
- run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*= *"\(.*\)".*/\1/')
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://crates.io/api/v1/crates/drain3/$VERSION")
if [ "$STATUS" = "200" ]; then
echo "ERROR: drain3 $VERSION already exists on crates.io"
exit 1
fi
- run: echo "${{ secrets.CARGO_REGISTRY_TOKEN }}" | cargo login
- run: cargo publish