kinjo 0.2.0

Kinjo: mDNS TUI and commands launch for local network services
Documentation
name: Publish macOS binaries

# Builds native tarballs for both Apple Silicon and Intel Macs, for a Homebrew
# formula to point at. Cross-compiling x86_64-apple-darwin from the arm64
# runner works out of the box: Apple's SDK/linker support both targets from
# either host, so a single macOS runner builds both without extra toolchains.

on:
  release:
    types: [created]
  workflow_dispatch:

permissions:
  contents: write
  actions: write # required for the `gh workflow run` dispatch below

env:
  CARGO_TERM_COLOR: always

jobs:
  macos:
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v7

      - uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 #v2.9.1

      - name: Add Rust targets
        run: rustup target add aarch64-apple-darwin x86_64-apple-darwin

      - name: Build and package both targets
        run: |
          version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
          for target in aarch64-apple-darwin x86_64-apple-darwin; do
            cargo build --release --locked --verbose --target "$target"
            name="kinjo-${version}-${target}"
            mkdir -p "$name/commands"
            cp "target/${target}/release/kinjo" "$name/"
            cp README.md LICENSE "$name/"
            cp actions/*.toml "$name/commands/"
            tar -czf "${name}.tar.gz" "$name"
          done

      - name: Upload packages to release
        env:
          GH_TOKEN: ${{ github.token }}
        # github.event.release is only set for the `release` trigger; fall back
        # to the checked-out ref when dispatched manually (see prepare-release.yml).
        run: gh release upload "${{ github.event.release.tag_name || github.ref_name }}" kinjo-*.tar.gz --clobber

      - name: Update the Homebrew tap
        env:
          GH_TOKEN: ${{ github.token }}
        # The tap workflow cannot listen for this run's completion itself:
        # this workflow is dispatched with GITHUB_TOKEN, whose activity emits
        # no workflow-triggering events, so dispatch the update explicitly now
        # that the tarballs the formula hashes are uploaded. A run from a
        # branch rather than a release tag has nothing to sync.
        run: |
          tag="${{ github.event.release.tag_name || github.ref_name }}"
          case "$tag" in
            v*) gh workflow run update-homebrew-tap.yml --ref main -f tag="$tag" ;;
            *)  echo "Not a release tag ($tag); skipping the tap update." ;;
          esac