-
Notifications
You must be signed in to change notification settings - Fork 1
63 lines (52 loc) · 1.97 KB
/
update-pre-commit.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
61
62
63
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
with:
# token with read/write repo access for abd-vro-machine
token: ${{ secrets.ABD_VRO_MACHINE_READ_WRITE_REPO }}
- 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
# same read/write token as the checkout step
token: ${{ secrets.ABD_VRO_MACHINE_READ_WRITE_REPO }}