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.8

      - name: Upgrade system packages
        run: python -m pip install --upgrade pip setuptools wheel

      - name: SSL
        run: python -c 'import ssl; print(ssl.OPENSSL_VERSION)'

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

      - name: Install torch nightly build
        run: pip install --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html

      - name: Install torchvision
        run: pip install --no-build-isolation --editable .

      - name: Install all optional dataset requirements
        run: pip install scipy 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
