-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (42 loc) · 1.35 KB
/
code_formatting.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
48
49
50
51
name: Code Formatting Check and Fix
on:
pull_request:
branches:
- main
- sparkx_devel
jobs:
code-formatting:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
fetch-depth: 0 # Ensures full history is available
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black==24.8.0
- name: Run black to check formatting
id: black-check
run: |
black --check --line-length 80 src/sparkx tests/
continue-on-error: true
- name: Capture formatting status
if: ${{ steps.black-check.outcome == 'failure' }}
run: echo "needs_formatting=true" >> $GITHUB_ENV
- name: Format code with black
if: env.needs_formatting == 'true'
run: black --line-length 80 src/sparkx tests/
- name: Push formatted changes
if: env.needs_formatting == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add src/sparkx tests/
git commit -m "Auto-format code with black"
git push origin ${{ github.head_ref }}