sara-tasks 1.5.2

Sara — folder-aware task manager
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
  #
  # There is deliberately no `use-cross` input: it is not a valid input for
  # upload-rust-binary-action, which warned "Unexpected input(s) 'use-cross'"
  # and ignored it on every run. The action already installs and uses `cross`
  # by itself when the target needs it — the v1.4.0 aarch64-unknown-linux-gnu
  # asset was verified as a genuine `ELF 64-bit ARM aarch64` binary.
  binaries:
    needs: create-release
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: aarch64-apple-darwin
            os: macos-latest
    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
          checksum: sha256
          token: ${{ secrets.GITHUB_TOKEN }}

  # 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
          sha256sum "$deb" sara_amd64.deb > sara_amd64.deb.sha256
          gh release upload "${GITHUB_REF_NAME}" "$deb" sara_amd64.deb sara_amd64.deb.sha256 --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"