Skip to content

Commit d59ce25

Browse files
authored
Add style bot (#1077)
* init * Apply suggestion from @NathanHB * Apply suggestion from @NathanHB * Apply suggestion from @NathanHB * Apply suggestion from @NathanHB * Apply suggestion from @NathanHB * try 2
1 parent 7f50228 commit d59ce25

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

.github/workflows/pr_style_bot.yaml

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,37 @@ jobs:
3636
core.setOutput("headRepoFullName", pr.head.repo.full_name);
3737
- name: Check out PR branch
3838
uses: actions/checkout@v3
39+
env:
40+
HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
41+
HEADREF: ${{ steps.pr_info.outputs.headRef }}
3942
with:
40-
repository: ${{ steps.pr_info.outputs.headRepoFullName }}
41-
ref: ${{ steps.pr_info.outputs.headRef }}
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
4247
fetch-depth: 0
4348
token: ${{ secrets.GITHUB_TOKEN }}
4449

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+
4560
- name: Set up Python
4661
uses: actions/setup-python@v4
47-
4862
- name: Install dependencies
49-
run: pip install .[quality]
50-
51-
- name: Apply style fixes
5263
run: |
53-
ruff format .
54-
ruff check --fix .
64+
pip install .[quality]
5565
66+
- name: Run ruff format --check
67+
run: |
68+
uv run ruff format --check .
69+
uv run ruff check --fix .
5670
- name: Commit and push changes
5771
id: commit_and_push
5872
env:
@@ -61,27 +75,35 @@ jobs:
6175
PRNUMBER: ${{ steps.pr_info.outputs.prNumber }}
6276
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6377
run: |
78+
echo "HEADREPOFULLNAME: ${{ env.HEADREPOFULLNAME }}, HEADREF: ${{ env.HEADREF }}"
79+
# Configure git with the Actions bot user
6480
git config user.name "github-actions[bot]"
6581
git config user.email "github-actions[bot]@users.noreply.github.com"
82+
# Make sure your 'origin' remote is set to the contributor's fork
6683
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
6785
if [ -n "$(git status --porcelain)" ]; then
6886
git add .
6987
git commit -m "Apply style fixes"
88+
# Push to the original contributor's forked branch
7089
git push origin HEAD:${{ env.HEADREF }}
7190
echo "changes_pushed=true" >> $GITHUB_OUTPUT
7291
else
92+
echo "No changes to commit."
7393
echo "changes_pushed=false" >> $GITHUB_OUTPUT
7494
fi
75-
- name: Comment on PR
95+
- name: Comment on PR with workflow run link
7696
if: steps.commit_and_push.outputs.changes_pushed == 'true'
7797
uses: actions/github-script@v6
7898
with:
7999
script: |
80-
const prNumber = ${{ steps.pr_info.outputs.prNumber }};
81-
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
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}`
82102
await github.rest.issues.createComment({
83103
owner: context.repo.owner,
84104
repo: context.repo.repo,
85105
issue_number: prNumber,
86106
body: `Style fixes have been applied. [View the workflow run here](${runUrl}).`
87107
});
108+
env:
109+
prNumber: ${{ steps.pr_info.outputs.prNumber }}

0 commit comments

Comments
 (0)