Pre-Commit Updates #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: Pre-Commit Updates | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Daily at midnight | |
workflow_dispatch: # Manual trigger | |
jobs: | |
update-deps: | |
runs-on: ubuntu-latest | |
env: | |
# Space separated list of repos to exclude from the update | |
EXCLUDED_REPOS: "https://github.com/python-poetry/poetry" | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: "Install Python" | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12.3" | |
cache: "pip" | |
- name: Install Pre-Commit and yq | |
run: | | |
pip install pre-commit yq | |
- name: Extract Repos Excluding Poetry | |
id: extract_repos | |
run: | | |
# Convert EXCLUDED_REPOS to a grep pattern | |
EXCLUDE_PATTERN=$(echo "$EXCLUDED_REPOS" | tr ' ' '|') | |
# Extract repos and exclude those defined in EXCLUDED_REPOS | |
REPOS=$(yq '.repos[].repo' .pre-commit-config.yaml | \ | |
grep -Ev "$EXCLUDE_PATTERN" | \ | |
xargs -n1 echo --repo | tr '\n' ' ') | |
# Properly escape the output for GitHub Actions - percent (%), newline (\n), and carriage return (\r) | |
REPOS="${REPOS//'%'/'%25'}" | |
REPOS="${REPOS//$'\n'/'%0A'}" | |
REPOS="${REPOS//$'\r'/'%0D'}" | |
echo "repos=${REPOS}" >> "$GITHUB_OUTPUT" | |
- name: Run Pre-Commit Autoupdate | |
run: | | |
pre-commit autoupdate ${{ steps.extract_repos.outputs.repos }} | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
title: 'chore: update pre-commit hooks' | |
commit-message: 'chore: update pre-commit hooks' | |
branch: update-pre-commit-hooks |