name: Bundle Windows EXE


on:
  # Only trigger on release creation
  release:
    types:
      - created
  workflow_dispatch:
    inputs:
      ref_name:
        description: Name to use for the release
env:
  target_tag: ${{ github.ref_name || github.event.inputs.ref_name }}
  sha: ${{ github.sha || github.event.inputs.ref_name }}


jobs:
  build:

    runs-on: windows-2019
    permissions:
      contents: write
    strategy:
      matrix:
        python-version: ["3.12"]

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        pip install -e .
        # Pinned for now until I figure out why it freaks out on bundling PySide6
        pip install cx_freeze==6.15.15

    - name: Bundle with cx_Freeze
      shell: bash
      run: |
        python setup_cxfreeze.py build_exe
        pip install pip-licenses
        pip-licenses --format=plain-vertical --with-license-file --no-license-path --output-file=lib_licenses.txt
        python setup_cxfreeze.py finalize_cxfreeze
        # Should only be one, but we don't know what it's named
        mv ./dist/*.zip hippolyzer-windows-${{ env.target_tag }}.zip

    - name: Upload the artifact
      uses: actions/upload-artifact@v4
      with:
        name: hippolyzer-windows-${{ env.sha }}
        path: ./hippolyzer-windows-${{ env.target_tag }}.zip

    - uses: ncipollo/release-action@v1.10.0
      if: github.event_name != 'workflow_dispatch'
      with:
        artifacts: hippolyzer-windows-${{ env.target_tag }}.zip
        tag: ${{ env.target_tag }}
        token: ${{ secrets.GITHUB_TOKEN }}
        allowUpdates: true
