Check and Fix Whitespace on Schedule #513
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check and Fix Whitespace on Schedule | |
on: | |
schedule: | |
# Runs every day | |
- 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 | |
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 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create and push changes if needed | |
if: env.FIX_NEEDED == 'true' | |
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" | |
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 }} | |
destination_branch: main | |
pr_title: "Fix whitespace issues" | |
pr_body: "This PR automatically applies whitespace fixes." | |
token: ${{ secrets.GITHUB_TOKEN }} |