-
Notifications
You must be signed in to change notification settings - Fork 13
85 lines (70 loc) · 2.22 KB
/
pre-commit-autoupdate.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: "pre-commit autoupdate"
on:
schedule:
- cron: 20 4 * * *
workflow_dispatch:
jobs:
pre-commit-autoupdate:
name: pre-commit autoupdate
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Setup pre-commit
run: |
python -m pip install --upgrade pre-commit
pre-commit --version
- name: Run pre-commit autoupdate
id: autoupdate
run: |
echo "log<<EOF" >>$GITHUB_OUTPUT
pre-commit autoupdate | tee -a >(cat >> $GITHUB_OUTPUT)
echo 'EOF' >> $GITHUB_OUTPUT
- name: Check diff
id: diff
shell: bash
run: |
echo 'diff<<EOF' >> $GITHUB_OUTPUT
git diff | tee -a >(cat >> $GITHUB_OUTPUT)
echo 'EOF' >> $GITHUB_OUTPUT
- name: Create PR
if: ${{ steps.diff.outputs.diff != '' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
set -xeu
git switch -c pre-commit-autoupdate
git add .
git config --global user.name "pre-commit autoupdate"
git config --global user.email "[email protected]"
git commit -m "pre-commit autoupdate"
git push --force --set-upstream origin pre-commit-autoupdate
title="pre-commit autoupdate"
body_file=/tmp/body
echo '```' >> $body_file
echo '$ pre-commit autoupdate' >> $body_file
echo '${{steps.autoupdate.outputs.log}}' >> $body_file
echo '```' >> $body_file
body="$(cat $body_file)"
pr_number=$(gh pr list -S "pre-commit autoupdate" --json number --jq '.[0].number')
if [[ -z $pr_number ]]; then
echo "Creating PR"
gh pr create \
--label dependencies \
--title "$title" \
--body "$body"
exit 0
fi
echo "Updating PR \#${pr_number}"
gh pr edit \
$pr_number \
--body "$body" \
--title "$title"