name: Pull-Request-CI

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main

jobs:
  Build-and-Test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
       os: [ubuntu-latest, macos-latest]
       python-version: ["3.8", "3.9", "3.10", "3.11"]
    defaults:
      run:
        shell: bash -l {0}
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: conda-incubator/setup-miniconda@v2
        with:
          miniconda-version: "latest"
          activate-environment: ale
          environment-file: environment.yml
          auto-activate-base: false
          auto-update-conda: true
          python-version: ${{ matrix.python-version }}
      - name: Check build environment
        run: |
          conda list
      - name: Install Python Package
        run: |
          python setup.py install
      - name: Test Python Package
        run: |
           pytest --cov-report=xml --cov=ale tests/pytests -vv
      - name: Build C++ Package
        run: |
          mkdir -p build
          cd build
          cmake -DCMAKE_BUILD_TYPE=RELEASE -DCOVERAGE=ON ..
          cmake --build .
      - name: Test C++ Package
        run: |
          cd build
          ctest -VV
      - name: Upload Coverage
        uses: codecov/codecov-action@v1
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          fail_ci_if_error: true
          verbose: true
        if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9'
