Skip to content

Commit 5993fb1

Browse files
committed
Add pre-commit autoupdate workflow
1 parent f25c814 commit 5993fb1

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Pre-commit auto-update
2+
3+
on:
4+
schedule:
5+
# Cron syntax:
6+
# 1. Entry: Minute when the process will be started [0-60]
7+
# 2. Entry: Hour when the process will be started [0-23]
8+
# 3. Entry: Day of the month when the process will be started [1-28/29/30/31]
9+
# 4. Entry: Month of the year when the process will be started [1-12]
10+
# 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday]
11+
- cron: '0 8 * * 3'
12+
13+
env:
14+
UP_TO_DATE: false
15+
16+
jobs:
17+
auto-update:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.10"
26+
27+
- name: Install pre-commit
28+
run: pip install pre-commit
29+
30+
- name: Apply and commit updates
31+
run: |
32+
git clone https://github.com/E3SM-Project/polaris.git update-pre-commit-deps
33+
cd update-pre-commit-deps
34+
# Configure git using GitHub Actions credentials.
35+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
36+
git config --local user.name "github-actions[bot]"
37+
git checkout -b update-pre-commit-deps
38+
pre-commit autoupdate
39+
git add .
40+
# The second command will fail if no changes were present, so we ignore it
41+
git commit -m "Update pre-commit dependencies" || ( echo "UP_TO_DATE=true" >> "$GITHUB_ENV")
42+
43+
- name: Push Changes
44+
if: ${{ env.UP_TO_DATE == 'false' }}
45+
uses: ad-m/github-push-action@master
46+
with:
47+
branch: update-pre-commit-deps
48+
directory: update-pre-commit-deps
49+
github_token: ${{ secrets.GITHUB_TOKEN }}
50+
force: true
51+
env:
52+
GH_TOKEN: ${{ github.token }}
53+
54+
- name: Make PR and add reviewers and labels
55+
if: ${{ env.UP_TO_DATE == 'false' }}
56+
run: |
57+
cd update-pre-commit-deps
58+
gh pr create \
59+
--title "Update pre-commit and its dependencies" \
60+
--body "This PR was auto-generated to update pre-commit and its dependencies." \
61+
--head update-pre-commit-deps \
62+
--reviewer altheaden,xylar \
63+
--label ci
64+
env:
65+
GH_TOKEN: ${{ github.token }}
66+

0 commit comments

Comments
 (0)