Skip to content

Commit

Permalink
[jfdi] Add phpcbf before lint (#380)
Browse files Browse the repository at this point in the history
* bump checkout version

* move composer install to its own step

* add phpcbf job

* add perms so we can commit

* make it all one action & allow push to fail

* Update lint-test.yml to allow commit and push to fail if there are no changes

* use an existing action & workflow

* use our phpcs jobs but use the existing commit job

* remove cbf from lint-test and go back to just linting

* don't need write permissions anymore

* move phpcbf & commit to a separate workflow
that runs on pull_request

* add a comment back to the PR if the robot made changes

* intentionally break linting

* allow the workflow to continue when phpcbf returns error code 1

* remove branch
use whatever the default is

* take out the third party action for the commit

* we need to actually push the changes

* another intentional bad code change

* fix destination to push to

* explicitly use the pr head ref

* PHPCBF: Fix coding standards

---------

Co-authored-by: Pantheon Robot <bot@getpantheon.com>
  • Loading branch information
jazzsequence and Pantheon Robot authored Jul 18, 2024
1 parent 310eba3 commit 250cc45
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/phpcbf.yml
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit 250cc45

Please sign in to comment.