-
Notifications
You must be signed in to change notification settings - Fork 4
58 lines (48 loc) · 1.71 KB
/
Code-Formatter.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
52
53
54
55
56
57
58
name: Code-Formatter
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Format code with Black
uses: psf/black@stable
with:
options: "." # Options for Black (e.g., --line-length)
src: "." # The directory to format (entire repo)
- name: Check for changes
id: check_changes
run: |
# Check if there are code changes after formatting
git diff --exit-code || echo "Code changes detected"
continue-on-error: true
- name: Commit formatted code
if: steps.check_changes.outputs.exit_code != '0'
run: |
# Configure Git user
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Actions"
# Add and commit changes if any
git add .
git diff --quiet && git diff --staged --quiet || git commit -m "Format code with Black"
- name: Push changes
if: steps.check_changes.outputs.exit_code != '0'
uses: ad-m/github-push-action@v0.8.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Display changes and success message
if: steps.check_changes.outputs.exit_code != '0'
run: |
# Show a summary of the changes made by Black
echo "The code has been successfully formatted with Black."
echo "The following changes were made:"
git diff --name-only HEAD~1 HEAD
# Display success message
echo "Code formatting completed successfully and changes have been pushed."