name: Linting

on:
  push:
  pull_request:
  schedule:
  # Run every Friday at 18:02 UTC
  - cron: 2 18 * * 5

jobs:
  lint:
    name: ${{ matrix.os }}
    runs-on: ${{ matrix.os }}-latest
    env:
      TOXENV: lint,docs,vendoring

    strategy:
      matrix:
        os:
        - Ubuntu
        - Windows

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.9
      uses: actions/setup-python@v2
      with:
        python-version: 3.9

    # Setup Caching
    - name: pip cache
      uses: actions/cache@v1
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-${{ hashFiles('tools/requirements/tests.txt') }}-${{ hashFiles('tools/requirements/docs.txt') }}-${{ hashFiles('tox.ini') }}
        restore-keys: |
          ${{ runner.os }}-pip-
          ${{ runner.os }}-

    - name: Set PY (for pre-commit cache)
      run: echo "PY=$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
    - name: pre-commit cache
      uses: actions/cache@v1
      with:
        path: ~/.cache/pre-commit
        key: pre-commit|2020-02-14|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}

    # Get the latest tox
    - name: Install tox
      run: python -m pip install tox

    # Main check
    - run: python -m tox
