This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
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,9 @@ | ||
FROM cytopia/phpcs:3 | ||
|
||
COPY entrypoint.sh \ | ||
problem-matcher.json \ | ||
/action/ | ||
|
||
RUN chmod +x /action/entrypoint.sh | ||
|
||
ENTRYPOINT ["/action/entrypoint.sh"] |
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 |
---|---|---|
@@ -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. | ||
|
||
<img src="https://leonardo.osnova.io/491e4ce9-72d9-9417-29f7-9934ce7ec8ad/" title="How Annotations Works" width="560" height="432" /> | ||
|
||
## 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. |
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,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' |
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,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 |
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,23 @@ | ||
{ | ||
"problemMatcher": [ | ||
{ | ||
"owner": "phpcs", | ||
"severity": "error", | ||
"pattern": [ | ||
{ | ||
"regexp": "^<file name=\"(.*)\">$", | ||
"file": 1 | ||
}, | ||
{ | ||
"regexp": "<error line=\"(\\d*)\" column=\"(\\d*)\" severity=\"(error|warning)\" message=\"(.*)\" source=\"(.*)(\"\\/>+)$", | ||
"line": 1, | ||
"column": 2, | ||
"severity": 3, | ||
"message": 4, | ||
"code": 5, | ||
"loop": true | ||
} | ||
] | ||
} | ||
] | ||
} |