fix: ensure automated release (#27) #2
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 and Publish | ||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: 'Version to publish (without v prefix)' | ||
| required: true | ||
| type: string | ||
| env: | ||
| CARGO_TERM_COLOR: always | ||
| jobs: | ||
| test: | ||
| uses: ./.github/workflows/ci.yml | ||
|
Check failure on line 19 in .github/workflows/release.yml
|
||
| validate: | ||
| name: Validate Release | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| version: ${{ steps.version.outputs.version }} | ||
| steps: | ||
| - name: Checkout sources | ||
| uses: actions/checkout@v6 | ||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@stable | ||
| - name: Cache cargo registry | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.cargo/registry | ||
| ~/.cargo/git | ||
| target | ||
| key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }} | ||
| - name: Extract version | ||
| id: version | ||
| run: | | ||
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | ||
| VERSION="${{ github.event.inputs.version }}" | ||
| else | ||
| VERSION=${GITHUB_REF#refs/tags/v} | ||
| fi | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| echo "Extracted version: $VERSION" | ||
| - name: Verify version matches Cargo.toml | ||
| run: | | ||
| CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | ||
| if [[ "$CARGO_VERSION" != "${{ steps.version.outputs.version }}" ]]; then | ||
| echo "Version mismatch: Cargo.toml has $CARGO_VERSION, but release is ${{ steps.version.outputs.version }}" | ||
| exit 1 | ||
| fi | ||
| publish: | ||
| name: Publish to crates.io | ||
| runs-on: ubuntu-latest | ||
| needs: [test, validate] | ||
| environment: release | ||
| steps: | ||
| - name: Checkout sources | ||
| uses: actions/checkout@v6 | ||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@stable | ||
| - name: Cache cargo registry | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.cargo/registry | ||
| ~/.cargo/git | ||
| target | ||
| key: ${{ runner.os }}-cargo-publish-${{ hashFiles('**/Cargo.lock') }} | ||
| - name: Login to crates.io | ||
| run: cargo login ${{ secrets.CRATES_IO_TOKEN }} | ||
| - name: Publish to crates.io | ||
| run: cargo publish | ||