name: Python application

on:
  pull_request:
    branches: [ "master" ]
    paths:
      - '.github/workflows/python-app.yml'
      - 'pymobiledevice3/**'
      - 'requirements.txt'
      - 'pyproject.toml'
  release:
    types: [ created ]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    if: '! github.event.pull_request.draft'
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        python-version: [ 3.9, "3.10", "3.11", "3.12", "3.13" ]
        os: [ ubuntu-latest, macos-latest, windows-latest ]

    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          python3 -m pip install --upgrade pip
          python3 -m pip install pre-commit
      - name: Run pre-commit hooks
        run: |
          pre-commit run --all-files
      - name: Test install
        run: |
          python -m pip install -U '.[test]'
      - name: Test show usage
        run: pytest -m cli

#  pyinstaller:
#    needs: [ 'test' ]
#    if: '! github.event.pull_request.draft'
#    runs-on: ${{ matrix.os }}
#
#    strategy:
#      matrix:
#        python-version: [ "3.12" ]
#        os: [ ubuntu-latest, macos-latest, windows-latest ]
#
#    steps:
#      - uses: actions/checkout@v4
#      - name: Set up Python
#        uses: actions/setup-python@v4
#        with:
#          python-version: '3.x'
#      - name: Install dependencies
#        run: |
#          python -m pip install --upgrade pip
#          pip install -U . coloredlogs pyinstaller apple_compress
#      - name: Build
#        run: |
#          python .github/workflows/generate-executable.py
#
#      - if: matrix.os == 'ubuntu-latest'
#        name: Test ubuntu artifact
#        run: |
#          ./dist/pymobiledevice3
#
#      - if: matrix.os == 'macos-latest'
#        name: Test macos artifact
#        run: |
#          ./dist/pymobiledevice3
#
#      - if: matrix.os == 'windows-latest'
#        name: Test windows artifact
#        run: |
#          ./dist/pymobiledevice3.exe
#
#      - if: matrix.os == 'ubuntu-latest'
#        name: Rename ubuntu artifact
#        run: |
#          mv ./dist/pymobiledevice3 ./dist/pymobiledevice3_ubuntu
#      - if: matrix.os == 'macos-latest'
#        name: Rename macos artifact
#        run: |
#          mv ./dist/pymobiledevice3 ./dist/pymobiledevice3_macos
#
#      - if: matrix.os == 'ubuntu-latest'
#        name: Upload ubuntu artifact
#        uses: actions/upload-artifact@v3
#        with:
#          name: pymobiledevice3_ubuntu
#          path: ./dist/pymobiledevice3_ubuntu
#      - if: matrix.os == 'macos-latest'
#        name: Upload macos artifact
#        uses: actions/upload-artifact@v3
#        with:
#          name: pymobiledevice3_macosx
#          path: ./dist/pymobiledevice3_macos
#      - if: matrix.os == 'windows-latest'
#        name: Upload windows artifact
#        uses: actions/upload-artifact@v3
#        with:
#          name: pymobiledevice3_windows.exe
#          path: ./dist/pymobiledevice3.exe
#
#      - name: Upload server artifacts to GitHub Release
#        if: github.event_name == 'release'
#        uses: softprops/action-gh-release@v1
#        with:
#          files: |
#            dist/pymobiledevice3_macos
#            dist/pymobiledevice3_ubuntu
#            dist/pymobiledevice3.exe
#          token: ${{ secrets.GITHUB_TOKEN }}