-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (96 loc) · 3.51 KB
/
pre-commit-autoupdate.yaml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Update pre-commit hooks
on:
schedule:
# Every monday at 7 AM
- cron: 0 7 * * 1
push:
branches:
- main
page_build:
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
# Give the default GITHUB_TOKEN write permission to create or update
# pull requests
pull-requests: write
jobs:
update:
runs-on: ubuntu-latest
if: github.repository_owner == 'mindstream-it'
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
.pre-commit-config.yaml
- uses: actions/setup-python@v5
with:
# Read python version from a file .python-version
python-version-file: '.python-version'
- uses: actions/cache@v4
with:
path: |
~/.cache/pre-commit
~/.cache/pip
key: "pre-commit-3|\
${{ env.pythonLocation }}|\
${{ hashFiles('.pre-commit-config.yaml') }}"
- name: Install pre-commit
run: python -m pip install pre-commit
- name: Freeze pre-commit
run: python -m pip freeze --local
- name: Run `pre-commit autoupdate`
id: pre-commit-autoupdate
run: |
echo 'LOG<<_PRECOMMIT_EOF' >>"$GITHUB_OUTPUT"
{
set -euo pipefail
pre-commit autoupdate --freeze --color=never 2>&1
} | tee -a "$GITHUB_OUTPUT"
echo '_PRECOMMIT_EOF' >>"$GITHUB_OUTPUT"
- name: Create branch
id: pre-commit-create-branch
if: contains(steps.pre-commit-autoupdate.outputs.LOG, ' updating ')
# https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#create-a-reference
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${GITHUB_REPOSITORY}/git/refs" \
-f ref="refs/heads/${NEW_BRANCH_NAME}" \
-f sha="${GITHUB_SHA}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_BRANCH_NAME: "bot-pre-commit-autoupdate-\
${{ hashFiles('.pre-commit-config.yaml') }}"
- uses: planetscale/[email protected]
# Commit changed files back to the repository
# if no changed files then continue without error
if: contains(steps.pre-commit-autoupdate.outputs.LOG, ' updating ')
with:
commit_message: "chore(deps): Update pre-commit hooks"
repo: ${{ github.repository }}
branch: "bot-pre-commit-autoupdate-\
${{ hashFiles('.pre-commit-config.yaml') }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: peter-evans/[email protected]
# Open Pull Requests if there are any commits on the target branch
if: contains(steps.pre-commit-autoupdate.outputs.LOG, ' updating ')
with:
branch: "bot-pre-commit-autoupdate-\
${{ hashFiles('.pre-commit-config.yaml') }}"
title: "chore(deps): Update pre-commit hooks"
body: |
Updates pre-commit hooks
<details>
<summary>
<code>pre-commit autoupdate --freeze --color=never</code>
</summary>
```
${{ steps.pre-commit-autoupdate.outputs.LOG }}
```
</details>
labels: dependencies
delete-branch: True