ci(cd): fix crates.io and npm publish failures #14
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
| # Automatic release workflow | |
| # Creates a release tag when releasable commits are merged to main | |
| # | |
| # Repo variables: | |
| # AUTO_RELEASE_ENABLED: set to 'true' to enable automatic releases | |
| # AUTO_RELEASE_DRY_RUN: set to 'true' to log what would happen without creating tags | |
| name: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| dry_run: | |
| description: "Dry run (log only, don't create tags)" | |
| type: boolean | |
| default: false | |
| concurrency: | |
| group: release-${{ github.ref }} | |
| cancel-in-progress: false | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| check-release: | |
| name: Check for release | |
| if: vars.AUTO_RELEASE_ENABLED == 'true' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| outputs: | |
| should_release: ${{ steps.check.outputs.should_release }} | |
| next_version: ${{ steps.check.outputs.next_version }} | |
| changelog: ${{ steps.changelog.outputs.content }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get latest tag | |
| id: latest_tag | |
| run: | | |
| tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
| echo "tag=${tag}" >> $GITHUB_OUTPUT | |
| - name: Install git-cliff | |
| uses: ./.github/actions/setup-cargo-tools | |
| with: | |
| binstall-tools: git-cliff | |
| - name: Check for releasable commits | |
| id: check | |
| run: | | |
| # Get the bumped version from git-cliff | |
| next_version=$(git cliff --bumped-version 2>/dev/null || echo "") | |
| if [ -z "$next_version" ]; then | |
| echo "No version bump detected" | |
| echo "should_release=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| current_tag="${{ steps.latest_tag.outputs.tag }}" | |
| if [ "$next_version" = "$current_tag" ]; then | |
| echo "Already at version $next_version" | |
| echo "should_release=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "Will release: $current_tag -> $next_version" | |
| echo "should_release=true" >> $GITHUB_OUTPUT | |
| echo "next_version=${next_version}" >> $GITHUB_OUTPUT | |
| - name: Generate changelog | |
| if: steps.check.outputs.should_release == 'true' | |
| id: changelog | |
| run: | | |
| content=$(git cliff --config cliff.toml -vv --unreleased --strip all 2>/dev/null) | |
| { | |
| echo "content<<CHANGELOG_EOF" | |
| echo "$content" | |
| echo "CHANGELOG_EOF" | |
| } >> $GITHUB_OUTPUT | |
| create-release: | |
| name: Create release | |
| needs: check-release | |
| if: needs.check-release.outputs.should_release == 'true' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure git | |
| uses: ./.github/actions/bot-setup | |
| - name: Dry run | |
| if: inputs.dry_run == true || vars.AUTO_RELEASE_DRY_RUN == 'true' | |
| run: | | |
| echo "=== DRY RUN ===" | |
| echo "Would create tag: ${{ needs.check-release.outputs.next_version }}" | |
| echo "" | |
| echo "Changelog:" | |
| echo "${{ needs.check-release.outputs.changelog }}" | |
| - name: Create and push tag | |
| if: inputs.dry_run != true && vars.AUTO_RELEASE_DRY_RUN != 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| version="${{ needs.check-release.outputs.next_version }}" | |
| echo "Creating tag: ${version}" | |
| git tag -a "${version}" -m "Release ${version}" | |
| git push origin "${version}" | |
| echo "✅ Tag ${version} created and pushed" | |
| echo "The CD workflow will now build and publish the release." | |