Merge pull request #94 from nobbi1991/dev #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Create branch and push updates | |
# Create a new branch and push updates (if the branch does not exist) | |
run: | | |
# Check if the branch exists, if not, create it | |
git fetch origin | |
BRANCH_NAME="pre-commit-updates" | |
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 | |
# Add the updated .pre-commit-config.yaml file and commit changes | |
git add .pre-commit-config.yaml | |
git commit -m 'Update pre-commit hook versions' | |
# Push the changes to the branch | |
git push -u origin $BRANCH_NAME |