Skip to content

Commit

Permalink
Merge pull request #19 from mailchimp/feature/12-phpcs-workflow
Browse files Browse the repository at this point in the history
Add the PHPCS linting GitHub Action Workflow
  • Loading branch information
jeffpaul authored May 31, 2024
2 parents ba1b065 + e35f8c8 commit 10a00f6
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 4 deletions.
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" />

<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>

0 comments on commit 10a00f6

Please sign in to comment.