name: Publish to crates.io
on:
push:
tags:
- 'v*'
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
key: publish
- name: Verify tag matches Cargo.toml
run: |
CARGO_VERSION=$(grep -m1 '^version = ' Cargo.toml | cut -d '"' -f2)
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
echo "::error::Cargo.toml version ($CARGO_VERSION) != tag ($TAG_VERSION)"
exit 1
fi
echo "version=$CARGO_VERSION" >> "$GITHUB_ENV"
- name: Skip if version already on crates.io
id: check
run: |
status=$(curl -sf -A "winx-ci/1.0" \
"https://crates.io/api/v1/crates/winx-code-agent/${{ env.version }}" \
-o /dev/null -w "%{http_code}" || true)
if [ "$status" = "200" ]; then
echo "winx-code-agent ${{ env.version }} already exists on crates.io — skipping"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Cargo publish
if: steps.check.outputs.skip != 'true'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish --locked