name: Build and Test Linux
on: [push, pull_request]
jobs:
  build-linux:
    name: Python (${{ matrix.python-version }})
    runs-on: ubuntu-latest
    env:
      PROJ_DIR: /usr
      PROJ_LIB: /usr/share/proj
    strategy:
      matrix:
        python-version: ["3.11"]
    steps:

    - uses: actions/checkout@v4

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

    - name: Install Ubuntu Dependencies
      run: |
        sudo apt-get update
        sudo apt-get install gfortran libeccodes-dev

    - name: Update Pip
      run: |
        python -m pip install --upgrade pip

    - name: Install some dependencies via pip
      run: |
        # Install pyspharm using a few tricks
        pip install numpy setuptools wheel
        FFLAGS="-fallow-argument-mismatch" pip install --no-use-pep517 pyspharm
        # for later building/checking
        pip install build twine
        pip install check-manifest
        # below here only needed for mpl/cartopy based tests
        pip install pytest-mpl
        pip install cartopy

    - name: Install pygrib
      run: |
        pip install -e .

    - name: Test
      run: |
        cd test
        export MPLBACKEND=agg
        pytest test*py --mpl --mpl-baseline-path=baseline_images
        # if no mpl/cartopy run this
        #pytest test.py test_latlons.py

    - name: Tarball
      run: |
        python -m build --sdist
        check-manifest --verbose
        twine check --strict dist/*
