ghostty-pane-splitter 0.2.1

CLI tool to split panes on Ghostty Terminal
name: Release

on:
  push:
    branches: [main]
    paths:
      - "Cargo.toml"

env:
  CARGO_TERM_COLOR: always

jobs:
  check-version:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.version.outputs.version }}
      changed: ${{ steps.check.outputs.changed }}
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - name: Get version from Cargo.toml
        id: version
        run: |
          VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"
      - name: Check if tag already exists
        id: check
        run: |
          if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
            echo "changed=false" >> "$GITHUB_OUTPUT"
          else
            echo "changed=true" >> "$GITHUB_OUTPUT"
          fi

  build:
    needs: check-version
    if: needs.check-version.outputs.changed == 'true'
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v2
      - name: Install libxdo-dev (Linux)
        if: runner.os == 'Linux'
        run: sudo apt-get update && sudo apt-get install -y libxdo-dev
      - name: Build
        run: cargo build --release --target ${{ matrix.target }}
      - name: Archive
        run: |
          cd target/${{ matrix.target }}/release
          tar czf ../../../ghostty-pane-splitter-${{ matrix.target }}.tar.gz ghostty-pane-splitter
      - uses: actions/upload-artifact@v7
        with:
          name: ghostty-pane-splitter-${{ matrix.target }}
          path: ghostty-pane-splitter-${{ matrix.target }}.tar.gz

  release:
    needs: [check-version, build]
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v6
      - name: Create tag
        run: |
          git tag "v${{ needs.check-version.outputs.version }}"
          git push origin "v${{ needs.check-version.outputs.version }}"
      - uses: actions/download-artifact@v8
        with:
          merge-multiple: true
      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: v${{ needs.check-version.outputs.version }}
          generate_release_notes: true
          files: ghostty-pane-splitter-*.tar.gz

  publish-crate:
    needs: [check-version, release]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - name: Install libxdo-dev
        run: sudo apt-get update && sudo apt-get install -y libxdo-dev
      - name: Publish to crates.io
        run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  update-homebrew:
    needs: [check-version, release]
    runs-on: ubuntu-latest
    steps:
      - name: Update Homebrew formula
        uses: peter-evans/repository-dispatch@v4
        with:
          token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
          repository: rikeda71/homebrew-tap
          event-type: update-formula
          client-payload: '{"version": "${{ needs.check-version.outputs.version }}"}'