name: Release

# 打 vX.Y.Z 标签即触发：各平台用 wails 构建桌面端安装包 → 发布到 GitHub Release。
# 用户旧版 App 启动时查 /releases/latest，发现新版即提示下载（见 frontend/src/lib/version.ts）。
on:
  push:
    tags: ["v*"]

permissions:
  contents: write # 创建 release + 上传产物需要

jobs:
  build:
    name: 构建 ${{ matrix.label }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: macos-latest
            label: macOS (universal)
            platform: darwin/universal
          - os: windows-latest
            label: Windows (amd64)
            platform: windows/amd64
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: "1.25"
      - uses: actions/setup-node@v4
        with:
          node-version: "20"
      - name: 安装 wails CLI
        run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.12.0

      - name: 构建桌面端（wails build；GOWORK=off 因 desktop 不在工作区）
        working-directory: sundynix-desktop
        env:
          GOWORK: "off" # 必须加引号：YAML 裸 off 会被解析成布尔 false，使 workflow 校验不合法而不触发
        run: wails build -clean -platform ${{ matrix.platform }}

      # macOS：.app 是目录，打包成 zip 才能作为单文件资产分发。
      - name: 打包 macOS 产物
        if: runner.os == 'macOS'
        working-directory: sundynix-desktop/build/bin
        run: zip -r -y sundynix_desktop_macos_universal.zip sundynix_desktop.app

      - name: 重命名 Windows 产物
        if: runner.os == 'Windows'
        working-directory: sundynix-desktop/build/bin
        run: ren sundynix_desktop.exe sundynix_desktop_windows_amd64.exe

      - name: 发布到 GitHub Release（按 tag 创建/追加资产）
        uses: softprops/action-gh-release@v2
        with:
          fail_on_unmatched_files: false
          files: |
            sundynix-desktop/build/bin/sundynix_desktop_macos_universal.zip
            sundynix-desktop/build/bin/sundynix_desktop_windows_amd64.exe
