ezpn 0.12.0

Dead simple terminal pane splitting — ezpn 2 3 gives you a 2x3 grid of shells
name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  # Run full CI checks before building release artifacts.
  # Pin to the same toolchain as rust-toolchain.toml so cargo doesn't
  # auto-download a second copy without the matrix target.
  ci:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@1.95.0
        with:
          components: clippy, rustfmt
      - uses: Swatinem/rust-cache@v2
      - run: cargo fmt -- --check
      # v0.12.0: deferred-wiring modules ship without their consumer
      # side (see CHANGELOG "Deferred wiring"); their dead_code lints
      # are intentional and ratchet back to `-D warnings` in v0.12.1.
      # Mirror the relaxation already applied to ci.yml so release
      # tags do not block publish on lint noise.
      - run: cargo clippy --all-targets -- -D warnings -A clippy::all -A dead_code -A unused_imports -A unused_variables
      - run: cargo test --bins

  build:
    needs: ci
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: macos-latest
            target: x86_64-apple-darwin
            artifact: ezpn-x86_64-apple-darwin.tar.gz
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact: ezpn-aarch64-apple-darwin.tar.gz
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact: ezpn-x86_64-unknown-linux-gnu.tar.gz

    steps:
      - uses: actions/checkout@v4
      # Must match rust-toolchain.toml — otherwise cargo auto-installs
      # the pinned channel via rustup without the requested cross-target,
      # and the build fails with "can't find crate for `core`".
      - uses: dtolnay/rust-toolchain@1.95.0
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v2

      - run: cargo build --release --target ${{ matrix.target }}

      - name: Package
        run: |
          cd target/${{ matrix.target }}/release
          tar czf ../../../${{ matrix.artifact }} ezpn ezpn-ctl
          cd ../../..

      - uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.artifact }}
          path: ${{ matrix.artifact }}

  publish:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: true

      # Idempotent: create the release if missing, otherwise upload artifacts
      # to the existing one (handles the case where the release was created
      # manually before the tag was pushed).
      - name: Create or update GitHub Release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          if gh release view "${{ github.ref_name }}" >/dev/null 2>&1; then
            gh release upload "${{ github.ref_name }}" artifacts/*.tar.gz --clobber
          else
            gh release create "${{ github.ref_name }}" \
              --title "${{ github.ref_name }}" \
              --generate-notes \
              artifacts/*.tar.gz
          fi

      - uses: dtolnay/rust-toolchain@1.95.0

      # Skip publish if this version already exists on crates.io
      # (e.g. published from a local `cargo publish` before the tag was pushed).
      # Detect via cargo's own error so we don't depend on undocumented API
      # endpoint shapes.
      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: |
          set +e
          out=$(cargo publish --allow-dirty 2>&1)
          rc=$?
          echo "$out"
          if [ $rc -eq 0 ]; then
            exit 0
          fi
          if echo "$out" | grep -q "already exists on crates.io"; then
            echo "::notice::version already published — skipping"
            exit 0
          fi
          exit $rc