Release Crates #1
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
| name: Release Crates | |
| on: | |
| push: | |
| tags: | |
| - "v*.*.*" | |
| workflow_dispatch: | |
| inputs: | |
| dry-run: | |
| description: "Perform a dry run without actually publishing" | |
| required: false | |
| type: boolean | |
| default: false | |
| jobs: | |
| publish-crates: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| toolchain: stable | |
| - name: Cache Cargo dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-release- | |
| ${{ runner.os }}-cargo- | |
| - name: Verify version matches tag | |
| if: github.event_name == 'push' | |
| run: | | |
| TAG_VERSION="${GITHUB_REF#refs/tags/v}" | |
| CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)".*/\1/') | |
| if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then | |
| echo "❌ Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)" | |
| exit 1 | |
| fi | |
| echo "✅ Version check passed: $TAG_VERSION" | |
| - name: Run tests | |
| run: cargo test --all --locked | |
| - name: Verify package can be built | |
| run: cargo package --locked --allow-dirty | |
| - name: Publish to crates.io (dry-run) | |
| if: github.event_name == 'workflow_dispatch' && inputs.dry-run | |
| run: cargo publish --dry-run --locked | |
| - name: Publish to crates.io | |
| if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !inputs.dry-run) | |
| uses: katyo/publish-crates@v2 | |
| with: | |
| registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| ignore-unpublished-changes: true | |
| - name: Create GitHub Release | |
| if: github.event_name == 'push' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| generate_release_notes: true | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |