diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index 3a0c451..4dac59c 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -7,14 +7,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: pantheon-systems/validate-readme-spacing@v1 wporg-validation: name: WP.org Validator runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: WP.org Validator uses: pantheon-systems/action-wporg-validator@1.0.0 with: @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Lint run: | composer install diff --git a/.github/workflows/phpcbf.yml b/.github/workflows/phpcbf.yml new file mode 100644 index 0000000..f031ef6 --- /dev/null +++ b/.github/workflows/phpcbf.yml @@ -0,0 +1,39 @@ +name: PHP Code Beautifier +on: [pull_request] +permissions: + contents: write + pull-requests: write +jobs: + phpcbf: + name: PHPCBF & Commit + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + - name: Install Composer dependencies and run PHPCBF + run: | + composer install + composer phpcbf || true # Allow the workflow to continue even if PHPCBF fails + - name: Commit changes to PR + id: git-auto-commit + run: | + git config --global user.email "bot@getpantheon.com" + git config --global user.name "Pantheon Robot" + DIFF=$(git diff-index --quiet HEAD || echo "true") + if [ "$DIFF" == "true" ]; then + git add . + git commit -m "PHPCBF: Fix coding standards" --no-verify + git push origin ${{ github.event.pull_request.head.ref }} + echo "changes_detected=true" >> $GITHUB_ENV + else + echo "changes_detected=false" >> $GITHUB_ENV + fi + - name: Add PR Comment + if: env.changes_detected == 'true' + env: + GH_TOKEN: ${{ github.token }} + run: | + CURRENT_COMMIT=$(git rev-parse --short HEAD) + gh pr comment ${{ github.event.pull_request.number }} -b "Hi from your friendly robot! :robot: I fixed PHPCS issues with \`phpcbf\` on $CURRENT_COMMIT. Please review the changes."