-
Notifications
You must be signed in to change notification settings - Fork 0
48 lines (38 loc) · 1.28 KB
/
python-lint.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
name: Lint and Auto-fix Code with Black and Isort
on:
push:
branches:
- main # Run on pushes to the main branch (you can specify other branches as needed)
pull_request:
branches:
- main # Optionally run on pull requests targeting the main branch
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10' # Specify the Python version you're using
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black isort
- name: Run Isort (Auto-fix)
run: |
isort .
- name: Run Black (Auto-fix)
run: |
black .
- name: Commit changes if any
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git diff-index --quiet HEAD || git commit -m "Auto-format: black and isort" || echo "No changes to commit"
- name: Push changes back to repository
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}