Skip to content

Commit 7399cac

Browse files
authored
Merge pull request #8 from localheinz/feature/php-cs-fixer
Enhancement: Run friendsofphp/php-cs-fixer on GitHub Actions
2 parents 4486f89 + 040fe8a commit 7399cac

File tree

5 files changed

+82
-4
lines changed

5 files changed

+82
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
2+
3+
name: "Continuous Integration"
4+
5+
on:
6+
pull_request:
7+
push:
8+
branches:
9+
- "master"
10+
11+
jobs:
12+
coding-standards:
13+
name: "Coding Standards"
14+
15+
runs-on: "ubuntu-latest"
16+
17+
steps:
18+
- name: "Checkout"
19+
uses: "actions/[email protected]"
20+
21+
- name: "Install PHP with extensions"
22+
uses: "shivammathur/[email protected]"
23+
with:
24+
coverage: "none"
25+
extensions: "simplexml"
26+
php-version: "7.0"
27+
28+
- name: "Cache dependencies installed with composer"
29+
uses: "actions/[email protected]"
30+
with:
31+
path: "~/.composer/cache"
32+
key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.lock') }}"
33+
restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"
34+
35+
- name: "Install dependencies with composer"
36+
run: "composer install --no-interaction --no-progress --no-suggest"
37+
38+
- name: "Run friendsofphp/php-cs-fixer"
39+
run: "vendor/bin/php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --dry-run --verbose"

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
.php_cs.cache
3+
composer.lock

.php_cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$header = <<<'EOF'
6+
Turns checkstyle based XML-Reports into Github Pull Request Annotations via the Checks API. This script is meant for use within your GithubAction.
7+
8+
(c) Markus Staab <[email protected]>
9+
10+
For the full copyright and license information, please view the LICENSE
11+
file that was distributed with this source code.
12+
13+
https://github.com/staabm/annotate-pull-request-from-checkstyle
14+
EOF;
15+
16+
$finder = PhpCsFixer\Finder::create()
17+
->files()
18+
->in(__DIR__)
19+
->name('cs2pr');
20+
21+
return PhpCsFixer\Config::create()
22+
->setFinder($finder)
23+
->setRules([
24+
'header_comment' => [
25+
'commentType' => 'comment',
26+
'header' => $header,
27+
'location' => 'after_declare_strict',
28+
'separate' => 'both',
29+
]
30+
]);

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Annotate a Pull Request based on a Checkstyle XML-report
22

3+
[![Continuous Integration](https://github.com/staabm/annotate-pull-request-from-checkstyle/workflows/Continuous%20Integration/badge.svg)](https://github.com/staabm/annotate-pull-request-from-checkstyle/actions)
4+
35
Turns [checkstyle based XML-Reports](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/checkstyle.xsd) into Github Pull Request [Annotations via the Checks API](https://developer.github.com/v3/checks/).
46
This script is meant for use within your GithubAction.
57

6-
That means you no longer search thru your GithubAction logfiles.
8+
That means you no longer search thru your GithubAction logfiles.
79
No need to interpret messages which are formatted differently with every tool.
810
Instead you can focus on your Pull Request, and you don't need to leave the Pull Request area.
911

@@ -97,7 +99,7 @@ jobs:
9799
vendor/bin/phpstan analyse --error-format=checkstyle | vendor/bin/cs2pr
98100
```
99101

100-
# Resources
102+
# Resources
101103

102104
[GithubAction Problem Matchers](https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md)
103105

composer.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
"ext-simplexml" : "*"
77
},
88
"require-dev" : {
9-
"phpunit/phpunit" : "^7.0"
9+
"phpunit/phpunit" : "^7.0",
10+
"friendsofphp/php-cs-fixer": "^2.16.1"
1011
},
1112
"authors" : [
1213
{
1314
"name" : "Markus Staab"
1415
}
1516
],
16-
"bin" : ["cs2pr"]
17+
"bin" : ["cs2pr"],
18+
"scripts": {
19+
"cs": "php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --verbose"
20+
}
1721
}

0 commit comments

Comments
 (0)