-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (50 loc) · 1.85 KB
/
update_pre_commit_hooks.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: Update pre-commit hooks
on:
schedule:
- cron: '0 0 * * 0' # Runs every Sunday at midnight UTC
push:
branches:
- main # Runs when changes are pushed to the main branch
jobs:
update-pre-commit-hooks:
runs-on: ubuntu-latest
steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
# Install pre-commit
- name: Install pre-commit
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Run pre-commit autoupdate
# Run pre-commit autoupdate to update the hook versions
run: pre-commit autoupdate
# Set git user identity to avoid "empty ident name" error
- 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
# Check for changes and push updates only if there are changes
run: |
# Check if there are any changes to commit
git diff --exit-code
if [ $? -eq 0 ]; then
echo "No changes detected, skipping commit."
exit 0 # No changes, so skip the commit step
fi
# If changes are detected, continue with committing and pushing
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 checkout $BRANCH_NAME
else
echo "Branch $BRANCH_NAME does not exist, creating it."
git checkout -b $BRANCH_NAME
fi
# Commit and push changes
git add .pre-commit-config.yaml
git commit -m 'Update pre-commit hook versions'
git push -u origin $BRANCH_NAME