name: Windows

on:
  push:
    branches:
      - master

jobs:
  build:
    name: GPXSee
    strategy:
      matrix:
        include:
          - arch: x64
            os: windows-2022
          - arch: arm64
            os: windows-11-arm
    runs-on: ${{matrix.os}}
    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
          aqtsource: 'git+https://github.com/miurahr/aqtinstall.git'
      - name: Set up Visual Studio shell
        uses: egor-tensin/vs-shell@v2
        with:
          arch: ${{matrix.arch}}
      - name: Create localization
        run: lrelease-pro gpxsee.pro
      - name: Configure build
        run: qmake gpxsee.pro
      - name: Build project
        run: nmake release
      - name: Create installer
        run: |
          md installer
          copy release\GPXSee.exe installer
          windeployqt --exclude-plugins qsqlibase,qsqlmimer,qsqloci,qsqlodbc,qsqlpsql,qstylekitstyle --release installer\GPXSee.exe
          copy pkg\windows\gpxsee64.nsi installer
          xcopy data\CRS installer\CRS /i
          xcopy data\maps installer\maps /i
          xcopy data\style installer\style /s /i
          xcopy lang\*.qm installer\translations\ /sy
          xcopy icons\symbols installer\symbols /i
          copy licence.txt installer
          makensis /D${{matrix.arch}} installer\gpxsee64.nsi
      - name: Code Signing
        env:
          CERTIFICATE: ${{secrets.CERTIFICATE}}
          CERTIFICATE_PWD: ${{secrets.CERTIFICATE_PWD}}
        if: env.CERTIFICATE
        run: |
          md certificate
          echo "$env:CERTIFICATE" > certificate\certificate.txt
          certutil -decode certificate\certificate.txt certificate\certificate.pfx
          signtool sign /f certificate\certificate.pfx /fd SHA256 /p "$env:CERTIFICATE_PWD" /tr "http://timestamp.acs.microsoft.com" /td SHA256 installer\GPXSee-*.exe
      - name: Upload artifacts
        uses: actions/upload-artifact@v7
        with:
          path: installer/GPXSee-*.exe
          name: GPXSee_${{matrix.arch}}.exe
          archive: false
