audiorouter 0.1.5

Cross-platform command-line audio router with a terminal UI
name: Release

on:
  push:
    tags:
      - "v*"

concurrency:
  group: release-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  # ── Build cross-platform binaries ──────────────────────────────────
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux (native runners)
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            archive: tar.gz
          - os: ubuntu-24.04-arm
            target: aarch64-unknown-linux-gnu
            archive: tar.gz
          # macOS
          - os: macos-15          # ARM64
            target: aarch64-apple-darwin
            archive: tar.gz
          - os: macos-15-intel    # Intel
            target: x86_64-apple-darwin
            archive: tar.gz
          # Windows
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            archive: zip

    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0   # needed so git describe resolves the tag in build.rs

      - name: Set version env
        shell: bash
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          echo "APP_VERSION=${VERSION}" >> "$GITHUB_ENV"

      - name: Install ALSA headers (Linux)
        if: runner.os == 'Linux'
        run: sudo apt-get update && sudo apt-get install -y libasound2-dev

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 24
          cache: pnpm
          cache-dependency-path: crates/audiorouter-dashboard/dashboard/pnpm-lock.yaml

      - name: Install dashboard deps
        run: pnpm install --frozen-lockfile
        working-directory: crates/audiorouter-dashboard/dashboard

      - name: Install Rust target
        run: rustup target add ${{ matrix.target }}

      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

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

      - name: Package (Unix)
        if: matrix.archive == 'tar.gz'
        run: |
          mkdir -p dist
          cp target/${{ matrix.target }}/release/audiorouter dist/
          tar czf audiorouter-${{ matrix.target }}.tar.gz -C dist audiorouter

      - name: Package (Windows)
        if: matrix.archive == 'zip'
        shell: bash
        run: |
          mkdir -p dist
          cp target/${{ matrix.target }}/release/audiorouter.exe dist/
          cd dist && 7z a ../audiorouter-${{ matrix.target }}.zip audiorouter.exe

      - name: Upload artifact
        uses: actions/upload-artifact@v6
        with:
          name: audiorouter-${{ matrix.target }}
          path: audiorouter-${{ matrix.target }}.${{ matrix.archive }}
          retention-days: 7

  # ── Publish to crates.io ────────────────────────────────────────────
  publish-crates:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs: build
    permissions:
      id-token: write   # required for trusted publishing
    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0

      - name: Set version from tag
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          echo "Setting version to ${VERSION}"
          bash scripts/set-version.sh "${VERSION}"

      - name: Install ALSA headers
        run: sudo apt-get update && sudo apt-get install -y libasound2-dev

      - name: Authenticate to crates.io
        id: auth
        uses: rust-lang/crates-io-auth-action@v1

      - name: Publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          # publish in dependency order: core -> dashboard -> main
          for crate in audiorouter-core audiorouter-dashboard audiorouter; do
            if curl -fsS -A "audiorouter release workflow" \
                "https://crates.io/api/v1/crates/${crate}/${VERSION}" >/dev/null 2>&1; then
              echo "✓ ${crate} ${VERSION} already published; skipping"
              continue
            fi
            echo "→ publishing ${crate} ${VERSION}"
            cargo publish --no-verify --allow-dirty -p "${crate}"
          done

  # ── Create GitHub Release with all binary assets ────────────────────
  github-release:
    name: GitHub Release
    runs-on: ubuntu-latest
    needs: build
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v5

      - name: Download all artifacts
        uses: actions/download-artifact@v6
        with:
          path: artifacts
          merge-multiple: true

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          name: ${{ github.ref_name }}
          generate_release_notes: true
          files: artifacts/*