Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Test PR: phpcs-changed and woocommerce linting rules test. #69

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
21 changes: 0 additions & 21 deletions .github/workflows/php-coding-standards-diff.yml

This file was deleted.

48 changes: 48 additions & 0 deletions .github/workflows/php-cs-on-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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]
fail-fast: false
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 }}
17 changes: 17 additions & 0 deletions bin/lint-branch.sh
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
18 changes: 0 additions & 18 deletions bin/phpcs-diff.sh

This file was deleted.

12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
}
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^v0.7",
"wp-coding-standards/wpcs": "^2.3",
"woocommerce/woocommerce-sniffs": "^0.1.3",
"exussum12/coverage-checker": "^1.0",
"woocommerce/woocommerce-sniffs": "1.0.0",
"sirbrillig/phpcs-changed": "^2.11.1",
"phpunit/phpunit": "^9.5",
"yoast/phpunit-polyfills": "^1.0"
"yoast/phpunit-polyfills": "^1.0",
"exussum12/coverage-checker": "^1.0"
},
"scripts": {
"lint": "chg=$(git diff --relative --name-only -- '*.php'); [[ -z $chg ]] || phpcs-changed -s --git --git-unstaged $chg",
"lint-staged": "chg=$(git diff HEAD --relative --name-only -- '*.php'); [[ -z $chg ]] || phpcs-changed -s --git $chg",
"lint-branch": "sh ./bin/lint-branch.sh",
"test-unit": "./vendor/bin/phpunit"
}
}
Loading