Skip to content

chore: update dependency versions across workspace #17

chore: update dependency versions across workspace

chore: update dependency versions across workspace #17

name: Publish Crates to crates.io
on:
push:
branches:
- main
paths:
- 'hanzo-libs/*/Cargo.toml'
- '.github/workflows/publish-crates.yml'
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
changed-crates: ${{ steps.detect.outputs.crates }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Detect changed crate versions
id: detect
run: |
# Get list of changed Cargo.toml files
CHANGED_TOMLS=$(git diff HEAD^ HEAD --name-only | grep 'hanzo-libs/.*/Cargo.toml' || true)
if [ -z "$CHANGED_TOMLS" ]; then
echo "No Cargo.toml changes detected"
echo "crates=[]" >> $GITHUB_OUTPUT
exit 0
fi
# Extract crate names and check for version changes
CRATES="["
FIRST=true
for TOML in $CHANGED_TOMLS; do
CRATE_DIR=$(dirname $TOML)
CRATE_NAME=$(basename $CRATE_DIR)
# Check if version changed
VERSION_CHANGED=$(git diff HEAD^ HEAD $TOML | grep '^+version = ' || true)
if [ -n "$VERSION_CHANGED" ]; then
if [ "$FIRST" = false ]; then
CRATES="$CRATES,"
fi
CRATES="$CRATES\"$CRATE_NAME\""
FIRST=false
echo "Detected version change in: $CRATE_NAME"
fi
done
CRATES="$CRATES]"
echo "crates=$CRATES" >> $GITHUB_OUTPUT
echo "Changed crates: $CRATES"
publish:
needs: detect-changes
if: needs.detect-changes.outputs.changed-crates != '[]'
runs-on: ubuntu-latest
strategy:
matrix:
crate: ${{ fromJson(needs.detect-changes.outputs.changed-crates) }}
fail-fast: false
max-parallel: 1 # Publish one at a time to respect dependencies
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Verify crate builds
working-directory: hanzo-libs/${{ matrix.crate }}
run: cargo build --release
- name: Run tests
working-directory: hanzo-libs/${{ matrix.crate }}
run: cargo test --all-features
continue-on-error: true # Don't fail publish if tests fail
- name: Publish to crates.io
working-directory: hanzo-libs/${{ matrix.crate }}
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
continue-on-error: true # Continue even if already published
- name: Wait for crates.io to update
run: sleep 30 # Give crates.io time to index the new version
notify:
needs: [detect-changes, publish]
if: always()
runs-on: ubuntu-latest
steps:
- name: Summary
run: |
echo "## Crate Publication Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Changed crates: ${{ needs.detect-changes.outputs.changed-crates }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.publish.result }}" == "success" ]; then
echo "✅ All crates published successfully" >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ Some crates may have failed to publish" >> $GITHUB_STEP_SUMMARY
fi