name: tests

on:
  pull_request:
    paths:
      - "test/test_datasets_download.py"
      - ".github/failed_schedule_issue_template.md"
      - ".github/workflows/tests-schedule.yml"

  schedule:
    - cron: "0 9 * * *"

jobs:
  download:
    runs-on: ubuntu-latest

    steps:
      - name: Set up python
        uses: actions/setup-python@v2
        with:
          python-version: 3.6

      - name: Upgrade pip
        run: python -m pip install --upgrade pip

      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Install PyTorch from the nightlies
        run: |
          pip install numpy
          pip install --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html

      - name: Install all optional dataset requirements
        run: pip install scipy pandas pycocotools lmdb requests

      - name: Install tests requirements
        run: pip install pytest

      - name: Run tests
        run: pytest -ra -v test/test_datasets_download.py

      - uses: JasonEtco/create-an-issue@v2.4.0
        name: Create issue if download tests failed
        if: failure() && github.event_name == 'schedule'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          REPO: ${{ github.repository }}
          WORKFLOW: ${{ github.workflow }}
          JOB: ${{ github.job }}
          ID: ${{ github.run_id }}
        with:
          filename: .github/failed_schedule_issue_template.md
