name: Pre-commit check

on:
  push:
    branches-ignore:
    - dependabot/**
    - deepsource**
  pull_request:

jobs:
  pre-commit:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.10'
        cache: pip
        cache-dependency-path: requirements/*.txt
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip wheel
        pip install -r requirements/dev.txt
    - name: pre-commit
      run: pre-commit run --all

  pydocstyle:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.10'
        cache: pip
        cache-dependency-path: requirements/*.txt
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip wheel
        pip install -r requirements/dev.txt
    - name: Run pydocstyle
      run: |
        echo "::add-matcher::.github/matchers/flake8.json"
        pre-commit run --all pydocstyle
        echo "::remove-matcher owner=flake8::"

  flake8:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.10'
        cache: pip
        cache-dependency-path: requirements/*.txt
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip wheel
        pip install -r requirements/dev.txt
    - name: Run flake8
      run: |
        echo "::add-matcher::.github/matchers/flake8.json"
        pre-commit run --all flake8
        echo "::remove-matcher owner=flake8::"
