-
Notifications
You must be signed in to change notification settings - Fork 397
59 lines (52 loc) · 1.87 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
name: Check and Fix Whitespace on Schedule
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit hooks and apply fixes
id: pre-commit
run: |
# Run pre-commit with auto-fix and ignore exit code
pre-commit run --all-files --hook-stage=manual --show-diff-on-failure || true
# Check if any files were modified
git diff --exit-code || echo "FIX_NEEDED=true" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push changes if needed
if: env.FIX_NEEDED == 'true'
id: create_branch
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create a new branch for the changes
BRANCH_NAME="fix/whitespace-$(date +'%Y%m%d%H%M%S')"
git checkout -b "$BRANCH_NAME"
git add .
git commit -m "fix: apply whitespace fixes"
git push origin "$BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Open Pull Request
if: env.FIX_NEEDED == 'true'
uses: repo-sync/pull-request@v2
with:
source_branch: ${{ env.branch_name }}
destination_branch: ${{ github.ref_name }}
pr_title: "Fix whitespace issues"
pr_body: "This PR automatically applies whitespace fixes."
token: ${{ secrets.GITHUB_TOKEN }}