Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/pr_style_bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

name: PR Style Bot

on:
issue_comment:
types: [created]

permissions:
contents: write
pull-requests: write

jobs:
run-style-bot:
if: >
contains(github.event.comment.body, '@bot /style') &&
github.event.issue.pull_request != null
runs-on: ubuntu-latest

steps:
- name: Extract PR details
id: pr_info
uses: actions/github-script@v6
with:
script: |
const prNumber = context.payload.issue.number;
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
core.setOutput("prNumber", prNumber);
core.setOutput("headRef", pr.head.ref);

- name: Check out PR branch
uses: actions/checkout@v3
with:
repository: ${{ github.repository }}
ref: ${{ steps.pr_info.outputs.headRef }}

- name: Debug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you do the same here ? create 3 env variable and use them on the run

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the latest changes work?

run: echo "Full results ${{ steps.pr_info.outputs.headRef }}"

- name: Set up Python
uses: actions/setup-python@v4

- name: Install dependencies
run: |
pip install .[quality]

- name: Run make style and make quality
run: |
make style && make quality

- name: Commit and push changes
id: commit_and_push
run: |
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# If there are changes after running style/quality, commit them
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "Apply style fixes"
# Push back to the PR branch
git push origin HEAD:${{ steps.pr_info.outputs.headRef }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will push to diffusers/headRef instead of the original contributor's forked repo'branch (if it is from a forked repository) - If I am not making mistake here.

Better to revise this part I think :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I PoC'd it here: https://github.com/sayakpaul/poc-style-bot in sayakpaul/poc-style-bot#1.

If you have ideas about revisions, please provide them.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because your PR is opened by a branch pushed to the same repository. To actually test the situation, you have to fork the repository poc-style-bot say to (under another github account sayakapaul_2), push a branch to sayakapaul_2/poc-style-bot, and opening a PR in sayakpaul/poc-style-bot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ydshieh I pushed some updates to account for your comment here #10274 (comment). LMK.

Copy link
Contributor

@ydshieh ydshieh Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks my comment is addressed, although I didn't check line by line.

I always recommend to test it with a external contributor (a new github account, say sayakpaul2) opening a PR from it's forked repo. to your POC repository (under @sayakpaul).

But I will leave the final decision to you :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with external contributor here sayakpaul/poc-style-bot#2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo "changes_pushed=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit."
echo "changes_pushed=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Comment on PR with workflow run link
if: steps.commit_and_push.outputs.changes_pushed == 'true'
uses: actions/github-script@v6
with:
script: |
const prNumber = parseInt(process.env.prNumber, 10);
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `Style fixes have been applied. [View the workflow run here](${runUrl}).`
});
env:
prNumber: ${{ steps.pr_info.outputs.prNumber }}
4 changes: 2 additions & 2 deletions .github/workflows/pr_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Fast tests for PRs

on:
pull_request:
branches:
- main
branches: [main]
types: [synchronize]
paths:
- "src/diffusers/**.py"
- "benchmarks/**.py"
Expand Down
Loading