Unverified Commit fbf6b856 authored by Célina's avatar Célina Committed by GitHub
Browse files

use style bot GH Action from `huggingface_hub` (#10970)



use style bot GH action from hfh
Co-authored-by: default avatarSayak Paul <spsayakpaul@gmail.com>
parent e031caf4
...@@ -9,160 +9,43 @@ permissions: ...@@ -9,160 +9,43 @@ permissions:
pull-requests: write pull-requests: write
jobs: jobs:
check-permissions: style:
if: > uses: huggingface/huggingface_hub/.github/workflows/style-bot-action.yml@main
contains(github.event.comment.body, '@bot /style') && with:
github.event.issue.pull_request != null python_quality_dependencies: "[quality]"
runs-on: ubuntu-latest pre_commit_script_name: "Download and Compare files from the main branch"
outputs: pre_commit_script: |
is_authorized: ${{ steps.check_user_permission.outputs.has_permission }} echo "Downloading the files from the main branch"
steps:
- name: Check user permission curl -o main_Makefile https://raw.githubusercontent.com/huggingface/diffusers/main/Makefile
id: check_user_permission curl -o main_setup.py https://raw.githubusercontent.com/huggingface/diffusers/refs/heads/main/setup.py
uses: actions/github-script@v6 curl -o main_check_doc_toc.py https://raw.githubusercontent.com/huggingface/diffusers/refs/heads/main/utils/check_doc_toc.py
with:
script: | echo "Compare the files and raise error if needed"
const comment_user = context.payload.comment.user.login;
const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({ diff_failed=0
owner: context.repo.owner, if ! diff -q main_Makefile Makefile; then
repo: context.repo.repo, echo "Error: The Makefile has changed. Please ensure it matches the main branch."
username: comment_user diff_failed=1
}); fi
const authorized = permission.permission === 'admin';
console.log(`User ${comment_user} has permission level: ${permission.permission}, authorized: ${authorized} (only admins allowed)`); if ! diff -q main_setup.py setup.py; then
core.setOutput('has_permission', authorized); echo "Error: The setup.py has changed. Please ensure it matches the main branch."
diff_failed=1
run-style-bot: fi
needs: check-permissions
if: needs.check-permissions.outputs.is_authorized == 'true' if ! diff -q main_check_doc_toc.py utils/check_doc_toc.py; then
runs-on: ubuntu-latest echo "Error: The utils/check_doc_toc.py has changed. Please ensure it matches the main branch."
steps: diff_failed=1
- name: Extract PR details fi
id: pr_info
uses: actions/github-script@v6 if [ $diff_failed -eq 1 ]; then
with: echo "❌ Error happened as we detected changes in the files that should not be changed ❌"
script: | exit 1
const prNumber = context.payload.issue.number; fi
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner, echo "No changes in the files. Proceeding..."
repo: context.repo.repo, rm -rf main_Makefile main_setup.py main_check_doc_toc.py
pull_number: prNumber style_command: "make style && make quality"
}); secrets:
bot_token: ${{ secrets.GITHUB_TOKEN }}
// We capture both the branch ref and the "full_name" of the head repo \ No newline at end of file
// so that we can check out the correct repository & branch (including forks).
core.setOutput("prNumber", prNumber);
core.setOutput("headRef", pr.head.ref);
core.setOutput("headRepoFullName", pr.head.repo.full_name);
- name: Check out PR branch
uses: actions/checkout@v3
env:
HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
HEADREF: ${{ steps.pr_info.outputs.headRef }}
with:
# Instead of checking out the base repo, use the contributor's repo name
repository: ${{ env.HEADREPOFULLNAME }}
ref: ${{ env.HEADREF }}
# You may need fetch-depth: 0 for being able to push
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Debug
env:
HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
HEADREF: ${{ steps.pr_info.outputs.headRef }}
PRNUMBER: ${{ steps.pr_info.outputs.prNumber }}
run: |
echo "PR number: $PRNUMBER"
echo "Head Ref: $HEADREF"
echo "Head Repo Full Name: $HEADREPOFULLNAME"
- name: Set up Python
uses: actions/setup-python@v4
- name: Install dependencies
run: |
pip install .[quality]
- name: Download necessary files from main branch of Diffusers
run: |
curl -o main_Makefile https://raw.githubusercontent.com/huggingface/diffusers/main/Makefile
curl -o main_setup.py https://raw.githubusercontent.com/huggingface/diffusers/refs/heads/main/setup.py
curl -o main_check_doc_toc.py https://raw.githubusercontent.com/huggingface/diffusers/refs/heads/main/utils/check_doc_toc.py
- name: Compare the files and raise error if needed
run: |
diff_failed=0
if ! diff -q main_Makefile Makefile; then
echo "Error: The Makefile has changed. Please ensure it matches the main branch."
diff_failed=1
fi
if ! diff -q main_setup.py setup.py; then
echo "Error: The setup.py has changed. Please ensure it matches the main branch."
diff_failed=1
fi
if ! diff -q main_check_doc_toc.py utils/check_doc_toc.py; then
echo "Error: The utils/check_doc_toc.py has changed. Please ensure it matches the main branch."
diff_failed=1
fi
if [ $diff_failed -eq 1 ]; then
echo "❌ Error happened as we detected changes in the files that should not be changed ❌"
exit 1
fi
echo "No changes in the files. Proceeding..."
rm -rf main_Makefile main_setup.py main_check_doc_toc.py
- name: Run make style and make quality
run: |
make style && make quality
- name: Commit and push changes
id: commit_and_push
env:
HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
HEADREF: ${{ steps.pr_info.outputs.headRef }}
PRNUMBER: ${{ steps.pr_info.outputs.prNumber }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "HEADREPOFULLNAME: $HEADREPOFULLNAME, HEADREF: $HEADREF"
# Configure git with the Actions bot user
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Make sure your 'origin' remote is set to the contributor's fork
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/$HEADREPOFULLNAME.git"
# 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 to the original contributor's forked branch
git push origin HEAD:$HEADREF
echo "changes_pushed=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit."
echo "changes_pushed=false" >> $GITHUB_OUTPUT
fi
- 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 }}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment