mycelium-manager 0.7.0

A robust, production-grade task/plan manager CLI (binary: myc)
name: Release

# Builds the `myc` CLI binaries and the MycUI desktop app bundles for every
# platform and attaches them to the GitHub Release for the pushed tag.
# Triggered by version tags (the same tags used for the crate, e.g. v0.2.4).
on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

jobs:
  # ---- MycUI desktop bundles (Tauri) -------------------------------------
  mycui:
    name: MycUI (${{ matrix.platform }})
    strategy:
      fail-fast: false
      matrix:
        include:
          - platform: macos-latest   # Apple Silicon + Intel via universal
            args: "--target universal-apple-darwin"
          - platform: ubuntu-latest
            args: ""
          - platform: windows-latest
            args: ""
    runs-on: ${{ matrix.platform }}
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          # macOS universal build needs both arch targets.
          targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}

      - name: Install Bun
        uses: oven-sh/setup-bun@v2

      # Tauri's Linux bundler needs GTK/WebKit and friends.
      - name: Install Linux system deps
        if: matrix.platform == 'ubuntu-latest'
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libwebkit2gtk-4.1-dev \
            libappindicator3-dev \
            librsvg2-dev \
            patchelf \
            libgtk-3-dev

      - name: Install frontend deps
        working-directory: mycui
        run: bun install

      - name: Build + bundle MycUI and upload to the release
        uses: tauri-apps/tauri-action@v0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          projectPath: mycui
          tagName: ${{ github.ref_name }}
          releaseName: "Mycelium ${{ github.ref_name }}"
          releaseBody: "MycUI desktop app + `myc` CLI. See assets below."
          releaseDraft: false
          prerelease: false
          args: ${{ matrix.args }}

  # ---- myc CLI binaries --------------------------------------------------
  cli:
    name: myc CLI (${{ matrix.target }})
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: macos-latest
            target: aarch64-apple-darwin
          - os: macos-latest
            target: x86_64-apple-darwin
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - os: windows-latest
            target: x86_64-pc-windows-msvc
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4

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

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

      # Package the binary as a per-target archive so it uploads cleanly.
      - name: Package (unix)
        if: matrix.os != 'windows-latest'
        run: |
          bin="target/${{ matrix.target }}/release/myc"
          tar -czf "myc-${{ matrix.target }}.tar.gz" -C "$(dirname "$bin")" myc

      - name: Package (windows)
        if: matrix.os == 'windows-latest'
        run: |
          Compress-Archive -Path "target/${{ matrix.target }}/release/myc.exe" -DestinationPath "myc-${{ matrix.target }}.zip"

      - name: Upload CLI archive to the release
        uses: softprops/action-gh-release@v2
        with:
          files: |
            myc-${{ matrix.target }}.tar.gz
            myc-${{ matrix.target }}.zip
          fail_on_unmatched_files: false

  # ---- Homebrew tap formula ----------------------------------------------
  # Regenerate Formula/myc.rb in tcsenpai/homebrew-tap with fresh sha256s for
  # the tarballs the `cli` job just published, then push it to the tap.
  # Requires a repo secret HOMEBREW_TAP_TOKEN: a PAT (or fine-grained token)
  # with contents:write on tcsenpai/homebrew-tap.
  brew:
    name: Update Homebrew tap
    needs: cli
    runs-on: ubuntu-latest
    steps:
      - name: Compute checksums and render formula
        env:
          REPO: ${{ github.repository }}
          TAG: ${{ github.ref_name }}
        run: |
          set -euo pipefail
          version="${TAG#v}"
          base="https://github.com/$REPO/releases/download/$TAG"

          fetch_sha() {
            curl -fsSL "$base/$1" -o "$1"
            sha256sum "$1" | cut -d' ' -f1
          }
          sha_arm_mac=$(fetch_sha "myc-aarch64-apple-darwin.tar.gz")
          sha_x86_mac=$(fetch_sha "myc-x86_64-apple-darwin.tar.gz")
          sha_x86_linux=$(fetch_sha "myc-x86_64-unknown-linux-gnu.tar.gz")

          mkdir -p Formula
          cat > Formula/myc.rb <<EOF
          # This file is auto-generated by .github/workflows/release.yml.
          # Do not edit by hand — changes are overwritten on the next release.
          class Myc < Formula
            desc "Robust, production-grade task/plan manager CLI (mycelium)"
            homepage "https://github.com/$REPO"
            version "$version"
            license "MIT"

            on_macos do
              if Hardware::CPU.arm?
                url "$base/myc-aarch64-apple-darwin.tar.gz"
                sha256 "$sha_arm_mac"
              else
                url "$base/myc-x86_64-apple-darwin.tar.gz"
                sha256 "$sha_x86_mac"
              end
            end

            on_linux do
              # Only x86_64 Linux binaries are published today.
              url "$base/myc-x86_64-unknown-linux-gnu.tar.gz"
              sha256 "$sha_x86_linux"
            end

            def install
              bin.install "myc"
            end

            test do
              assert_match "myc #{version}", shell_output("#{bin}/myc --version")
            end
          end
          EOF
          echo "Rendered Formula/myc.rb for $version"

      - name: Push formula to the tap
        env:
          GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
          TAG: ${{ github.ref_name }}
        run: |
          set -euo pipefail
          git clone "https://x-access-token:${GH_TOKEN}@github.com/tcsenpai/homebrew-tap.git" tap
          mkdir -p tap/Formula
          cp Formula/myc.rb tap/Formula/myc.rb
          cd tap
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add Formula/myc.rb
          # Check AFTER staging: `git diff --quiet` alone ignores a brand-new
          # untracked formula, so the first release would silently no-op.
          if git diff --cached --quiet; then
            echo "Formula unchanged; nothing to push."
            exit 0
          fi
          git commit -m "myc ${TAG#v}"
          git push