-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2633 from woocommerce/add/phpcs-changed
Add code style check on changed files only.
- Loading branch information
Showing
5 changed files
with
389 additions
and
162 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: PHP Coding Standards - PR Changed Files | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "**.php" | ||
- .github/workflows/php-cs-on-changes.yml | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
strategy: | ||
matrix: | ||
php: [7.4, 8.2] | ||
name: Code sniff (PHP ${{ matrix.php }}, WP Latest) | ||
permissions: | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Prepare PHP ${{ matrix.php }} | ||
uses: woocommerce/grow/prepare-php@actions-v1 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
|
||
- name: Get Changed Files | ||
id: changed-files | ||
uses: tj-actions/changed-files@v39 | ||
with: | ||
files: "**/*.php" | ||
|
||
- name: Tool versions | ||
run: | | ||
php --version | ||
composer --version | ||
vendor/bin/phpcs-changed --version | ||
- name: Run PHPCS | ||
if: steps.changed-files.outputs.any_changed == 'true' | ||
run: vendor/bin/phpcs-changed --warning-severity=0 -s --git --git-base ${{ github.event.pull_request.base.sha }} ${{ steps.changed-files.outputs.all_changed_files }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
# Lint branch | ||
# | ||
# Runs phpcs-changed, comparing the current branch to its "base" or "parent" branch. | ||
# The base branch defaults to trunk, but another branch name can be specified as an | ||
# optional positional argument. | ||
# | ||
# Example: | ||
# ./lint-branch.sh base-branch | ||
|
||
baseBranch=${1:-"develop"} | ||
|
||
changedFiles=$(git diff $(git merge-base HEAD $baseBranch) --relative --name-only -- '*.php') | ||
|
||
# Only complete this if changed files are detected. | ||
[[ -z $changedFiles ]] || composer exec phpcs-changed -- -s --git --git-base $baseBranch $changedFiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.