tauri-typegen 0.5.2

A rust crate that automatically generates TypeScript models and bindings from your Tauri commands
Documentation
name: CD

on:
  workflow_dispatch:
    inputs:
      version_bump:
        description: 'Version bump type'
        required: true
        type: choice
        options:
          - major
          - minor
          - patch
        default: 'patch'

permissions:
  contents: write

env:
  # crates.io's data-access policy requires a User-Agent identifying the caller
  # with a contact. https://crates.io/data-access
  CRATES_USER_AGENT: "tauri-typegen-release (+https://github.com/thwbh/tauri-typegen)"

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Install cargo-edit
        run: cargo install cargo-edit --locked

      - name: Get latest version from crates.io
        id: current_version
        run: |
          LATEST_VERSION=$(curl -sf -H "User-Agent: ${CRATES_USER_AGENT}" \
            https://crates.io/api/v1/crates/tauri-typegen | jq -r '.crate.max_stable_version')
          if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" = "null" ]; then
            echo "Failed to fetch latest version from crates.io" >&2
            exit 1
          fi
          echo "Latest published version: $LATEST_VERSION"
          echo "current_version=$LATEST_VERSION" >> "$GITHUB_OUTPUT"

      - name: Compute new version
        id: bump_version
        run: |
          CURRENT="${{ steps.current_version.outputs.current_version }}"
          case "${{ github.event.inputs.version_bump }}" in
            major) NEW_VERSION=$(echo "$CURRENT" | awk -F. '{print $1+1".0.0"}') ;;
            minor) NEW_VERSION=$(echo "$CURRENT" | awk -F. '{print $1"."$2+1".0"}') ;;
            patch) NEW_VERSION=$(echo "$CURRENT" | awk -F. '{print $1"."$2"."$3+1}') ;;
          esac
          echo "New version: $NEW_VERSION"
          echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"

      - name: Extract release notes from CHANGELOG.md
        id: release_notes
        run: |
          VERSION="${{ steps.bump_version.outputs.new_version }}"
          # Pull the section between "## [VERSION]" and the next "## [" header,
          # trimming leading and trailing blank lines.
          NOTES=$(awk -v ver="$VERSION" '
            $0 ~ "^## \\[" ver "\\]" { flag=1; next }
            flag && /^## \[/ { exit }
            flag {
              if (!started && $0 ~ /^[[:space:]]*$/) next
              started=1; buf[n++]=$0
            }
            END {
              while (n>0 && buf[n-1] ~ /^[[:space:]]*$/) n--
              for (i=0;i<n;i++) print buf[i]
            }
          ' CHANGELOG.md)
          if [ -z "$NOTES" ]; then
            echo "No CHANGELOG.md section found for version $VERSION." >&2
            echo "Add a '## [$VERSION] - <date>' entry before releasing." >&2
            exit 1
          fi
          # Write outside the checkout so the working tree stays clean for
          # `cargo publish` (which refuses to package a dirty tree).
          printf '%s\n' "$NOTES" > "${RUNNER_TEMP}/release_notes.md"
          echo "Extracted release notes for $VERSION:"
          cat "${RUNNER_TEMP}/release_notes.md"

      - name: Set version in Cargo.toml
        # set-version overwrites whatever is in the local (intentionally stale)
        # Cargo.toml — this change is never committed back, so github-actions
        # does not appear in the contributor list.
        run: cargo set-version "${{ steps.bump_version.outputs.new_version }}"

      - name: Build and test
        run: |
          cargo build --release
          cargo test

      - name: Publish to crates.io
        run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}

      - name: Create GitHub Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh release create "${{ steps.bump_version.outputs.new_version }}" \
            --title "${{ steps.bump_version.outputs.new_version }}" \
            --notes-file "${RUNNER_TEMP}/release_notes.md"