Skip to content

Auto-fix file format #5

Auto-fix file format

Auto-fix file format #5

Workflow file for this run

name: Auto-fix file format
# Since pre-commit.ci cannot run local hooks, run them here manually to fixup formatting in pull requests
on: pull_request
env:
# SSH Deploy Key with write access (needed to trigger push workflow runs in created pull request)
SSH_KEY: ${{ secrets.SSH_KEY_GITHUB_ACTION }}
jobs:
pre-commit:
name: Format files with pre-commit
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
ssh-key: ${{ env.SSH_KEY }}
fetch-depth: 0
- name: Bot setup
run: |
AUTHOR=$(git log -1 --pretty=%an)
if [ "$AUTHOR" == "Bot" ]; then
echo "Commit made by bot, skipping further steps in the pipeline."
exit 0
fi
git config user.name "Bot"
git config user.email "<[email protected]>"
- name: Install python
uses: actions/setup-python@v3
- name: Install pre-commit
run: |
python3 -m pip install pre-commit
pre-commit install
- name: Format files
continue-on-error: true
id: check
run: |
FILES=$(git diff --name-only HEAD origin/$GITHUB_BASE_REF | tr '\n' ' ')
echo $FILES
pre-commit run --files $FILES
- name: Push formatting fixes
if: steps.check.outcome == 'failure'
run: |
git commit -am "Fixes formatting"
git push origin HEAD:${{github.event.pull_request.head.ref}}