-
Notifications
You must be signed in to change notification settings - Fork 3
104 lines (87 loc) · 3.08 KB
/
pre-commit-update.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Update pre-commit
#######
# Updates pre-commit's hooks, runs pre-commit, and commits all changes into a PR.
#######
on:
schedule:
- cron: "0 20 * * SUN" # Sunday @ 2000 UTC
workflow_dispatch:
workflow_call:
inputs:
pre-commit-source:
description: "The arguments for `pip install` to install pre-commit; use ./path/to/package[dev] for the repo's pinned version."
default: ".[dev]"
type: string
create-changenote:
description: "Defaults 'true' to create a misc changenote in the './changes' directory."
default: true
type: boolean
permissions:
pull-requests: write
env:
BRANCH_NAME: "autoupdates/pre-commit"
CHANGENOTE_DIR: "./changes"
FORCE_COLOR: "1"
defaults:
run:
shell: bash
jobs:
pre-commit-update:
name: Update Pre-commit config
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
token: ${{ secrets.BRUTUS_PAT_TOKEN }}
- name: Configure git
run: |
git config user.email "brutus@beeware.org"
git config user.name "Brutus (robot)"
- name: Set up Python
uses: actions/setup-python@v4.6.0
with:
python-version: 3.X
- name: Install pre-commit
run: python -m pip install ${{ inputs.pre-commit-source || 'pre-commit' }}
- name: Update pre-commit hooks
run: |
pre-commit autoupdate
pre-commit install-hooks
- name: Run pre-commit
# pre-commit returns non-zero when files are changed and fails the job
continue-on-error: true
run: pre-commit run --all-files
- name: PR Needed?
id: pr
run: |
if [[ $(git status --porcelain) ]]; then
echo "needed=true" >> ${GITHUB_OUTPUT}
else
echo "needed=false" >> ${GITHUB_OUTPUT}
fi
- name: Create Pull Request
id: created-pr
if: steps.pr.outputs.needed == 'true'
uses: peter-evans/create-pull-request@v5.0.1
with:
token: ${{ secrets.BRUTUS_PAT_TOKEN }}
title: "Auto-update `pre-commit` hooks"
branch: ${{ env.BRANCH_NAME }}
commit-message: "Auto-updated `pre-commit` hooks."
committer: "Brutus (robot) <brutus@beeware.org>"
author: "Brutus (robot) <brutus@beeware.org>"
body: "Updated `pre-commit` hooks to their latest versions and ran updated hooks against the repo."
labels: "dependencies"
- name: Add changenote
if: (inputs.create-changenote == true) && (steps.created-pr.outputs.pull-request-number != '')
run: |
git fetch origin
git checkout ${{ env.BRANCH_NAME }}
FILENAME="${{ env.CHANGENOTE_DIR }}/${{ steps.created-pr.outputs.pull-request-number }}.misc.rst"
printf 'Updated ``pre-commit`` hooks to the latest version.\n' > "${FILENAME}"
git add "${FILENAME}"
git commit -m "Add changenote."
git push --set-upstream origin ${{ env.BRANCH_NAME }}