name: {{ NAME }}{% if report_coverage %} cov{% endif %} {{ OS_NAME }} {{ PYTHON_VERSION }}

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

jobs:
  build:

    runs-on: {{ '${{ matrix.os }}' }}
    strategy:
      matrix:
        os: [{{ OS_IMAGE }}]
        python-version: [ "{{ PYTHON_VERSION }}" ]
    defaults:
      run:
        shell: bash{% if not use_setup_py %} -l {0}{% endif %}

    {% raw %}
    name: Python ${{ matrix.python-version }} ${{ matrix.os }}
    {% endraw %}
    steps:
      - uses: actions/checkout@v2
      - uses: actions/cache@v2
        with:{% raw %}
          path: |
            ~/conda_pkgs_dir
            ~/miniconda*/envs/
          key: ${{ runner.os }}-${{ matrix.python-version }}-env-${{ hashFiles('requirements/tests.txt') }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.python-version }}-env-{% endraw %}

      {% if use_setup_py %}
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: {{ '${{ matrix.python-version }}' }}

      {% else %}
      - name: Setup conda
        uses: conda-incubator/setup-miniconda@v2
        with:
          activate-environment: xonsh-test
          auto-update-conda: true
          python-version: {{ '${{ matrix.python-version }}' }}  # this itself makes sure that Python version is installed
          condarc-file: ci/condarc.yml
          use-only-tar-bz2: true
      {% endif %}
      - name: Get pip cache dir
        id: pip-cache
        run: |
          python -m pip install --upgrade pip wheel
          echo "::set-output name=dir::$(python -m pip cache dir)"
      {%- raw %}
      - name: pip cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.pip-cache.outputs.dir }}
          key: ${{ runner.os }}-pip-${{ hashFiles('requirements/tests.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-
      {% endraw %}
      - name: Install dependencies
        run: |
          python -m pip --version
          python -m pip install -r requirements/tests.txt
          python -m pip install{% if report_coverage or (test_cmd == "qa")  %} -e{% endif %} . --no-deps
      - name: Run tests
        run: python -m xonsh run-tests.xsh {{ test_cmd }}
        {% if allow_failure %}
        continue-on-error: true
        {% endif %}
      {% if report_coverage %}
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v2
        with:
          verbose: true
          flags: "{{ OS_NAME }}"
      {% endif %}
