name: build marcos

on: [push, pull_request, workflow_dispatch]

jobs:
  test:
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: 'Ubuntu-Latest'
            python: '3.11'
            os: 'ubuntu-latest'

    timeout-minutes: 30

    steps:
      - uses: actions/checkout@v4

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

      - name: Check Python version
        run: python --version

      - name: Install dependencies
        run: |
          set -xv
          python -m pip install --upgrade pip
          python -m pip --version
          python -m pip install --upgrade --progress-bar=off -r ci/requirements.txt
          pip list --format=freeze

      - name: Setup amplpy modules
        run: |
          set -xv
          python -m pip install amplpy --upgrade
          python -m amplpy.modules install gurobi highs coin scip
          python -m amplpy.modules activate ${{ secrets.AMPL_UUID }}

      - name: Install amplpower
        run: |
          python -m pip install .

      - name: Run tests
        run: |
          set -xv
          pytest

  finish:
    needs: test
    if: ${{ always() }}
    runs-on: ubuntu-latest
    steps:
      - uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
