Skip to content

Commit c00d48f

Browse files
committed
ci: add python lint and auto-format workflow
1 parent 8653378 commit c00d48f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

.github/workflows/lint-fix.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Python Lint and Auto-Format
2+
3+
on:
4+
push:
5+
branches: ["main", "master"]
6+
pull_request:
7+
branches: ["main", "master"]
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
lint-and-format:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.x'
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install flake8 black
29+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
30+
31+
- name: Run Linter (Flake8)
32+
id: lint
33+
# We use continue-on-error so the workflow proceeds to formatting if linting fails
34+
run: flake8 . --count --max-line-length=88 --statistics
35+
continue-on-error: true
36+
37+
- name: Run Auto-formatter (Black)
38+
if: steps.lint.outcome == 'failure'
39+
run: black .
40+
41+
- name: Create Pull Request
42+
if: steps.lint.outcome == 'failure'
43+
uses: peter-evans/create-pull-request@v6
44+
with:
45+
token: ${{ secrets.GITHUB_TOKEN }}
46+
commit-message: "style: auto-format python code"
47+
title: "style: Auto-format Python code"
48+
body: |
49+
The linter found errors in the code.
50+
This PR applies auto-formatting using Black to resolve formatting issues.
51+
branch: "auto-format-fixes"
52+
delete-branch: true
53+
base: ${{ github.head_ref || github.ref_name }}

0 commit comments

Comments
 (0)