diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eddf815 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM cytopia/phpcs:3 + +COPY entrypoint.sh \ + problem-matcher.json \ + /action/ + +RUN chmod +x /action/entrypoint.sh + +ENTRYPOINT ["/action/entrypoint.sh"] diff --git a/README.md b/README.md index a03ff52..1abeef6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,36 @@ -# phpcs-action -Github Action help you check your code with PHP_CodeSniffer +# PHP CodeSniffer GitHub Action + +This action will help you to run phpcs (PHP_CodeSniffer) with [GitHub Actions](https://github.com/features/actions) platform. It also supports [annotations](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-status-checks#checks) out of the box —— you don't need to use any tokens to make it work. + + + +## Usage + +Add the following code to `.github/workflows/phpcs.yml` file. + +```yaml +name: PHPCS check + +on: pull_request + +jobs: + phpcs: + name: PHPCS + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: PHPCS check + uses: chekalsky/phpcs-action:v1 +``` + +Eventually you could also check for warnings. + +```yaml + ... + - name: PHPCS check + uses: chekalsky/phpcs-action:v1 + with: + enable_warnings: true +``` + +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. \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..2b4f1a3 --- /dev/null +++ b/action.yml @@ -0,0 +1,14 @@ +name: 'PHP CodeSniffer Check' +description: 'PHPCS checker with annotations out of the box' +author: 'Ilya Chekalsky' +inputs: + enable_warnings: + description: 'Enable checking for warnings (-w)' + required: false + default: '' +runs: + using: 'docker' + image: 'Dockerfile' +branding: + icon: 'check-circle' + color: 'green' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..5e9d18c --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +cp /action/problem-matcher.json /github/workflow/problem-matcher.json + +echo "::add-matcher::${RUNNER_TEMP}/_github_workflow/problem-matcher.json" + +if [ -z "${INPUT_ENABLE_WARNINGS}" ] || [ "${INPUT_ENABLE_WARNINGS}" = "false" ]; then + echo "Check for warnings disabled" + + phpcs --report=checkstyle +else + echo "Check for warnings enabled" + + phpcs -w --report=checkstyle +fi + +status=$? + +echo "::remove-matcher owner=phpcs::" + +exit $status diff --git a/problem-matcher.json b/problem-matcher.json new file mode 100644 index 0000000..1cd6a14 --- /dev/null +++ b/problem-matcher.json @@ -0,0 +1,23 @@ +{ + "problemMatcher": [ + { + "owner": "phpcs", + "severity": "error", + "pattern": [ + { + "regexp": "^$", + "file": 1 + }, + { + "regexp": "+)$", + "line": 1, + "column": 2, + "severity": 3, + "message": 4, + "code": 5, + "loop": true + } + ] + } + ] +}