diff --git a/.github/workflows/fix-pr-formatting.yml b/.github/workflows/fix-pr-formatting.yml new file mode 100644 index 00000000..fa5363e9 --- /dev/null +++ b/.github/workflows/fix-pr-formatting.yml @@ -0,0 +1,37 @@ +# This is a format job. Pre-commit has a first-party GitHub action, so we use +# that: https://github.com/pre-commit/action + +name: PR fix formatting + +on: + workflow_dispatch: + pull_request: + +jobs: + pre-commit: + name: Format + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # fetch all history for all branches and tags, which might be needed when pushing commits. + token: ${{ secrets.BOT_PAT }} + ref: ${{ github.head_ref }} + - uses: actions/setup-python@v5 + with: + python-version: 3.10.6 + - name: Install system hooks + run: sudo apt update && sudo apt install -qq clang-format-14 cppcheck + - name: Run pre-commit checks + uses: pre-commit/action@v3.0.1 + with: + extra_args: --all-files --hook-stage manual + continue-on-error: true + - name: Commit and push if changed + run: | + git diff + git config --global user.name 'github-actions[bot]' + git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' + git add -u + git commit -m "Automated code fixes by pre-commit." || echo "No changes to commit" + git push origin HEAD:${{ github.head_ref }} \ No newline at end of file