name: Build
description: Build app
inputs:
  calling-job:
    required: true
    description: Job that's calling this one
  os-name:
    required: true
    description: OS to run on
  python-version:
    required: true
    description: Python version to install

runs:
  using: "composite"
  steps:
    # checkout commit
    - name: Checkout commit
      shell: bash
      run: |
        echo "Checkout commit"
    - name: Checkout commit
      uses: actions/checkout@v4.1.4

    # get parent dir
    - name: Get Parent Directory
      id: parentDir
      uses: ./.github/actions/get-parent-dir

    # try to get UPX
    - name: Get UPX
      shell: bash
      run: |
        echo "Get UPX"
    - name: Get UPX
      shell: bash
      env:
        OS_NAME: ${{ inputs.os-name }}
        UPX_VERSION: "4.2.3"
      run: |
        python ./resources/ci/common/get_upx.py

    # run build.py
    - name: 💬Build Binaries
      shell: bash
      run: |
        echo "💬Build Binaries"
    - name: Build Binaries
      shell: bash
      run: |
        pip install pyinstaller
        python -m source.meta.build

    # upload problem children
    # - name: 🔼Upload Problem Children Artifact
    #   shell: bash
    #   run: |
    #     echo "🔼Upload Problem Children Artifact"
    # - name: 🔼Upload Problem Children Artifact
    #   uses: actions/upload-artifact@v4.3.3
    #   with:
    #     name: problemchildren-${{ inputs.os-name }}-py${{ inputs.python-version }}
    #     path: ./resources/app/meta/manifests/excluded_dlls.json
    #     if-no-files-found: ignore # 'warn' or 'ignore' are also available, defaults to `warn`

    # prepare binary artifact for later step
    - name: 💬Prepare Binary Artifact
      shell: bash
      run: |
        echo "💬Prepare Binary Artifact"
    - name: Prepare Binary Artifact
      shell: bash
      env:
        OS_NAME: ${{ inputs.os-name }}
      run: |
        python ./resources/ci/common/prepare_binary.py

    # upload binary artifact for later step
    - name: 🔼Upload Binary Artifact
      shell: bash
      run: |
        echo "🔼Upload Binary Artifact"
    - name: 🔼Upload Binary Artifact
      uses: actions/upload-artifact@v4.3.3
      with:
        name: binary-${{ inputs.os-name }}-py${{ inputs.python-version }}
        path: ${{ steps.parentDir.outputs.parentDir }}/artifact
        if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`
