From e269c2f264f400adcda7c6b24c8550302350d495 Mon Sep 17 00:00:00 2001 From: Ilya Chekalsky Date: Sat, 4 Apr 2020 02:19:09 +0200 Subject: [PATCH] Custom standards and installed_paths option (#8) --- README.md | 27 +++++++++++++++++++++++++++ action.yml | 16 ++++++++++++---- entrypoint.sh | 8 ++++++-- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9993b80..53a9c23 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,30 @@ Eventually you could also check for warnings. ``` You probably would like to have [configuration file](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file) for PHP_CodeSniffer in order to make it work as you like. + +#### `installed_paths` and `Dealerdirect/phpcodesniffer-composer-installer` +If you are using custom standards, you have two options on how to customize this action. + +1. Just use [special library](https://github.com/Dealerdirect/phpcodesniffer-composer-installer) which will find and activate all the standards you have in your `composer.json`. + +It will also change phpcs `installed_paths` setting, but will prefer local phpcs install. That means we should use local phpcs binary in the action. To do so run action with certain parameter. + +```yaml + ... + - name: Install dependencies + run: composer install --dev --prefer-dist --no-progress --no-suggest + - name: PHPCS check + uses: chekalsky/phpcs-action@v1 + with: + phpcs_bin_path: './vendor/bin/phpcs' +``` + +2. Change the `installed_paths` directly by using another option. + +```yaml + ... + - name: PHPCS check + uses: chekalsky/phpcs-action@v1 + with: + installed_paths: '${{ github.workspace }}/vendor/phpcompatibility/php-compatibility' +``` \ No newline at end of file diff --git a/action.yml b/action.yml index 103bc9c..33928b8 100644 --- a/action.yml +++ b/action.yml @@ -1,14 +1,22 @@ -name: 'PHP_CodeSniffer Check' -description: 'PHPCS checker with annotations out of the box' +name: 'PHP_CodeSniffer Check with Annotations' +description: 'PHPCS checker with auto annotations out of the box' author: 'Ilya Chekalsky' inputs: enable_warnings: description: 'Enable checking for warnings (-w)' required: false default: '' + phpcs_bin_path: + description: 'Path to phpcs binary' + required: false + default: 'phpcs' + installed_paths: + description: 'Setting the installed standard paths' + required: false + default: '' runs: using: 'docker' image: 'Dockerfile' branding: - icon: 'check-circle' - color: 'green' + icon: 'zap' + color: 'purple' diff --git a/entrypoint.sh b/entrypoint.sh index d3cc884..20add03 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,14 +4,18 @@ cp /action/problem-matcher.json /github/workflow/problem-matcher.json echo "::add-matcher::${RUNNER_TEMP}/_github_workflow/problem-matcher.json" +if [ -n "${INPUT_INSTALLED_PATHS}" ]; then + ${INPUT_PHPCS_BIN_PATH} --config-set installed_paths "${INPUT_INSTALLED_PATHS}" +fi + if [ -z "${INPUT_ENABLE_WARNINGS}" ] || [ "${INPUT_ENABLE_WARNINGS}" = "false" ]; then echo "Check for warnings disabled" - phpcs -n --report=checkstyle + ${INPUT_PHPCS_BIN_PATH} -n --report=checkstyle else echo "Check for warnings enabled" - phpcs --report=checkstyle + ${INPUT_PHPCS_BIN_PATH} --report=checkstyle fi status=$?