name: MacOS Qt6
on:
  push:
    paths-ignore:
      - "README.md"
      - "LICENSE"
      - "BUILD.md"
  pull_request:
    paths-ignore:
      - "README.md"
      - "LICENSE"
      - "BUILD.md"
  release:
    types: [published]
jobs:
  build:
    name: Build
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-latest]
        build_type: [Release, RelWithDebInfo, Debug]
        arch: [x86_64, arm64]
        qt_ver: [6.9.3]
        qt_arch: [clang_64]
    env:
      targetName: lemon
    steps:
      - name: Install Qt
        uses: jurplel/install-qt-action@v4
        with:
          version: ${{ matrix.qt_ver }}
          cached: ${{ steps.MacosCacheQt.outputs.cache-hit }}

      - uses: actions/checkout@v6
        with:
          submodules: true
      - name: macOS - ${{ matrix.qt_version }} - Build preparation - Install Packages
        run: |
          brew install ninja pkg-config
      - name: build macos
        run: |
          cmake . \
            -GNinja \
            -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
            -DLEMON_BUILD_INFO="Build for macOS" \
            -DLEMON_BUILD_EXTRA_INFO="Build on $(uname -sr)" \
            -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 \
            -DCMAKE_OSX_ARCHITECTURES="${{ matrix.arch }}" 
          cmake --build . --parallel $(sysctl -n hw.logicalcpu)
      - name: Run tests
        if: ${{ false }}
        run: |
          ctest --test-dir . --output-on-failure --timeout 120
      # tag 打包
      - name: package
        env:
          Qt6_DIR: ../Qt/${{matrix.qt_ver}}/${{matrix.qt_arch}}
        run: |
          # 拷贝依赖
          #mv ${targetName} ${targetName}.app
          export PATH=$Qt6_DIR/bin:$PATH
          macdeployqt ${targetName}.app -qmldir=. -verbose=1 -dmg
      - name: Upload artifact
        uses: actions/upload-artifact@v7
        with:
          name: ${{ env.targetName }}-Qt${{ matrix.qt_ver }}-${{ matrix.build_type }}-${{ matrix.arch }}.dmg
          path: ${{ env.targetName }}.dmg
      - name: uploadRelease
        if: startsWith(github.event.ref, 'refs/tags/')
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: ./${{ env.targetName }}.dmg
          asset_name: ${{ env.targetName }}-Qt${{ matrix.qt_ver }}-${{ matrix.build_type }}-${{ matrix.arch }}.dmg
          tag: ${{ github.ref }}
