name: pre-commit

on:
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  pre-commit:
    runs-on: ["self-hosted", "linux"]
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0  # Required for us to have a valid ref to the target branch
    - uses: actions/setup-python@v3
    - uses: actions/cache@v3
      with:
        path: ~/.cache/pre-commit/
        key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
    - uses: webfactory/ssh-agent@v0.8.0
      with:
        ssh-private-key: ${{ secrets.PRE_COMMIT_SCRIPTS_DEPLOY_KEY }}
    - name: SSH Keys and known_hosts
      run: |
        mkdir -p ~/.ssh/ && touch ~/.ssh/known_hosts
        ssh-keyscan github.com >> ~/.ssh/known_hosts
    - uses: pre-commit/action@v3.0.0
      with:
        extra_args: "--from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}"
