name: macOS

on:
  push:
    branches:
      - master

jobs:
  build:
    name: GPXSee
    runs-on: macos-26
    steps:
      - name: Checkout
        uses: actions/checkout@v7
      - name: Install Qt
        uses: jurplel/install-qt-action@v4
        with:
          version: '6.12.0'
          modules: qtpositioning qtserialport qtimageformats qtmultimedia qt5compat
      - name: Remove the StyleKit style (QTBUG-147447 workaround)
        run: rm -rf ${{env.QT_PLUGIN_PATH}}/styles/libqstylekitstyle*
      - name: Create localization
        run: lrelease-pro gpxsee.pro
      - name: Configure build
        run: qmake gpxsee.pro QMAKE_APPLE_DEVICE_ARCHS="x86_64h arm64"
      - name: Build project
        run: make -j3
      - name: Install codesigning certificate
        env:
          CERTIFICATE: ${{secrets.CODESIGN_CERT}}
          CERTIFICATE_PWD: ${{secrets.CODESIGN_PWD}}
        if: env.CERTIFICATE
        run: |
          echo $CERTIFICATE | base64 --decode > certificate.p12
          security create-keychain -p password keychain
          security default-keychain -s keychain
          security unlock-keychain -p password keychain
          security import certificate.p12 -k keychain -P $CERTIFICATE_PWD -T /usr/bin/codesign
          security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k password keychain
      - name: Create DMG
        run: |
          if security find-certificate -c GPXSee keychain; then
            macdeployqt GPXSee.app -dmg -appstore-compliant -codesign=GPXSee
          else
            macdeployqt GPXSee.app -dmg -appstore-compliant
          fi
      - name: Upload artifacts
        uses: actions/upload-artifact@v7
        with:
          path: GPXSee.dmg
          name: GPXSee.dmg
          archive: false
