-
Notifications
You must be signed in to change notification settings - Fork 6
65 lines (53 loc) · 1.78 KB
/
black.yaml
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
name: Auto-format Code with Debugging
on:
push:
pull_request:
jobs:
auto-format:
name: Auto-format and Push Changes
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v3
# Step 2: Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
# Step 3: Install tools (black and isort)
- name: Install Tools
run: |
echo "Installing tools..."
python -m pip install --upgrade pip
pip install black isort
# Step 4: Run black and isort to format the code
- name: Run Black and isort
run: |
echo "Running black..."
black --line-length=119 .
echo "Running isort..."
isort .
# Step 5: Commit and push changes if any files were modified
- name: Commit and Push Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Configuring git user..."
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
echo "Checking for changes..."
git status
if [ -n "$(git status --porcelain)" ]; then
echo "Changes detected. Inspecting changes..."
git diff
echo "Staging files..."
git add .
echo "Committing changes..."
git commit -m "Auto-format code with Black and isort"
echo "Pushing changes to branch..."
git push
echo "Push completed successfully."
else
echo "No changes detected. Nothing to commit or push."
fi