name: Pre-commit auto-update

on:
  # every first day of the month
  schedule:
    - cron: "0 0 1 * *"
  # on demand
  workflow_dispatch:

jobs:
  auto-update:
    runs-on: ubuntu-latest

    permissions:
      contents: write
      pull-requests: write

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        with:
          python-version: 3.x

      - run: pip install pre-commit
      - run: pre-commit autoupdate
      - run: pre-commit run --all-files

      - uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
        if: always()
        env:
          GH_REPO: ${{ github.repository }}
          GH_TOKEN: ${{ github.token }}
        with:
          branch: update/pre-commit-hooks
          title: Update pre-commit hooks
          commit-message: "style: update pre-commit hooks"
          body: Update versions of pre-commit hooks to latest version.
          reviewers: "godexsoft,kuznetsss,PeterChen13579,mathbunnyru"
