actr-cli 0.1.15

Command line tool for Actor-RTC framework projects
Documentation
name: Release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:
    inputs:
      version:
        description: "Version to release (e.g., 0.1.5)"
        required: false
        type: string

env:
  CARGO_TERM_COLOR: always

jobs:
  meta:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    outputs:
      version: ${{ steps.vars.outputs.version }}
      tag: ${{ steps.vars.outputs.tag }}
    steps:
      - name: Resolve version
        id: vars
        run: |
          version_input="${{ inputs.version }}"
          if [ -n "$version_input" ]; then
            version="$version_input"
          else
            version="${GITHUB_REF_NAME}"
          fi
          version="${version#v}"
          if [ -z "$version" ]; then
            echo "Version is required." >&2
            exit 1
          fi
          tag="v${version}"
          echo "version=$version" >> "$GITHUB_OUTPUT"
          echo "tag=$tag" >> "$GITHUB_OUTPUT"

  build:
    needs: meta
    runs-on: macos-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: aarch64-apple-darwin

      - name: Install protoc
        uses: arduino/setup-protoc@v3

      - uses: Swatinem/rust-cache@v2

      - name: Build release asset
        run: scripts/build-release.sh "${{ needs.meta.outputs.version }}"

      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: dist-macos-arm64
          path: dist/actr-${{ needs.meta.outputs.version }}-macos-arm64*
          if-no-files-found: error

  release:
    needs: [meta, build]
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          pattern: dist-macos-arm64
          path: dist
          merge-multiple: true

      - name: Publish GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.meta.outputs.tag }}
          name: ${{ needs.meta.outputs.tag }}
          target_commitish: ${{ github.sha }}
          generate_release_notes: true
          files: dist/*

  update-brew:
    needs: [meta, release]
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v4

      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          pattern: dist-macos-arm64
          path: dist
          merge-multiple: true

      - name: Update Homebrew formula
        env:
          GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
        run: |
          VERSION="${{ needs.meta.outputs.version }}"
          SHA256=$(cat dist/actr-${VERSION}-macos-arm64.tar.gz.sha256)
          ASSET="actr-${VERSION}-macos-arm64.tar.gz"
          URL="https://github.com/actor-rtc/actr-cli/releases/download/v${VERSION}/${ASSET}"
          
          # Clone the tap repository
          git clone https://x-access-token:${GH_TOKEN}@github.com/actor-rtc/homebrew-tap.git tap
          
          # Update the formula file
          FORMULA="tap/Formula/actr-cli.rb"
          rm -f "tap/Formula/actr.rb"
          cat > "$FORMULA" <<EOF
          class ActrCli < Formula
            desc "Actr CLI"
            homepage "https://github.com/actor-rtc/actr-cli"
            version "${VERSION}"
            license "MIT"
          
            on_macos do
              on_arm do
                url "${URL}"
                sha256 "${SHA256}"
              end
            end
          
            def install
              bin.install "actr"
            end
          end
          EOF
          
          # Commit and push
          cd tap
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add .
          git commit -m "actr ${VERSION}" || echo "No changes to commit"
          git push