Skip to content

Commit 361a471

Browse files
[TASK] Automatically fix whitespace issues (#643)
Releases: main, 13.4, 12.4 Co-authored-by: lina.wolf <[email protected]>
1 parent 859a9d3 commit 361a471

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Check and Fix Whitespace on Schedule
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
with:
15+
token: ${{ secrets.GITHUB_TOKEN }}
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: '3.x'
21+
22+
- name: Install pre-commit
23+
run: pip install pre-commit
24+
25+
- name: Run pre-commit hooks and apply fixes
26+
id: pre-commit
27+
run: |
28+
# Run pre-commit with auto-fix and ignore exit code
29+
pre-commit run --all-files --hook-stage=manual --show-diff-on-failure || true
30+
# Check if any files were modified
31+
git diff --exit-code || echo "FIX_NEEDED=true" >> $GITHUB_ENV
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Create and push changes if needed
36+
if: env.FIX_NEEDED == 'true'
37+
id: create_branch
38+
run: |
39+
git config user.name "github-actions[bot]"
40+
git config user.email "github-actions[bot]@users.noreply.github.com"
41+
# Create a new branch for the changes
42+
BRANCH_NAME="fix/whitespace-$(date +'%Y%m%d%H%M%S')"
43+
git checkout -b "$BRANCH_NAME"
44+
git add .
45+
git commit -m "fix: apply whitespace fixes"
46+
git push origin "$BRANCH_NAME"
47+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- name: Open Pull Request
52+
if: env.FIX_NEEDED == 'true'
53+
uses: repo-sync/pull-request@v2
54+
with:
55+
source_branch: ${{ env.branch_name }}
56+
destination_branch: ${{ github.ref_name }}
57+
pr_title: "Fix whitespace issues"
58+
pr_body: "This PR automatically applies whitespace fixes."
59+
token: ${{ secrets.GITHUB_TOKEN }}

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0 # Use the latest version
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer

0 commit comments

Comments
 (0)