name: job_nuitka-win

on:
  workflow_call:
    inputs:
      version:
        required: true
        type: string

jobs:
  build:
    name: Build
    runs-on: "windows-latest"
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          cache: pip
          python-version: '3.9'
          check-latest: true
          architecture: x64
      - name: Install build dependencies
        run: pip3 install nuitka ordered-set
      - name: Install target dependencies
        run: |
          pip3 install -r requirements.txt
          pip3 install -r requirements-presence.txt
      - name: Build
        run: >-
          python -m nuitka
          --assume-yes-for-downloads
          --msvc=latest
          --lto=yes
          --jobs=2
          --static-libpython=no
          --standalone
          --enable-plugin=anti-bloat
          --enable-plugin=pyqt5
          --show-modules
          --show-anti-bloat-changes
          --follow-stdlib
          --follow-imports
          --nofollow-import-to="*.tests"
          --nofollow-import-to="*.distutils"
          --prefer-source-code
          --include-package=pypresence
          --include-package-data=qtawesome
          --include-data-dir=rare\resources\images=rare\resources\images
          --include-data-files=rare\resources\languages=rare\resources\languages="*.qm"
          --windows-icon-from-ico=rare\resources\images\Rare.ico
          --windows-company-name=Rare
          --windows-product-name=Rare
          --windows-file-description=rare.exe
          --windows-file-version=${{ inputs.version }}
          --windows-product-version=${{ inputs.version }}
          --disable-console
          rare
      - name: Fix QtNetwork SSL
        run: |
          Copy-Item -Path "rare.dist\libcrypto-1_1.dll" -Destination "rare.dist\libcrypto-1_1-x64.dll"
          Copy-Item -Path "rare.dist\libssl-1_1.dll" -Destination "rare.dist\libssl-1_1-x64.dll"
      - name: Compress
        run: |
          python -c "import shutil; shutil.make_archive('Rare-Windows', 'zip', 'rare.dist')"

      - name: Upload artifact
        uses: actions/upload-artifact@v3
        with:
          name: Rare-Windows-${{ inputs.version }}.zip
          path: Rare-Windows.zip