name: Build Windows EXE

on:
  push:
    branches: [main]
  release:
    types: [published]

jobs:
  build:
    runs-on: windows

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install dependencies
        run: pip install -r requirements.txt

      - name: Build EXE
        run: pyinstaller es24n_conf.spec

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: es24n_conf-windows
          path: dist/es24n_conf.exe

      - name: Attach EXE to release
        if: github.event_name == 'release'
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: dist/es24n_conf.exe
          asset_name: es24n_conf.exe
          asset_content_type: application/octet-stream
