name: Pre-commit checks
on:
  workflow_dispatch:

permissions: {}

jobs:
  pre-commit-checks:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false
      - name: Set up Python
        uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: "3.10"
          cache: "pip"
      - name: Check Pull Request Title
        uses: Slashgear/action-check-pr-title@76166c63ec0b25cdbe693e5e972e83ca186313fb # main
        with:
          regexp: '(break|build|ci|docs|feat|fix|perf|refactor|style|test|ops|hotfix|release|maint|init|enh|revert)\([a-z,A-Z,0-9,\-,\_,\/,:]+\)(:)\s{1}([\w\s]+)' # Regex the title should match.
      - name: Getting changed files list
        id: files
        uses: jitterbit/get-changed-files@b17fbb00bdc0c0f63fcf166580804b4d2cdc2a42 # v1
      - name: Checking changed files
        env:
          CHANGED_FILES: ${{ steps.files.outputs.all }}
        shell: bash
        run: |
          echo "Changed files"
          echo "$CHANGED_FILES"
          echo "GitHub Client version"
          gh --version
      - name: Pre-Commit Checks
        env:
          CHANGED_FILES: ${{ steps.files.outputs.all }}
        run: |
          python -m pip install --upgrade pip
          pip install pre-commit
          echo "Running pre-commit scans:"
          # adding log display in case of pre-commit errors
          # shellcheck disable=SC2086
          pre-commit run -v --files $CHANGED_FILES
        shell: bash
