Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Custom standards and installed_paths option (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
chekalsky authored Apr 4, 2020
1 parent 522bb34 commit e269c2f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
```
16 changes: 12 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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'
8 changes: 6 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=$?
Expand Down

0 comments on commit e269c2f

Please sign in to comment.