Skip to content

Commit 217ae9c

Browse files
authored
Merge pull request #1 from kenjis/add-github-action
Add GitHub Actions
2 parents 92d1da7 + eb74566 commit 217ae9c

11 files changed

Lines changed: 356 additions & 63 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Coding Standards
2+
3+
on:
4+
push:
5+
branches:
6+
- 1.x
7+
paths:
8+
- 'src/**'
9+
- 'tests/**'
10+
- phpcs.xml
11+
pull_request:
12+
branches:
13+
- 1.x
14+
paths:
15+
- 'src/**'
16+
- 'tests/**'
17+
- phpcs.xml
18+
- '.github/workflows/**'
19+
workflow_dispatch:
20+
21+
jobs:
22+
coding-standards:
23+
name: Coding Standards
24+
runs-on: ubuntu-latest
25+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v2
29+
30+
- name: Setup PHP
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: 8.0
34+
tools: cs2pr
35+
coverage: none
36+
37+
- name: Get composer cache directory
38+
id: composer-cache
39+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
40+
41+
- name: Cache dependencies
42+
uses: actions/cache@v2
43+
with:
44+
path: ${{ steps.composer-cache.outputs.dir }}
45+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
46+
restore-keys: ${{ runner.os }}-composer-
47+
48+
- name: Install dependencies
49+
run: composer install --no-interaction --no-progress --prefer-dist
50+
51+
- name: Validate composer.json
52+
run: composer validate --strict
53+
54+
- name: Run PHP_CodeSniffer
55+
run: ./vendor/bin/phpcs -q --no-colors --report=checkstyle src tests | cs2pr

.github/workflows/phpunit.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: PHPUnit
2+
3+
on:
4+
push:
5+
branches:
6+
- 1.x
7+
paths:
8+
- 'src/**'
9+
- 'tests/**'
10+
- composer.json
11+
- phpunit.xml.dist
12+
pull_request:
13+
branches:
14+
- 1.x
15+
paths:
16+
- 'src/**'
17+
- 'tests/**'
18+
- composer.json
19+
- phpunit.xml.dist
20+
- '.github/workflows/**'
21+
workflow_dispatch:
22+
23+
jobs:
24+
phpunit:
25+
name: PHPUnit
26+
runs-on: ubuntu-latest
27+
strategy:
28+
matrix:
29+
operating-system:
30+
- ubuntu-latest
31+
php-version:
32+
- '7.3'
33+
- '7.4'
34+
- '8.0'
35+
dependencies:
36+
- lowest
37+
- highest
38+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v2
42+
43+
- name: Setup PHP, with composer and extensions
44+
uses: shivammathur/setup-php@master
45+
with:
46+
php-version: ${{ matrix.php-version }}
47+
coverage: pcov
48+
ini-values: zend.assertions=1
49+
50+
- name: Get composer cache directory
51+
id: composer-cache
52+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
53+
54+
- name: Cache dependencies
55+
uses: actions/cache@v2
56+
with:
57+
path: ${{ steps.composer-cache.outputs.dir }}
58+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
59+
restore-keys: ${{ runner.os }}-composer-
60+
61+
- name: Install lowest dependencies
62+
if: ${{ matrix.dependencies == 'lowest' }}
63+
run: composer update --prefer-lowest --no-interaction --no-progress
64+
65+
- name: Install highest dependencies
66+
if: ${{ matrix.dependencies == 'highest' }}
67+
run: composer update --no-interaction --no-progress
68+
69+
- name: Run test suite
70+
run: ./vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-text
71+
72+
- name: Upload coverage report
73+
uses: codecov/codecov-action@v1
74+
with:
75+
file: ./coverage.xml
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: Static Analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- 1.x
7+
paths:
8+
- 'src/**'
9+
- 'tests/**'
10+
- phpmd.xml
11+
- phpstan.neon
12+
- psalm.xml
13+
pull_request:
14+
branches:
15+
- 1.x
16+
paths:
17+
- 'src/**'
18+
- 'tests/**'
19+
- phpmd.xml
20+
- phpstan.neon
21+
- psalm.xml
22+
- '.github/workflows/**'
23+
workflow_dispatch:
24+
25+
jobs:
26+
static-analysis-phpstan:
27+
name: Static Analysis with PHPStan
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v2
32+
33+
- name: Setup PHP
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: 8.0
37+
tools: cs2pr
38+
coverage: none
39+
40+
- name: Get composer cache directory
41+
id: composer-cache
42+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
43+
44+
- name: Cache dependencies
45+
uses: actions/cache@v2
46+
with:
47+
path: ${{ steps.composer-cache.outputs.dir }}
48+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
49+
restore-keys: ${{ runner.os }}-composer-
50+
51+
- name: Install dependencies
52+
run: composer install --no-interaction --no-progress --prefer-dist
53+
54+
- name: Run PHPStan
55+
run: ./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --no-interaction --error-format=checkstyle | cs2pr
56+
57+
static-analysis-psalm:
58+
name: Static Analysis with Psalm
59+
runs-on: ubuntu-latest
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v2
63+
64+
- name: Setup PHP
65+
uses: shivammathur/setup-php@v2
66+
with:
67+
php-version: 8.0
68+
tools: cs2pr
69+
coverage: none
70+
71+
- name: Get composer cache directory
72+
id: composer-cache
73+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
74+
75+
- name: Install dependencies
76+
run: composer install --no-interaction --no-progress --prefer-dist
77+
78+
- name: Run Psalm
79+
run: ./vendor/bin/psalm --show-info=false --output-format=checkstyle --shepherd | cs2pr
80+
81+
static-analysis-phpmd:
82+
name: Static Analysis with PHPMD
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Checkout
86+
uses: actions/checkout@v2
87+
88+
- name: Setup PHP
89+
uses: shivammathur/setup-php@v2
90+
with:
91+
php-version: 7.4
92+
93+
- name: Get composer cache directory
94+
id: composer-cache
95+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
96+
97+
- name: Cache dependencies
98+
uses: actions/cache@v2
99+
with:
100+
path: ${{ steps.composer-cache.outputs.dir }}
101+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
102+
restore-keys: ${{ runner.os }}-composer-
103+
104+
- name: Install dependencies
105+
run: composer install --no-interaction --no-progress --prefer-dist
106+
107+
- name: Run PHP Mess Detector
108+
run: ./vendor/bin/phpmd src text --exclude src/Annotation ./phpmd.xml
109+
110+
static-analysis-php-metrics:
111+
name: Static Analysis with PhpMetrics
112+
runs-on: ubuntu-latest
113+
steps:
114+
- name: Checkout
115+
uses: actions/checkout@v2
116+
117+
- name: Setup PHP
118+
uses: shivammathur/setup-php@v2
119+
with:
120+
php-version: 8.0
121+
coverage: none
122+
123+
- name: Get composer cache directory
124+
id: composer-cache
125+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
126+
127+
- name: Install dependencies
128+
run: composer install --no-interaction --no-progress --prefer-dist
129+
130+
- name: Run PhpMetrics
131+
run: ./vendor/bin/phpmetrics --exclude=Exception src
132+
133+
static-analysis-composer-require-checker:
134+
name: Static Analysis with ComposerRequireChecker
135+
runs-on: ubuntu-latest
136+
steps:
137+
- name: Checkout
138+
uses: actions/checkout@v2
139+
140+
- name: Setup PHP
141+
uses: shivammathur/setup-php@v2
142+
with:
143+
php-version: 8.0
144+
coverage: none
145+
146+
- name: Get composer cache directory
147+
id: composer-cache
148+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
149+
150+
- name: Install dependencies
151+
run: |
152+
composer install --no-interaction --no-progress --prefer-dist
153+
composer require --dev maglnet/composer-require-checker ^3.0
154+
155+
- name: Run composer-require-checker
156+
run: ./vendor/bin/composer-require-checker

codecov.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ coverage:
66
status:
77
project:
88
default:
9-
target: 100%
9+
target: 80%
1010
patch:
1111
default:
12-
target: 100%
12+
target: 80%
1313

1414
comment: false

composer.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
"authors": [
99
{
1010
"name": "Kenji Suzuki",
11-
"email": "kenji.uui@gmail.com"
11+
"homepage": "https://github.com/kenjis"
1212
}
1313
],
1414
"require": {
15-
"php": "^7.3 || ^8.0"
15+
"php": "^7.3 || ^8.0",
16+
"ext-openssl": "*",
17+
"ext-tokenizer": "*",
18+
"phpunit/phpunit": "^9.5",
19+
"nikic/php-parser": "^4.10"
1620
},
1721
"require-dev": {
1822
"bamarni/composer-bin-plugin": "^1.4",
19-
"phpunit/phpunit": "^9.5",
20-
"kenjis/phpunit-helper": "^1.0",
21-
"nikic/php-parser": "^4.10"
23+
"kenjis/phpunit-helper": "^1.1"
2224
},
2325
"autoload": {
2426
"psr-4": {
@@ -51,7 +53,8 @@
5153
],
5254
"sa": [
5355
"./vendor/bin/phpstan analyse -c phpstan.neon",
54-
"psalm --show-info=true"
56+
"psalm --show-info=true",
57+
"./vendor/bin/phpmd src text ./phpmd.xml"
5558
],
5659
"tests": [
5760
"@cs",

phpmd.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
4444
<!--controversial-->
4545
<rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
46-
<rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
47-
<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
46+
<!-- <rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>-->
47+
<!-- <rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>-->
4848
<!--cleancode-->
4949
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
5050
<!-- <rule ref="rulesets/cleancode.xml/ElseExpression" /> -->

src/IncludeStream.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
use const STREAM_OPTION_WRITE_BUFFER;
7070
use const STREAM_URL_STAT_QUIET;
7171

72+
/**
73+
* @SuppressWarnings(PHPMD)
74+
*/
7275
class IncludeStream
7376
{
7477
public const STREAM_OPEN_FOR_INCLUDE = 128;

src/MonkeyPatchManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static function log(string $message): void
7575
}
7676

7777
$time = date('Y-m-d H:i:s');
78-
[$usec, $sec] = explode(' ', microtime());
78+
[$usec] = explode(' ', microtime());
7979
$usec = substr($usec, 1);
8080
$log = "[$time $usec] $message\n";
8181
file_put_contents(self::$log_file, $log, FILE_APPEND);
@@ -325,7 +325,7 @@ public static function patch(string $path)
325325
$source = file_get_contents($path);
326326
assert(is_string($source));
327327

328-
[$new_source, $patched] = self::execPatchers($source);
328+
[$new_source] = self::execPatchers($source);
329329

330330
// Write to cache file
331331
self::log('write_cache: ' . $path);

src/Traits/MonkeyPatchTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace Kenjis\MonkeyPatch\Traits;
1515

1616
use Kenjis\MonkeyPatch\MonkeyPatch;
17-
use MonkeyPatchManager;
17+
use Kenjis\MonkeyPatch\MonkeyPatchManager;
1818
use PHPUnit\Framework\ExpectationFailedException;
1919

2020
use function class_exists;

0 commit comments

Comments
 (0)