Skip to content

Commit

Permalink
chore(ci): add crates.io publishing workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
t00ts committed Jan 22, 2025
1 parent 8f5f4c2 commit cdc6d15
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/publish-crates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Publish Crates

on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish (without v prefix)'
required: true
type: string

permissions:
contents: read

jobs:
publish-crates:
name: Publish crates to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# Update versions in Cargo.toml files
- name: Update crate versions
run: |
VERSION=${{ inputs.version }}
# Update version in each Cargo.toml
for crate in common crypto serde class-hash; do
# Update the package version
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" "crates/$crate/Cargo.toml"
# Also update any internal dependencies to use the same version
sed -i "s/{ path = \"..\/common\" }/{ version = \"$VERSION\" }/" "crates/$crate/Cargo.toml"
sed -i "s/{ path = \"..\/crypto\" }/{ version = \"$VERSION\" }/" "crates/$crate/Cargo.toml"
sed -i "s/{ path = \"..\/serde\" }/{ version = \"$VERSION\" }/" "crates/$crate/Cargo.toml"
done
- uses: dtolnay/rust-toolchain@stable

# Verify all crates build and test before publishing
- name: Verify crates
run: |
cargo test -p pathfinder-crypto
cargo test -p pathfinder-common
cargo test -p pathfinder-serde
cargo test -p pathfinder-class-hash
- name: Login to crates.io
run: cargo login ${{ secrets.CRATES_IO_TOKEN }}

# Publish crates in dependency order with retries
- name: Publish crates
run: |
publish_with_retry() {
local package=$1
local max_attempts=3
local attempt=1
while [ $attempt -le $max_attempts ]; do
echo "Attempting to publish $package (attempt $attempt/$max_attempts)"
if cargo publish -p $package; then
return 0
fi
attempt=$((attempt + 1))
[ $attempt -le $max_attempts ] && sleep 30
done
return 1
}
# First publish crypto as it has no internal dependencies
publish_with_retry pathfinder-crypto
sleep 30
# Publish common which depends on crypto
publish_with_retry pathfinder-common
sleep 30
# Publish serde which depends on common and crypto
publish_with_retry pathfinder-serde
sleep 30
# Finally publish class-hash which depends on common, crypto and serde
publish_with_retry pathfinder-class-hash
15 changes: 15 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,18 @@ jobs:
target: ${{ matrix.target }}
profile: release-lto
token: ${{ secrets.GITHUB_TOKEN }}

publish-crates:
name: Publish crates to crates.io
needs: upload-assets
runs-on: ubuntu-latest
steps:
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- uses: ./.github/workflows/publish-crates.yml
with:
version: ${{ steps.version.outputs.version }}

0 comments on commit cdc6d15

Please sign in to comment.