Skip to content

Commit afce874

Browse files
isaacbmillergithub-actions[bot]
authored andcommitted
feat(ci): Create PRs with ruff fixes automatically (stanfordnlp#9336)
* add auto-ruff fix * ruff fixable change * change pr targeting * remove merge condition * add a second ruff error * fix: ruff auto-fix for stanfordnlp#9336 (stanfordnlp#9338) Co-authored-by: isaacbmiller <17116851+isaacbmiller@users.noreply.github.com> * Delete dspy/ruff_autofix_smoke.py * add a concurrency group for prs --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent fcf879b commit afce874

2 files changed

Lines changed: 77 additions & 10 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Close Ruff Auto-fix PR
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
close-autofix-pr:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: write
12+
steps:
13+
- name: Close matching Ruff auto-fix PR
14+
uses: actions/github-script@v7
15+
with:
16+
script: |
17+
const owner = context.repo.owner;
18+
const repo = context.repo.repo;
19+
const sourcePrNumber = context.payload.pull_request.number;
20+
const head = `${owner}:ci/ruff-autofix/pr-${sourcePrNumber}`;
21+
22+
const { data: pulls } = await github.rest.pulls.list({
23+
owner,
24+
repo,
25+
state: "open",
26+
head,
27+
per_page: 100,
28+
});
29+
30+
for (const pr of pulls) {
31+
await github.rest.pulls.update({
32+
owner,
33+
repo,
34+
pull_number: pr.number,
35+
state: "closed",
36+
});
37+
}

‎.github/workflows/run_tests.yml‎

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
pull_request:
88
types: [opened, synchronize, reopened]
99

10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
12+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
13+
1014
jobs:
1115
fix:
1216
name: Check Ruff Fix
@@ -33,17 +37,43 @@ jobs:
3337
- name: Install dependencies
3438
run: uv sync --dev -p .venv --extra dev
3539
- name: Ruff Check
40+
id: ruff_check
41+
continue-on-error: true
42+
run: ruff check --fix-only --exit-non-zero-on-fix
43+
- name: Create or update Ruff auto-fix PR
44+
if: steps.ruff_check.outcome == 'failure' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
45+
uses: peter-evans/create-pull-request@v7
46+
with:
47+
token: ${{ secrets.GITHUB_TOKEN }}
48+
commit-message: "fix: ruff auto-fix for #${{ github.event.pull_request.number }}"
49+
branch: ci/ruff-autofix/pr-${{ github.event.pull_request.number }}
50+
base: ${{ github.event.pull_request.head.ref }}
51+
title: "fix: ruff auto-fix for #${{ github.event.pull_request.number }}"
52+
body: |
53+
Auto-generated Ruff fixes for #${{ github.event.pull_request.number }}.
54+
55+
Source PR: #${{ github.event.pull_request.number }}
56+
Source SHA: `${{ github.event.pull_request.head.sha }}`
57+
58+
This PR targets `${{ github.event.pull_request.head.ref }}` and is kept as a rolling branch.
59+
It will be auto-closed when the source PR is merged.
60+
delete-branch: true
61+
- name: Fail when Ruff fixes are needed
62+
if: steps.ruff_check.outcome == 'failure'
3663
run: |
37-
ruff check --fix-only --diff --exit-non-zero-on-fix || (
38-
echo ""
39-
echo "❌ Ruff found issues that can be fixed automatically."
40-
echo "💡 To fix them locally, run:"
41-
echo ""
42-
echo " pre-commit run --all-files"
43-
echo ""
44-
echo "Then commit and push the changes."
45-
exit 1
46-
)
64+
echo ""
65+
echo "❌ Ruff found issues that can be fixed automatically."
66+
echo ""
67+
if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
68+
echo "💡 A rolling Ruff auto-fix PR to this PR branch has been created or updated."
69+
else
70+
echo "💡 Auto-fix PR creation was skipped (fork or non-PR event)."
71+
fi
72+
echo ""
73+
echo "To fix locally, run:"
74+
echo " pre-commit run --all-files"
75+
echo "Then commit and push the changes."
76+
exit 1
4777
4878
test:
4979
name: Run Tests

0 commit comments

Comments
 (0)