Skip to content

Commit bf57be5

Browse files
committed
feat: introduce a style bot.
1 parent ec1c7a7 commit bf57be5

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

.github/workflows/pr_style_bot.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
name: PR Style Bot
3+
4+
on:
5+
issue_comment:
6+
types: [created]
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
run-style-bot:
14+
if: >
15+
contains(github.event.comment.body, '@bot /style') &&
16+
github.event.issue.pull_request != null
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Extract PR details
21+
id: pr_info
22+
uses: actions/github-script@v6
23+
with:
24+
script: |
25+
const prNumber = context.payload.issue.number;
26+
const { data: pr } = await github.rest.pulls.get({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
pull_number: prNumber
30+
});
31+
core.setOutput("prNumber", prNumber);
32+
core.setOutput("headRef", pr.head.ref);
33+
34+
- name: Check out PR branch
35+
uses: actions/checkout@v3
36+
with:
37+
repository: ${{ github.repository }}
38+
ref: ${{ steps.pr_info.outputs.headRef }}
39+
40+
- name: Debug
41+
run: echo "Full results ${{ steps.pr_info.outputs.headRef }}"
42+
43+
- name: Set up Python
44+
uses: actions/setup-python@v4
45+
46+
- name: Install dependencies
47+
run: |
48+
pip install .[quality]
49+
50+
- name: Run make style and make quality
51+
run: |
52+
make style && make quality
53+
54+
- name: Commit and push changes
55+
id: commit_and_push
56+
run: |
57+
# Configure git
58+
git config user.name "github-actions[bot]"
59+
git config user.email "github-actions[bot]@users.noreply.github.com"
60+
61+
# If there are changes after running style/quality, commit them
62+
if [ -n "$(git status --porcelain)" ]; then
63+
git add .
64+
git commit -m "Apply style fixes"
65+
# Push back to the PR branch
66+
git push origin HEAD:${{ steps.pr_info.outputs.headRef }}
67+
echo "changes_pushed=true" >> $GITHUB_OUTPUT
68+
else
69+
echo "No changes to commit."
70+
echo "changes_pushed=false" >> $GITHUB_OUTPUT
71+
fi
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
75+
- name: Comment on PR with workflow run link
76+
if: steps.commit_and_push.outputs.changes_pushed == 'true'
77+
uses: actions/github-script@v6
78+
with:
79+
script: |
80+
const prNumber = parseInt(process.env.prNumber, 10);
81+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
82+
83+
await github.rest.issues.createComment({
84+
owner: context.repo.owner,
85+
repo: context.repo.repo,
86+
issue_number: prNumber,
87+
body: `Style fixes have been applied. [View the workflow run here](${runUrl}).`
88+
});
89+
env:
90+
prNumber: ${{ steps.pr_info.outputs.prNumber }}

.github/workflows/pr_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: Fast tests for PRs
22

33
on:
44
pull_request:
5-
branches:
6-
- main
5+
branches: [main]
6+
types: [synchronize]
77
paths:
88
- "src/diffusers/**.py"
99
- "benchmarks/**.py"

0 commit comments

Comments
 (0)