name: Pre-commit checks

on: pull_request

jobs:
  run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.9
        uses: actions/setup-python@v5
        with:
          python-version: 3.9
          cache: "pip" # caching pip dependencies

      - name: Install pre-commit
        run: |
          pip install 'pre-commit==3.3.2'
          pre-commit install

      - name: Set env variables
        run: |
          echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
          echo "PRECOMMIT=$(pip list | grep pre-commit)" >> $GITHUB_ENV

      - uses: actions/cache@v3
        with:
          path: ~/.cache/pre-commit
          key: pre-commit|${{ env.PY }}|${{ env.PRECOMMIT }}|${{ hashFiles('.pre-commit-config.yaml') }}

      - name: Run all pre-commit checks
        # TODO: remove skip once files are clean
        run: SKIP=isort pre-commit run --all-files --hook-stage manual -c .pre-commit-config.yaml
