Publish to crates.io #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # See https://crates.io/docs/trusted-publishing | |
| name: Publish to crates.io | |
| on: | |
| push: | |
| tags: ['v*'] | |
| workflow_dispatch: {} | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| id-token: write # Required for OIDC token exchange | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: rust-lang/crates-io-auth-action@v1 | |
| id: auth | |
| - run: | | |
| # Publish crates if their current version is not already on crates.io. | |
| # Order matters: dependencies must be published first. | |
| CRATES="utils mount blockdev" | |
| for dir in $CRATES; do | |
| manifest="crates/$dir/Cargo.toml" | |
| crate=$(cargo read-manifest --manifest-path "$manifest" | jq -r '.name') | |
| VERSION=$(cargo read-manifest --manifest-path "$manifest" | jq -r '.version') | |
| if cargo info --registry crates-io "$crate@$VERSION" > /dev/null 2>&1; then | |
| echo "$crate@$VERSION is already published, skipping" | |
| else | |
| echo "Publishing $crate@$VERSION..." | |
| cargo publish -p "$crate" | |
| echo "Successfully published $crate@$VERSION" | |
| fi | |
| done | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} |