@@ -9,12 +9,33 @@ permissions:
99 pull-requests : write
1010
1111jobs :
12- run-style-bot :
12+ check-permissions :
1313 if : >
1414 contains(github.event.comment.body, '@bot /style') &&
1515 github.event.issue.pull_request != null
1616 runs-on : ubuntu-latest
17+ outputs :
18+ is_authorized : ${{ steps.check_user_permission.outputs.has_permission }}
19+ steps :
20+ - name : Check user permission
21+ id : check_user_permission
22+ uses : actions/github-script@v6
23+ with :
24+ script : |
25+ const comment_user = context.payload.comment.user.login;
26+ const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({
27+ owner: context.repo.owner,
28+ repo: context.repo.repo,
29+ username: comment_user
30+ });
31+ const authorized = permission.permission === 'admin';
32+ console.log(`User ${comment_user} has permission level: ${permission.permission}, authorized: ${authorized} (only admins allowed)`);
33+ core.setOutput('has_permission', authorized);
1734
35+ run-style-bot :
36+ needs : check-permissions
37+ if : needs.check-permissions.outputs.is_authorized == 'true'
38+ runs-on : ubuntu-latest
1839 steps :
1940 - name : Extract PR details
2041 id : pr_info
5374 HEADREF : ${{ steps.pr_info.outputs.headRef }}
5475 PRNUMBER : ${{ steps.pr_info.outputs.prNumber }}
5576 run : |
56- echo "PR number: ${{ env. PRNUMBER }} "
57- echo "Head Ref: ${{ env. HEADREF }} "
58- echo "Head Repo Full Name: ${{ env. HEADREPOFULLNAME }} "
77+ echo "PR number: $PRNUMBER"
78+ echo "Head Ref: $HEADREF"
79+ echo "Head Repo Full Name: $HEADREPOFULLNAME"
5980
6081 - name : Set up Python
6182 uses : actions/setup-python@v4
@@ -64,18 +85,38 @@ jobs:
6485 run : |
6586 pip install .[quality]
6687
67- - name : Download Makefile from main branch
88+ - name : Download necessary files from main branch of Diffusers
6889 run : |
6990 curl -o main_Makefile https://raw.githubusercontent.com/huggingface/diffusers/main/Makefile
91+ curl -o main_setup.py https://raw.githubusercontent.com/huggingface/diffusers/refs/heads/main/setup.py
92+ curl -o main_check_doc_toc.py https://raw.githubusercontent.com/huggingface/diffusers/refs/heads/main/utils/check_doc_toc.py
7093
71- - name : Compare Makefiles
94+ - name : Compare the files and raise error if needed
7295 run : |
96+ diff_failed=0
97+
7398 if ! diff -q main_Makefile Makefile; then
7499 echo "Error: The Makefile has changed. Please ensure it matches the main branch."
100+ diff_failed=1
101+ fi
102+
103+ if ! diff -q main_setup.py setup.py; then
104+ echo "Error: The setup.py has changed. Please ensure it matches the main branch."
105+ diff_failed=1
106+ fi
107+
108+ if ! diff -q main_check_doc_toc.py utils/check_doc_toc.py; then
109+ echo "Error: The utils/check_doc_toc.py has changed. Please ensure it matches the main branch."
110+ diff_failed=1
111+ fi
112+
113+ if [ $diff_failed -eq 1 ]; then
114+ echo "❌ Error happened as we detected changes in the files that should not be changed ❌"
75115 exit 1
76116 fi
77- echo "No changes in Makefile. Proceeding..."
78- rm -rf main_Makefile
117+
118+ echo "No changes in the files. Proceeding..."
119+ rm -rf main_Makefile main_setup.py main_check_doc_toc.py
79120
80121 - name : Run make style and make quality
81122 run : |
@@ -89,20 +130,20 @@ jobs:
89130 PRNUMBER : ${{ steps.pr_info.outputs.prNumber }}
90131 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
91132 run : |
92- echo "HEADREPOFULLNAME: ${{ env. HEADREPOFULLNAME }} , HEADREF: ${{ env. HEADREF }} "
133+ echo "HEADREPOFULLNAME: $HEADREPOFULLNAME, HEADREF: $HEADREF"
93134 # Configure git with the Actions bot user
94135 git config user.name "github-actions[bot]"
95136 git config user.email "github-actions[bot]@users.noreply.github.com"
96137
97138 # Make sure your 'origin' remote is set to the contributor's fork
98- git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ env. HEADREPOFULLNAME }} .git"
139+ git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/$HEADREPOFULLNAME.git"
99140
100141 # If there are changes after running style/quality, commit them
101142 if [ -n "$(git status --porcelain)" ]; then
102143 git add .
103144 git commit -m "Apply style fixes"
104145 # Push to the original contributor's forked branch
105- git push origin HEAD:${{ env. HEADREF }}
146+ git push origin HEAD:$HEADREF
106147 echo "changes_pushed=true" >> $GITHUB_OUTPUT
107148 else
108149 echo "No changes to commit."
0 commit comments