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

Commit

Permalink
First version of the action (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
chekalsky authored Jan 16, 2020
1 parent 713a7a0 commit 0fc7c3a
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
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"]
38 changes: 36 additions & 2 deletions README.md
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.
14 changes: 14 additions & 0 deletions action.yml
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'
21 changes: 21 additions & 0 deletions entrypoint.sh
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
23 changes: 23 additions & 0 deletions problem-matcher.json
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
}
]
}
]
}

0 comments on commit 0fc7c3a

Please sign in to comment.