name: build-python-package

on: [push, pull_request]

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

jobs:
  build_sdist:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: seanmiddleditch/gha-setup-ninja@master

      - name: Build sdist
        run: |
          python3 -m pip install build
          python3 -m build --sdist

      - name: Install sdist
        run: |
          ls dist
          python3 -m pip install dist/*.tar.gz

      - name: Test highspy
        run: |
          python3 -m pip install pytest
          python3 -m pytest $GITHUB_WORKSPACE

  build_sdist_mac:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build sdist
        run: |
          python3 -m pip install build --break-system-packages
          python3 -m build --sdist

      - name: Install sdist
        run: |
          ls dist
          python3 -m pip install dist/*.tar.gz --break-system-packages

      - name: Test highspy
        run: |
          python3 -m pip install pytest --break-system-packages
          python3 -m pytest $GITHUB_WORKSPACE

  build_sdist_win:
    runs-on: windows-2022
    steps:
      - uses: actions/checkout@v4

      - name: Install correct python version
        uses: actions/setup-python@v5
        with:
          python-version: 3.9

      - name: Build sdist
        run: |
          python -m pip install build
          python -m build --sdist

      - name: Install sdist
        run: |
          $item = Get-ChildItem dist
          python -m pip install "$item"
          python -c "import highspy; print(dir(highspy))"

      - name: Test highspy
        run: |
          python -m pip install pytest
          python -m pytest

  build_wheel_linux:
    runs-on: ubuntu-24.04
    strategy:
        matrix:
          python: [3.11]
    steps:
      - uses: actions/checkout@v4

      - name: Install correct python version
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python }}

      - name: Build wheel
        run: |
          python3 --version
          python3 -m pip install cibuildwheel
          python3 -m cibuildwheel --only cp311-manylinux_x86_64 $GITHUB_WORKSPACE

      - name: Install wheel
        run: |
          ls wheelhouse
          python3 -m pip install wheelhouse/*.whl

      - name: Test highspy
        run: |
          python3 -m pip install pytest
          python3 -m pytest $GITHUB_WORKSPACE

  build_wheel_linux_arm:
    runs-on: ubuntu-24.04-arm
    strategy:
        matrix:
          python: [3.11]
    steps:
      - uses: actions/checkout@v4

      - name: Install python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python }}

      - name: Build wheel
        run: |
          python3 --version
          python3 -m pip install cibuildwheel
          python3 -m cibuildwheel --only cp311-manylinux_aarch64 $GITHUB_WORKSPACE

      - name: Install wheel
        run: |
          ls wheelhouse
          python3 -m pip install wheelhouse/*.whl

      - name: Test highspy
        run: |
          python3 -m pip install pytest
          python3 -m pytest $GITHUB_WORKSPACE

  build_wheel_macos_intel:
    runs-on: macos-15-intel
    strategy:
      matrix:
        python: [3.11]
    steps:
      - uses: actions/checkout@v4

      - name: Install correct python version
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python }}

      - name: Build wheel
        run: |
          python3 -m pip install cibuildwheel
          python3 -m cibuildwheel --only cp311-macosx_x86_64 $GITHUB_WORKSPACE

      - name: Install wheel
        run: |
          ls wheelhouse
          python3 --version
          python3 -m pip install wheelhouse/*.whl
          python3 -c "import highspy; print(dir(highspy))"

      - name: Test highspy
        run: |
          python3 -m pip install pytest
          python3 -m pytest $GITHUB_WORKSPACE
            
  build_wheel_macos_arm:
    runs-on: macos-14  # macos-14 is arm64
    strategy:
      matrix:
        python: [3.11]
    steps:
      - uses: actions/checkout@v4

      - name: Install correct python version
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python }}

      - name: Build wheel
        run: |
          python3 -m pip install cibuildwheel
          python3 -m cibuildwheel --only cp311-macosx_arm64 $GITHUB_WORKSPACE

      - name: Install wheel
        run: |
          ls wheelhouse
          python3 --version
          python3 -m pip install wheelhouse/*.whl
          python3 -c "import highspy; print(dir(highspy))"

      - name: Test highspy
        run: |
          python3 -m pip install pytest
          python3 -m pytest $GITHUB_WORKSPACE

  build_wheel_windows:
    runs-on: windows-2022
    steps:
      - uses: actions/checkout@v4

      - name: Install correct python version
        uses: actions/setup-python@v5
        with:
          python-version: 3.9

      - name: Build wheel
        run: |
          python -m pip install cibuildwheel
          python -m cibuildwheel --only cp39-win_amd64 $GITHUB_WORKSPACE

      - name: Install wheel
        run: |
          ls wheelhouse
          $item = Get-ChildItem wheelhouse
          python -m pip install "$item"
          python -c "import highspy; print(dir(highspy))"

      - name: Test highspy
        run: |
          python -m pip install pytest
          python -m pytest 
          
  build_wheel_windows_313:
    runs-on: windows-2022
    steps:
      - uses: actions/checkout@v4

      - name: Install correct python version
        uses: actions/setup-python@v5
        with:
          python-version: 3.13

      - name: Build wheel
        run: |
          python -m pip install cibuildwheel
          python -m cibuildwheel --only cp313-win_amd64 $GITHUB_WORKSPACE

      - name: Install wheel
        run: |
          ls wheelhouse
          $item = Get-ChildItem wheelhouse
          python -m pip install "$item"
          python -c "import highspy; print(dir(highspy))"

      - name: Test highspy
        run: |
          python -m pip install pytest
          python -m pytest
