-
Notifications
You must be signed in to change notification settings - Fork 394
62 lines (52 loc) · 1.67 KB
/
apply-precommit.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
59
60
61
62
name: Check and Fix Whitespace
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install pre-commit
run: pip install pre-commit
- name: Configure Git
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
- name: Run pre-commit hooks to fix issues
id: pre-commit
run: |
pre-commit run --all-files --hook-stage=manual || true
# Stage all changes
git add .
# Commit changes if there are any
if git diff --cached --quiet; then
echo "No changes to commit"
else
git commit -m "Fix whitespace issues" || echo "No changes to commit"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Push changes
if: success() && github.event_name == 'push'
run: |
# Check if running on a pull request
if [ -n "${{ github.head_ref }}" ]; then
echo "Pushing changes to branch: ${{ github.head_ref }}"
git push origin "${{ github.head_ref }}" || echo "Failed to push changes"
else
echo "No pull request head ref available, skipping push"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Debug
run: |
echo "Git status:"
git status
echo "Git diff:"
git diff --cached