Skip to content

Commit dcbb682

Browse files
authored
Merge pull request #5 from SamPlaysKeys/ci/add-lint-workflow
Ci/add lint workflow
2 parents 00035a9 + 29056a5 commit dcbb682

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/lint-fix.yml

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

0 commit comments

Comments
 (0)