Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the PHPCS linting GitHub Action Workflow #19

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: PHP Linting

on:
push:
branches:
- develop
- main
paths:
- "**.php"
pull_request:
branches:
- develop
paths:
- "**.php"

jobs:
phpcs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup proper PHP version
uses: shivammathur/setup-php@v2
with:
php-version: 8.3

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: |
**/*.php

- name: Install dependencies
run: composer install --prefer-dist

- name: Run PHP_CodeSniffer
run: |
HEAD_REF=$(git rev-parse HEAD)
git checkout $HEAD_REF
./vendor/bin/phpcs-changed -s --git --git-base origin/${{ github.base_ref }} ${{ steps.changed-files.outputs.all_changed_files }}
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
"php": ">=5.6"
},
"require-dev": {
"10up/phpcs-composer": "^3.0"
"10up/phpcs-composer": "^3.0",
"sirbrillig/phpcs-changed": "^2.11"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
"lint": "phpcs --standard=./phpcs.xml -p -s ."
}
}
}
58 changes: 56 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<ruleset name="TenUp PHPCS">
<description>TenUp PHPCS extended.</description>

<rule ref="10up-Default" />
Comment on lines +2 to +5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update this to Mailchimp?


<exclude-pattern>*/tests/*</exclude-pattern>

<config name="minimum_supported_wp_version" value="6.0"/>
<config name="testVersion" value="7.4-"/>

<!-- Exclude the PHPCompatibilityWP ruleset -->
<rule ref="PHPCompatibilityWP">
<exclude name="PHPCompatibilityWP"/>
</rule>
</ruleset>