name: Test via PR Comment
on:
  issue_comment:
    types:
      - created

jobs:
  linux:
    runs-on: "ubuntu-latest"
    strategy:
      matrix:
        python-version: ["3.8", "3.9", "3.10"]
      fail-fast: false
    name: Linux Python ${{ matrix.python-version }}
    if: ${{ github.event.issue.pull_request && github.event.comment.body == '@runGAtests' }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: conda-incubator/setup-miniconda@v2
        with:
          activate-environment: esmvalcore
          environment-file: environment.yml
          python-version: ${{ matrix.python-version }}
          miniforge-version: "latest"
          miniforge-variant: Mambaforge
          use-mamba: true
      - shell: bash -l {0}
        run: mkdir -p test_linux_artifacts_python_${{ matrix.python-version }}
      - shell: bash -l {0}
        run: conda --version 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/conda_version.txt
      - shell: bash -l {0}
        run: python -V 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/python_version.txt
      - shell: bash -l {0}
        run: pip install -e .[develop] 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/install.txt
      - shell: bash -l {0}
        run: flake8
      - shell: bash -l {0}
        run: pytest -n 2 -m "not installation" 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/test_report.txt
      - name: Upload artifacts
        if: ${{ always() }}  # upload artifacts even if fail
        uses: actions/upload-artifact@v2
        with:
          name: Test_Linux_python_${{ matrix.python-version }}
          path: test_linux_artifacts_python_${{ matrix.python-version }}

  osx:
    runs-on: "macos-latest"
    strategy:
      matrix:
        python-version: ["3.8", "3.9", "3.10"]
      fail-fast: false
    name: OSX Python ${{ matrix.python-version }}
    if: ${{ github.event.issue.pull_request && github.event.comment.body == '@runGAtests' }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: conda-incubator/setup-miniconda@v2
        with:
          activate-environment: esmvalcore
          environment-file: environment.yml
          python-version: ${{ matrix.python-version }}
          miniforge-version: "latest"
          miniforge-variant: Mambaforge
          use-mamba: true
      - shell: bash -l {0}
        run: mkdir -p test_osx_artifacts_python_${{ matrix.python-version }}
      - shell: bash -l {0}
        run: conda --version 2>&1 | tee test_osx_artifacts_python_${{ matrix.python-version }}/conda_version.txt
      - shell: bash -l {0}
        run: python -V 2>&1 | tee test_osx_artifacts_python_${{ matrix.python-version }}/python_version.txt
      - shell: bash -l {0}
        run: pip install -e .[develop] 2>&1 | tee test_osx_artifacts_python_${{ matrix.python-version }}/install.txt
      - shell: bash -l {0}
        run: flake8
      - shell: bash -l {0}
        run: pytest -n 2 -m "not installation" 2>&1 | tee test_osx_artifacts_python_${{ matrix.python-version }}/test_report.txt
      - name: Upload artifacts
        if: ${{ always() }}  # upload artifacts even if fail
        uses: actions/upload-artifact@v2
        with:
          name: Test_OSX_python_${{ matrix.python-version }}
          path: test_osx_artifacts_python_${{ matrix.python-version }}
