Skip to content

Commit

Permalink
Merge pull request #1 from kenjis/add-github-action
Browse files Browse the repository at this point in the history
Add GitHub Actions
  • Loading branch information
kenjis authored Mar 5, 2021
2 parents 92d1da7 + eb74566 commit 217ae9c
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 63 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Coding Standards

on:
push:
branches:
- 1.x
paths:
- 'src/**'
- 'tests/**'
- phpcs.xml
pull_request:
branches:
- 1.x
paths:
- 'src/**'
- 'tests/**'
- phpcs.xml
- '.github/workflows/**'
workflow_dispatch:

jobs:
coding-standards:
name: Coding Standards
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Validate composer.json
run: composer validate --strict

- name: Run PHP_CodeSniffer
run: ./vendor/bin/phpcs -q --no-colors --report=checkstyle src tests | cs2pr
75 changes: 75 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: PHPUnit

on:
push:
branches:
- 1.x
paths:
- 'src/**'
- 'tests/**'
- composer.json
- phpunit.xml.dist
pull_request:
branches:
- 1.x
paths:
- 'src/**'
- 'tests/**'
- composer.json
- phpunit.xml.dist
- '.github/workflows/**'
workflow_dispatch:

jobs:
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
strategy:
matrix:
operating-system:
- ubuntu-latest
php-version:
- '7.3'
- '7.4'
- '8.0'
dependencies:
- lowest
- highest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master
with:
php-version: ${{ matrix.php-version }}
coverage: pcov
ini-values: zend.assertions=1

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install lowest dependencies
if: ${{ matrix.dependencies == 'lowest' }}
run: composer update --prefer-lowest --no-interaction --no-progress

- name: Install highest dependencies
if: ${{ matrix.dependencies == 'highest' }}
run: composer update --no-interaction --no-progress

- name: Run test suite
run: ./vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-text

- name: Upload coverage report
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
156 changes: 156 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: Static Analysis

on:
push:
branches:
- 1.x
paths:
- 'src/**'
- 'tests/**'
- phpmd.xml
- phpstan.neon
- psalm.xml
pull_request:
branches:
- 1.x
paths:
- 'src/**'
- 'tests/**'
- phpmd.xml
- phpstan.neon
- psalm.xml
- '.github/workflows/**'
workflow_dispatch:

jobs:
static-analysis-phpstan:
name: Static Analysis with PHPStan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PHPStan
run: ./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --no-interaction --error-format=checkstyle | cs2pr

static-analysis-psalm:
name: Static Analysis with Psalm
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run Psalm
run: ./vendor/bin/psalm --show-info=false --output-format=checkstyle --shepherd | cs2pr

static-analysis-phpmd:
name: Static Analysis with PHPMD
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PHP Mess Detector
run: ./vendor/bin/phpmd src text --exclude src/Annotation ./phpmd.xml

static-analysis-php-metrics:
name: Static Analysis with PhpMetrics
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PhpMetrics
run: ./vendor/bin/phpmetrics --exclude=Exception src

static-analysis-composer-require-checker:
name: Static Analysis with ComposerRequireChecker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Install dependencies
run: |
composer install --no-interaction --no-progress --prefer-dist
composer require --dev maglnet/composer-require-checker ^3.0
- name: Run composer-require-checker
run: ./vendor/bin/composer-require-checker
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ coverage:
status:
project:
default:
target: 100%
target: 80%
patch:
default:
target: 100%
target: 80%

comment: false
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
"authors": [
{
"name": "Kenji Suzuki",
"email": "kenji.uui@gmail.com"
"homepage": "https://github.com/kenjis"
}
],
"require": {
"php": "^7.3 || ^8.0"
"php": "^7.3 || ^8.0",
"ext-openssl": "*",
"ext-tokenizer": "*",
"phpunit/phpunit": "^9.5",
"nikic/php-parser": "^4.10"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4",
"phpunit/phpunit": "^9.5",
"kenjis/phpunit-helper": "^1.0",
"nikic/php-parser": "^4.10"
"kenjis/phpunit-helper": "^1.1"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -51,7 +53,8 @@
],
"sa": [
"./vendor/bin/phpstan analyse -c phpstan.neon",
"psalm --show-info=true"
"psalm --show-info=true",
"./vendor/bin/phpmd src text ./phpmd.xml"
],
"tests": [
"@cs",
Expand Down
4 changes: 2 additions & 2 deletions phpmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
<!--controversial-->
<rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
<rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
<!-- <rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>-->
<!-- <rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>-->
<!--cleancode-->
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
<!-- <rule ref="rulesets/cleancode.xml/ElseExpression" /> -->
Expand Down
3 changes: 3 additions & 0 deletions src/IncludeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
use const STREAM_OPTION_WRITE_BUFFER;
use const STREAM_URL_STAT_QUIET;

/**
* @SuppressWarnings(PHPMD)
*/
class IncludeStream
{
public const STREAM_OPEN_FOR_INCLUDE = 128;
Expand Down
4 changes: 2 additions & 2 deletions src/MonkeyPatchManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function log(string $message): void
}

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

[$new_source, $patched] = self::execPatchers($source);
[$new_source] = self::execPatchers($source);

// Write to cache file
self::log('write_cache: ' . $path);
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/MonkeyPatchTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Kenjis\MonkeyPatch\Traits;

use Kenjis\MonkeyPatch\MonkeyPatch;
use MonkeyPatchManager;
use Kenjis\MonkeyPatch\MonkeyPatchManager;
use PHPUnit\Framework\ExpectationFailedException;

use function class_exists;
Expand Down
Loading

0 comments on commit 217ae9c

Please sign in to comment.