-
Couldn't load subscription status.
- Fork 6.5k
[misc] feat: introduce a style bot. #10274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
bf57be5
95406d2
35c1552
b967a17
f7c715c
da671ea
91aa46b
a7b04ff
fea8f84
118cb2a
a19230a
d7c24d3
4c7fdea
f778226
ee5cbdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 }} | ||
sayakpaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - name: Debug | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }} | ||
|
||
| 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 }} | ||
Uh oh!
There was an error while loading. Please reload this page.