name: pr_stage_test

on:
  pull_request:
    paths-ignore:
      - 'README.md'
      - 'README_zh-CN.md'
      - 'docs/**'
      - 'demo/**'
      - 'tools/**'
      - 'configs/**'
      - '.dev_scripts/**'
      - '.circleci/**'

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    runs-on: ubuntu-18.04
    strategy:
      matrix:
        python-version: [3.7]
        include:
          - torch: 1.8.1
            torchvision: 0.9.1
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Upgrade pip
        run: pip install pip --upgrade
      - name: Install PyTorch
        run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
      - name: Install mmcls dependencies
        run: |
          pip install git+https://github.com/open-mmlab/mmengine.git@main
          pip install -U openmim
          mim install 'mmcv >= 2.0.0rc1'
          pip install -r requirements.txt
      - name: Build and install
        run: pip install -e .
      - name: Run unittests and generate coverage report
        run: |
          coverage run --branch --source mmcls -m pytest tests/
          coverage xml
          coverage report -m
      # Upload coverage report for python3.7 && pytorch1.8.1 cpu
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v1.0.14
        with:
          file: ./coverage.xml
          flags: unittests
          env_vars: OS,PYTHON
          name: codecov-umbrella
          fail_ci_if_error: false

  build_windows:
    runs-on: windows-2022
    strategy:
      matrix:
        python: [3.7]
        platform: [cu111]
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Upgrade pip
        run: python -m pip install pip --upgrade
      - name: Install PyTorch
        run: pip install torch==1.8.2+${{matrix.platform}} torchvision==0.9.2+${{matrix.platform}} -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
      - name: Install mmcls dependencies
        run: |
          pip install git+https://github.com/open-mmlab/mmengine.git@main
          pip install -U openmim
          mim install 'mmcv >= 2.0.0rc1'
          pip install -r requirements.txt
      - name: Build and install
        run: pip install -e .
      - name: Run unittests
        run: |
          pytest tests/ --ignore tests/test_models/test_backbones
