name: CI pipeline ⚙️

on:
  push:
    branches: [ "main" ]
  pull_request:

jobs:
  test-code:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python: ['3.10', '3.11', '3.12', '3.13', '3.14']
    defaults:
      run:
        shell: bash -l {0}
    steps:
    - uses: actions/checkout@v4
      with:
          fetch-depth: 2
    - name: Set up Python ${{ matrix.python }}
      uses: actions/setup-python@v4
      with:
        python-version: "${{ matrix.python }}"
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install .[tests]
    - name: Lint with flake8
      run: |
        # stop if there are Python syntax errors or undefined names
        flake8 ./marge3d ./tests --count --select=E9,F63,F7,F82 --show-source --statistics
    - name: Run pytest
      run: |
        pytest --cov --cov-report=xml -v --durations=0 ./tests
    - name: Upload coverage reports to Codecov
      uses: codecov/codecov-action@v5
      if: github.repository_owner == 'CompMath-TUHH' && matrix.python == '3.13'
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        slug: CompMath-TUHH/MaRGE_3D_solver

  test-tutorials:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 1
    - name: Set up Python 3.13
      uses: actions/setup-python@v4
      with:
        python-version: "3.13"
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install .[tests]
        python -c "import matplotlib"
    - name: Test with pytest-notebook
      run: |
        pytest ./docs/notebooks --nb-test-files -v
