iwatchr 0.1.1

Cross-platform CLI file watcher that re-runs a command on every file change
Documentation
name: Release

on:
  release:
    types: [created]

permissions:
  contents: write   # needed to upload release assets

jobs:
  # ── Build cross-platform binaries ─────────────────────────────────────────
  build:
    name: Build — ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux x86-64 (native)
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            use_cross: false

          # Linux ARM64 (cross-compiled via cross-rs)
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            use_cross: true

          # macOS Intel
          - target: x86_64-apple-darwin
            os: macos-latest
            use_cross: false

          # macOS Apple Silicon (native on M-series runner)
          - target: aarch64-apple-darwin
            os: macos-latest
            use_cross: false

          # Windows x86-64
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            use_cross: false

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Cache Cargo registry & build artefacts
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-${{ matrix.target }}-cargo-

      - name: Install cross (Linux ARM64 only)
        if: matrix.use_cross
        run: cargo install cross --git https://github.com/cross-rs/cross

      - name: Build release binary
        run: |
          if [ "${{ matrix.use_cross }}" = "true" ]; then
            cross build --release --target ${{ matrix.target }}
          else
            cargo build --release --target ${{ matrix.target }}
          fi
        shell: bash

      # ── Package ─────────────────────────────────────────────────────────────

      - name: Package — Unix (tar.gz)
        if: runner.os != 'Windows'
        run: |
          BINARY=target/${{ matrix.target }}/release/iwatchr
          ARCHIVE=iwatchr-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
          tar -czf "$ARCHIVE" -C "$(dirname $BINARY)" "$(basename $BINARY)"
          echo "ASSET=$ARCHIVE" >> "$GITHUB_ENV"
        shell: bash

      - name: Package — Windows (zip)
        if: runner.os == 'Windows'
        run: |
          $binary = "target\${{ matrix.target }}\release\iwatchr.exe"
          $archive = "iwatchr-${{ github.ref_name }}-${{ matrix.target }}.zip"
          Compress-Archive -Path $binary -DestinationPath $archive
          "ASSET=$archive" | Out-File -FilePath $env:GITHUB_ENV -Append
        shell: pwsh

      # ── Upload to the GitHub Release ─────────────────────────────────────────

      - name: Upload release asset
        uses: softprops/action-gh-release@v2
        with:
          files: ${{ env.ASSET }}

  # ── Publish to crates.io (runs after all builds succeed) ──────────────────
  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Publish
        run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }}