Skip to content

Pre-commit auto-update #20

Pre-commit auto-update

Pre-commit auto-update #20

name: Update pre-commit hooks
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
update-pre-commit-hooks:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install pre-commit
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Run pre-commit autoupdate
run: pre-commit autoupdate
- name: Set git user identity
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
- name: Check for changes and push updates
id: check-for-changes
run: |
if git diff --quiet && git diff --cached --quiet; then
echo "No changes detected, skipping commit."
echo "changes_found=false" >> $GITHUB_ENV
exit 0
fi
BRANCH_NAME="pre-commit-updates"
git fetch origin
if git rev-parse --verify origin/$BRANCH_NAME; then
echo "Branch $BRANCH_NAME exists, switching to it."
git stash
git checkout $BRANCH_NAME
else
echo "Branch $BRANCH_NAME does not exist, creating it."
git checkout -b $BRANCH_NAME
fi
git add .pre-commit-config.yaml
git commit -m 'Update pre-commit hook versions'
git push -u origin $BRANCH_NAME
echo "changes_found=true" >> $GITHUB_ENV
- name: Create pull request
if: env.changes_found == 'true'
uses: peter-evans/create-pull-request@v7
with:
title: 'Update pre-commit hook versions'
body: 'Automated update of pre-commit hooks'
branch: ${{ github.ref_name }}
commit-message: 'Update pre-commit hook versions'
labels: 'pre-commit, automated'