Skip to content

Commit

Permalink
[TASK] Check and Fix Whitespace on Schedule
Browse files Browse the repository at this point in the history
As whitespace handling is hard to do when using the GitHub editor this will make a PR in case of whitespace issues instead.
  • Loading branch information
linawolf committed Nov 8, 2024
1 parent 3715a21 commit 4616dfb
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/apply-precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: Check and Fix Whitespace on Schedule

on:
schedule:
# Runs daily at midnight
- cron: '0 7 * * *'
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
Expand All @@ -26,15 +25,16 @@ jobs:
- name: Run pre-commit hooks and apply fixes
id: pre-commit
run: |
# Run pre-commit with auto-fix
pre-commit run --all-files --hook-stage=manual --show-diff-on-failure
# Check if any files have been modified
git diff --exit-code || FIX_NEEDED=true
# 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"
Expand All @@ -44,14 +44,15 @@ jobs:
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: ${{ steps.pre-commit.outputs.BRANCH_NAME }}
source_branch: ${{ env.branch_name }}
destination_branch: ${{ github.ref_name }}
pr_title: "Fix whitespace issues"
pr_body: "This PR automatically applies whitespace fixes."
Expand Down

0 comments on commit 4616dfb

Please sign in to comment.