Skip to content

Commit e1fba23

Browse files
authored
Merge pull request #912 from xylar/fix-pre-commit-update-workflow
Update the pre-commit upate workflow
2 parents f68f9fb + 674764d commit e1fba23

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

.github/workflows/pre_commit_update_workflow.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
# 4. Entry: Month of the year when the process will be started [1-12]
1010
# 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday]
1111
- cron: '0 8 * * 3'
12+
# Allow manual triggering of the workflow
13+
workflow_dispatch:
1214

1315
env:
1416
UP_TO_DATE: false
@@ -39,10 +41,12 @@ jobs:
3941
git checkout -b update-pre-commit-deps
4042
pre-commit autoupdate
4143
git add .
42-
# The second command will fail if no changes were present, so we ignore it
43-
git commit -m "Update pre-commit dependencies" || ( echo "UP_TO_DATE=true" >> "$GITHUB_ENV")
44+
# Either there are changes, in which case we commit them, or there are no changes,
45+
# in which case we can skip the push & pr-create jobs
46+
git commit -m "Update pre-commit dependencies" \
47+
|| ( echo "UP_TO_DATE=true" >> "$GITHUB_ENV")
4448
45-
- name: Push Changes
49+
- name: Push Changes with github-actions bot
4650
if: ${{ env.UP_TO_DATE == 'false' }}
4751
uses: ad-m/github-push-action@master
4852
with:
@@ -53,16 +57,30 @@ jobs:
5357
env:
5458
GH_TOKEN: ${{ github.token }}
5559

56-
- name: Make PR and add reviewers and labels
60+
- name: Create PR with github-actions bot
5761
if: ${{ env.UP_TO_DATE == 'false' }}
5862
run: |
5963
cd update-pre-commit-deps
6064
gh pr create \
61-
--title "Update pre-commit and its dependencies" \
62-
--body "This PR was auto-generated to update pre-commit and its dependencies." \
63-
--head update-pre-commit-deps \
64-
--reviewer ${{ env.REVIEWERS }} \
65-
--label ci
65+
--title "Update pre-commit and its dependencies" \
66+
--body "This PR was auto-generated to update pre-commit and its dependencies." \
67+
--head update-pre-commit-deps
6668
env:
6769
GH_TOKEN: ${{ github.token }}
6870

71+
- name: Add reviewers and labels with PAT
72+
if: ${{ env.UP_TO_DATE == 'false' }}
73+
run: |
74+
cd update-pre-commit-deps
75+
76+
gh pr edit --add-label ci
77+
78+
IFS=',' read -ra reviewers <<< "${REVIEWERS}"
79+
for reviewer in "${reviewers[@]}"; do
80+
echo "Adding reviewer: $reviewer"
81+
gh pr edit --add-reviewer "$reviewer"
82+
done
83+
84+
env:
85+
REVIEWERS: ${{ env.REVIEWERS }}
86+
GH_TOKEN: ${{ secrets.GH_CLI_TOKEN }}

0 commit comments

Comments
 (0)