sara-tasks 0.2.2

Sara — folder-aware task manager (successor to tk)
name: Release

# Tag-driven releases. Bump the version in Cargo.toml, then:
#   git tag v0.2.0 && git push <remote> v0.2.0
on:
  push:
    tags:
      - "v*"
  workflow_dispatch:

permissions:
  contents: write

jobs:
  # Create the GitHub Release that the other jobs upload assets to.
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: taiki-e/create-gh-release-action@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

  # Cross-compiled binaries (tar.gz) for Linux + macOS, attached to the release.
  # Archive names match scripts/install.sh: sara-<target>.tar.gz
  binaries:
    needs: create-release
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            use-cross: false
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            use-cross: true
          - target: x86_64-apple-darwin
            os: macos-latest
            use-cross: false
          - target: aarch64-apple-darwin
            os: macos-latest
            use-cross: false
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - name: Build and upload
        uses: taiki-e/upload-rust-binary-action@v1
        with:
          bin: sara
          target: ${{ matrix.target }}
          archive: sara-$target
          token: ${{ secrets.GITHUB_TOKEN }}
          use-cross: ${{ matrix.use-cross }}

  # Debian package (.deb) for amd64. Uploaded both versioned (cargo-deb's name)
  # and as a stable `sara_amd64.deb` so the README's latest-download URL works.
  deb:
    needs: create-release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Install cargo-deb
        run: cargo install cargo-deb --locked
      - name: Build .deb
        run: cargo deb
      - name: Upload .deb to release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          deb="$(ls target/debian/*.deb | head -n1)"
          cp "$deb" sara_amd64.deb
          gh release upload "${GITHUB_REF_NAME}" "$deb" sara_amd64.deb --clobber

  # Publish to crates.io. No-op unless the CARGO_REGISTRY_TOKEN secret is set.
  crates-io:
    needs: create-release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Publish
        env:
          TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: |
          if [ -z "${TOKEN:-}" ]; then
            echo "CARGO_REGISTRY_TOKEN not set — skipping crates.io publish."
            exit 0
          fi
          cargo publish --token "$TOKEN"