|
5 | 5 | types: [created] |
6 | 6 |
|
7 | 7 | permissions: |
8 | | - contents: write |
9 | 8 | pull-requests: write |
10 | 9 |
|
11 | 10 | jobs: |
12 | | - run-style-bot: |
13 | | - if: > |
14 | | - contains(github.event.comment.body, '@bot /style') && |
15 | | - github.event.issue.pull_request != null |
16 | | -
|
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 | | -
|
32 | | - // We capture both the branch ref and the "full_name" of the head repo |
33 | | - // so that we can check out the correct repository & branch (including forks). |
34 | | - core.setOutput("prNumber", prNumber); |
35 | | - core.setOutput("headRef", pr.head.ref); |
36 | | - core.setOutput("headRepoFullName", pr.head.repo.full_name); |
37 | | - - name: Check out PR branch |
38 | | - uses: actions/checkout@v3 |
39 | | - env: |
40 | | - HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }} |
41 | | - HEADREF: ${{ steps.pr_info.outputs.headRef }} |
42 | | - with: |
43 | | - # Instead of checking out the base repo, use the contributor's repo name |
44 | | - repository: ${{ env.HEADREPOFULLNAME }} |
45 | | - ref: ${{ env.HEADREF }} |
46 | | - # You may need fetch-depth: 0 for being able to push |
47 | | - fetch-depth: 0 |
48 | | - token: ${{ secrets.GITHUB_TOKEN }} |
49 | | - |
50 | | - - name: Debug |
51 | | - env: |
52 | | - HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }} |
53 | | - HEADREF: ${{ steps.pr_info.outputs.headRef }} |
54 | | - PRNUMBER: ${{ steps.pr_info.outputs.prNumber }} |
55 | | - run: | |
56 | | - echo "PR number: ${{ env.PRNUMBER }}" |
57 | | - echo "Head Ref: ${{ env.HEADREF }}" |
58 | | - echo "Head Repo Full Name: ${{ env.HEADREPOFULLNAME }}" |
59 | | -
|
60 | | - - name: Set up Python |
61 | | - uses: actions/setup-python@v4 |
62 | | - - name: Install dependencies |
63 | | - run: | |
64 | | - pip install .[quality] |
65 | | -
|
66 | | - - name: Run ruff format --check |
67 | | - run: | |
68 | | - ruff format . |
69 | | - ruff check --fix . |
70 | | - - name: Commit and push changes |
71 | | - id: commit_and_push |
72 | | - env: |
73 | | - HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }} |
74 | | - HEADREF: ${{ steps.pr_info.outputs.headRef }} |
75 | | - PRNUMBER: ${{ steps.pr_info.outputs.prNumber }} |
76 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
77 | | - run: | |
78 | | - echo "HEADREPOFULLNAME: ${{ env.HEADREPOFULLNAME }}, HEADREF: ${{ env.HEADREF }}" |
79 | | - # Configure git with the Actions bot user |
80 | | - git config user.name "github-actions[bot]" |
81 | | - git config user.email "github-actions[bot]@users.noreply.github.com" |
82 | | - # Make sure your 'origin' remote is set to the contributor's fork |
83 | | - git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ env.HEADREPOFULLNAME }}.git" |
84 | | - # If there are changes after running style/quality, commit them |
85 | | - if [ -n "$(git status --porcelain)" ]; then |
86 | | - git add . |
87 | | - git commit -m "Apply style fixes" |
88 | | - # Push to the original contributor's forked branch |
89 | | - git push origin HEAD:${{ env.HEADREF }} |
90 | | - echo "changes_pushed=true" >> $GITHUB_OUTPUT |
91 | | - else |
92 | | - echo "No changes to commit." |
93 | | - echo "changes_pushed=false" >> $GITHUB_OUTPUT |
94 | | - fi |
95 | | - - name: Comment on PR with workflow run link |
96 | | - if: steps.commit_and_push.outputs.changes_pushed == 'true' |
97 | | - uses: actions/github-script@v6 |
98 | | - with: |
99 | | - script: | |
100 | | - const prNumber = parseInt(process.env.prNumber, 10); |
101 | | - const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` |
102 | | - await github.rest.issues.createComment({ |
103 | | - owner: context.repo.owner, |
104 | | - repo: context.repo.repo, |
105 | | - issue_number: prNumber, |
106 | | - body: `Style fixes have been applied. [View the workflow run here](${runUrl}).` |
107 | | - }); |
108 | | - env: |
109 | | - prNumber: ${{ steps.pr_info.outputs.prNumber }} |
| 11 | + style: |
| 12 | + uses: huggingface/huggingface_hub/.github/workflows/style-bot-action.yml@main |
| 13 | + with: |
| 14 | + python_quality_dependencies: "[quality]" |
| 15 | + secrets: |
| 16 | + bot_token: ${{ secrets.HF_STYLE_BOT_ACTION }} |
0 commit comments