-
Notifications
You must be signed in to change notification settings - Fork 6
103 lines (91 loc) · 3.09 KB
/
safe-auto-fix.yml
File metadata and controls
103 lines (91 loc) · 3.09 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Safe Auto-fix (Step by Step)
on:
workflow_dispatch:
inputs:
step:
description: 'Which step to run'
required: true
default: 'preview'
type: choice
options:
- preview
- imports
- sorting
- formatting
- all
permissions:
contents: write
jobs:
safe-fix:
name: Safe Auto-fix
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black isort autoflake
- name: Preview changes (no modifications)
if: github.event.inputs.step == 'preview'
run: |
echo "🔍 PREVIEW MODE - No files will be modified"
echo ""
echo "📋 Unused imports that would be removed:"
autoflake --remove-all-unused-imports --recursive custom_components/ || true
echo ""
echo "📋 Import sorting changes:"
isort --diff custom_components/ || true
echo ""
echo "📋 Black formatting changes:"
black --diff custom_components/ || true
echo ""
echo "✅ Preview complete - no files were modified"
- name: Fix unused imports only
if: github.event.inputs.step == 'imports'
run: |
echo "🗑️ Removing unused imports..."
autoflake --remove-all-unused-imports --recursive --in-place custom_components/
- name: Fix import sorting only
if: github.event.inputs.step == 'sorting'
run: |
echo "📋 Sorting imports..."
isort custom_components/
- name: Fix Black formatting only
if: github.event.inputs.step == 'formatting'
run: |
echo "🎨 Applying Black formatting..."
black custom_components/
- name: Fix everything
if: github.event.inputs.step == 'all'
run: |
echo "🔧 Fixing all issues..."
autoflake --remove-all-unused-imports --recursive --in-place custom_components/
isort custom_components/
black custom_components/
- name: Show what changed
if: github.event.inputs.step != 'preview'
run: |
echo "📋 Changes made:"
git diff --name-only || echo "No files changed"
git diff --stat || echo "No changes"
- name: Commit and push changes
if: github.event.inputs.step != 'preview'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action Safe-fix"
git add .
if git diff --staged --quiet; then
echo "✅ No changes to commit"
else
git commit -m "safe-fix: ${{ github.event.inputs.step }} formatting fixes"
git push
echo "✅ Changes committed and pushed"
fi