From f31953f7cdcb42cd7a5d0eb50523320ac866b204 Mon Sep 17 00:00:00 2001 From: Torantulino Date: Sun, 2 Apr 2023 09:07:32 +0100 Subject: [PATCH] Adds auto formatting for pull requests. This is a great way to ensure that your code is formatted correctly before it is merged into the main branch and limit the number of formatting changes in pull requests. --- .github/workflows/auto_format.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/auto_format.yml diff --git a/.github/workflows/auto_format.yml b/.github/workflows/auto_format.yml new file mode 100644 index 00000000..46b33d3e --- /dev/null +++ b/.github/workflows/auto_format.yml @@ -0,0 +1,26 @@ +name: auto-format +on: pull_request +jobs: + format: + # Check if the PR is not from a fork + if: github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + with: + ref: ${{ github.head_ref }} + - name: autopep8 + uses: peter-evans/autopep8@v1 + with: + args: --exit-code --recursive --in-place --aggressive --aggressive . + - name: Check for modified files + id: git-check + run: echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT + - name: Push changes + if: steps.git-check.outputs.modified == 'true' + run: | + git config --global user.name 'Torantulino' + git config --global user.email 'toran.richards@gmail.com' + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} + git commit -am "Automated changes" + git push