Repository navigation
79 lines (66 loc) · 2.39 KB
/
Copy pathauto-fix-formatting.yml
File metadata and controls
79 lines (66 loc) · 2.39 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Auto-fix code formatting violations on PR branches
# Reduces manual toil by auto-committing formatter fixes
# Refs: MVA-2108 (investigation), MVA-2112 (implementation)
name: Auto-fix Code Formatting
on:
pull_request:
paths:
- '**/*.py'
- 'pyproject.toml'
- '.github/workflows/auto-fix-formatting.yml'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
permissions:
contents: write
jobs:
autofix:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v7
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python 3.12
uses: actions/setup-python@v7
with:
python-version: '3.14'
cache: 'pip'
- name: Install formatters
run: |
python -m pip install --upgrade pip
# Pin versions to match code-quality.yml and .pre-commit-config.yaml
python -m pip install black==26.3.1 isort==8.0.1 autoflake==2.3.3
- name: Run Black formatter
run: |
python3 -m black --line-length=120 autobot-backend/ autobot-slm-backend/ autobot_shared/
- name: Run isort
run: |
# Use --settings-path to read pyproject.toml (profile, src_paths, known_first_party)
python3 -m isort --settings-path=. --line-length=120 autobot-backend/ autobot-slm-backend/ autobot_shared/
- name: Run autoflake
run: |
python3 -m autoflake --in-place --recursive \
--remove-all-unused-imports \
--remove-unused-variables \
--expand-star-imports \
--ignore-init-module-imports \
autobot-backend/ autobot-slm-backend/ autobot_shared/
- name: Commit formatting fixes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --staged --quiet; then
echo "No formatting changes needed"
else
git commit -m "$(cat <<'EOF'
Auto-fix: code formatting
Applied Black, isort, and autoflake to match code-quality checks.
Triggered by workflow auto-fix-formatting.yml.
EOF
)"
git push
echo "✅ Formatting fixes committed and pushed"
fi