name: Release
on:
push:
tags:
- 'v*.*.*'
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Verify version matches tag
run: |
TAG=${GITHUB_REF#refs/tags/v}
CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
if [ "$TAG" != "$CARGO_VERSION" ]; then
echo "Tag version ($TAG) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
- name: Run tests
run: cargo test --all --verbose
- name: Run clippy
run: cargo clippy --all-targets -- -D warnings
- name: Build release
run: cargo build --release --verbose
- name: Check if version already published
id: check_published
run: |
CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
if cargo search zfish --limit 1 | grep -q "zfish = \"$CARGO_VERSION\""; then
echo "published=true" >> $GITHUB_OUTPUT
echo "Version $CARGO_VERSION is already published on crates.io"
else
echo "published=false" >> $GITHUB_OUTPUT
echo "Version $CARGO_VERSION is not yet published"
fi
- name: Publish dry-run
if: steps.check_published.outputs.published == 'false'
run: cargo publish --dry-run
- name: Publish to crates.io
if: steps.check_published.outputs.published == 'false'
run: |
echo "📦 Publishing zfish to crates.io..."
cargo publish --token ${{ secrets.CARGO_TOKEN }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
- name: Verify publication
if: steps.check_published.outputs.published == 'false'
run: |
echo "✅ Successfully published to crates.io!"
echo "📦 View at: https://crates.io/crates/zfish"
- name: Skip publishing
if: steps.check_published.outputs.published == 'true'
run: echo "⏭️ Skipping publish - version already exists on crates.io"
- name: Create package artifact
if: steps.check_published.outputs.published == 'false'
run: |
echo "📦 Creating package artifact..."
cargo package --list
# Create artifacts directory
mkdir -p artifacts
# Copy the packaged crate
CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
cp target/package/zfish-${CARGO_VERSION}.crate artifacts/
# Create checksums
cd artifacts
sha256sum zfish-${CARGO_VERSION}.crate > zfish-${CARGO_VERSION}.crate.sha256
cd ..
- name: Upload package to release
if: steps.check_published.outputs.published == 'false'
uses: softprops/action-gh-release@v2
with:
files: |
artifacts/zfish-*.crate
artifacts/zfish-*.sha256
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ github.ref_name }}
body: |
Release ${{ github.ref_name }}
See [CHANGELOG.md](https://github.com/JeetKarena/ZFish/blob/main/CHANGELOG.md) for details.
draft: false
prerelease: false