# NB: this name is used in the status badge
name: build

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  workflow_dispatch:
  schedule:
    - cron: "0 5 * * 6"  # 5:00 UTC every Saturday

jobs:
  vader:
    name: Vader
    runs-on: ubuntu-latest

    steps:
      - name: Git clone
        uses: actions/checkout@v3

      - name: Instal Vader
        run: git clone --depth=1 https://github.com/junegunn/vader.vim.git

      - name: Run tests
        run: test/run

  pytest:
    name: pytest
    runs-on: ubuntu-latest

    strategy:
      matrix:
        python-version:
          - "3.7"
          - "3.8"
          - "3.9"
          - "3.10"
          - "3.11"

    steps:
      - name: Git clone
        uses: actions/checkout@v3

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: "${{ matrix.python-version }}"

      - name: Pip cache
        uses: actions/cache@v3
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('tox.ini') }}
          restore-keys: |
            ${{ runner.os }}-pip-${{ matrix.python-version }}-
            ${{ runner.os }}-pip-

      - name: Install dependencies
        run: |
          python -m pip install -U pip
          python -m pip install -U setuptools wheel
          python -m pip install -U tox

      - name: Run tests
        run: tox -e py

  lint:
    name: ${{ matrix.toxenv }}
    runs-on: ubuntu-latest

    strategy:
      matrix:
        toxenv:
          - coverage

    steps:
      - name: Git clone
        uses: actions/checkout@v3

      - name: Set up Python ${{ env.default_python || '3.9' }}
        uses: actions/setup-python@v4
        with:
          python-version: "${{ env.default_python || '3.9' }}"

      - name: Pip cache
        uses: actions/cache@v3
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ matrix.toxenv }}-${{ hashFiles('tox.ini') }}
          restore-keys: |
            ${{ runner.os }}-pip-${{ matrix.toxenv }}-
            ${{ runner.os }}-pip-

      - name: Install dependencies
        run: |
          python -m pip install -U pip
          python -m pip install -U setuptools wheel
          python -m pip install -U tox

      - name: Run ${{ matrix.toxenv }}
        run: tox -e ${{ matrix.toxenv }}