Skip to content

Commit

Permalink
Add Infection to the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
villfa authored Mar 3, 2022
1 parent 136c1ad commit 7b0e148
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CHANGELOG.md export-ignore
churn.yml export-ignore
CONTRIBUTING.md export-ignore
img/ export-ignore
infection.json export-ignore
Makefile export-ignore
manifest.xml export-ignore
phpcs.xml export-ignore
Expand Down
101 changes: 86 additions & 15 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ jobs:
name: coverage
path: ./coverage-${{ matrix.vcs }}.xml

analysis:
name: "Static Analysis"
coverage:
name: "Code coverage"
runs-on: ubuntu-latest
# Run after "test-vcs" to gather all code coverage reports
needs: [test-vcs]
Expand All @@ -144,6 +144,57 @@ jobs:
coverage: "pcov"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: "8.0"
tools: composer:v2

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

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: composer-${{ runner.os }}-8.0-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ runner.os }}-8.0-
composer-${{ runner.os }}-
composer-
- name: "Install dependencies"
run: "composer update --no-interaction --no-scripts --no-progress --prefer-dist"

- name: "Calculate code coverage"
run: "vendor/bin/simple-phpunit --colors=always --testdox --testsuite churn-tests --coverage-clover=coverage.xml"

- name: "Download other code coverage reports"
uses: actions/download-artifact@v2
with:
name: coverage
path: ./coverage

- name: "List all coverage reports"
run: echo coverage_reports=./coverage/$(ls -m coverage/ | sed "s/, */,.\/coverage\//g") >> $GITHUB_ENV

- uses: codecov/codecov-action@v1
with:
files: ./coverage.xml,${{ env.coverage_reports }}
fail_ci_if_error: true
verbose: true

analysis:
name: "Static Analysis"
runs-on: ubuntu-latest

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: "8.0"
tools: composer:v2, composer-normalize

- name: Get composer cache directory
Expand Down Expand Up @@ -187,29 +238,49 @@ jobs:
- name: "Normalize composer.json"
run: "composer-normalize --dry-run --no-check-lock --no-update-lock"

- name: "Calculate code coverage"
run: "vendor/bin/simple-phpunit --colors=always --testdox --testsuite churn-tests --coverage-clover=coverage.xml"
mutation:
name: "Mutation testing"
runs-on: ubuntu-latest

- name: "Download other code coverage reports"
uses: actions/download-artifact@v2
steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
name: coverage
path: ./coverage
coverage: "pcov"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: "8.0"
tools: composer:v2, infection

- name: "List all coverage reports"
run: echo coverage_reports=./coverage/$(ls -m coverage/ | sed "s/, */,.\/coverage\//g") >> $GITHUB_ENV
- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- uses: codecov/codecov-action@v1
- name: Cache composer dependencies
uses: actions/cache@v2
with:
files: ./coverage.xml,${{ env.coverage_reports }}
fail_ci_if_error: true
verbose: true
path: ${{ steps.composercache.outputs.dir }}
key: composer-${{ runner.os }}-8.0-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ runner.os }}-8.0-
composer-${{ runner.os }}-
composer-
- name: "Install dependencies"
run: "composer update --no-interaction --no-scripts --no-progress --prefer-dist"

- name: "Run Infection"
run: |
git fetch --depth=1 origin $GITHUB_BASE_REF
infection -j$(nproc) --logger-github --git-diff-filter=AM --git-diff-base=origin/$GITHUB_BASE_REF --ignore-msi-with-no-mutations --min-msi=85 --min-covered-msi=95
build:
name: "Build Phar"
runs-on: ubuntu-latest
# Build when everything else is ok
needs: [tests, analysis]
needs: [tests, analysis, coverage, mutation]

steps:
- name: "Checkout"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/composer.lock
/coverage.xml
/docs/
/infection.log
/phpunit.xml
/vendor/
/vendor-bin/**/vendor
Expand Down
8 changes: 7 additions & 1 deletion bin/CyclomaticComplexityAssessorRunner
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ require_once __DIR__ . '/bootstrap.php';
use Churn\Assessor\CyclomaticComplexityAssessor;

$file = $argv[1];
$contents = \file_get_contents($file);
if ($contents === false) {
echo 0;
return;
}

$assessor = new CyclomaticComplexityAssessor();
echo $assessor->assess($file);
echo $assessor->assess($contents);
4 changes: 2 additions & 2 deletions bin/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Composer\InstalledVersions;
use Symfony\Component\Console\Application;

$application = new Application('churn-php', (function (string $package): string {
$application = new Application('churn-php', (static function (string $package): string {
$version = InstalledVersions::getPrettyVersion($package);
$ref = InstalledVersions::getReference($package);
if ($ref) {
$version .= '@' . \substr($ref, 0, 7);
$version .= '@' . substr($ref, 0, 7);
}

return $version;
Expand Down
28 changes: 18 additions & 10 deletions bin/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<?php

declare(strict_types=1);

error_reporting(E_ALL);
ini_set('display_errors', 'stderr');

if (is_file($autoload = __DIR__ . '/../vendor/autoload.php')) {
require_once($autoload);
} elseif (is_file($autoload = __DIR__ . '/../../../autoload.php')) {
require_once($autoload);
} else {
fwrite(STDERR,
'You must set up the project dependencies first. Run the following command:'.PHP_EOL.
'composer install'.PHP_EOL
);
exit(1);
foreach (
[
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/../../../autoload.php',
] as $autoload
) {
if (is_file($autoload)) {
return require_once $autoload;
}
}

fwrite(
STDERR,
'You must set up the project dependencies first. Run the following command:' . PHP_EOL .
'composer install' . PHP_EOL
);
exit(1);
15 changes: 15 additions & 0 deletions infection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://raw.githubusercontent.com/infection/infection/0.26.0/resources/schema.json",
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "infection.log"
},
"mutators": {
"@default": true,
"@cast": false
}
}
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<config name="php_version" value="70103"/>

<file>./src</file>
<file>./bin</file>

<rule ref="PSR12"/>

Expand Down
10 changes: 5 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
convertDeprecationsToExceptions="true"
Expand All @@ -18,11 +18,11 @@
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</include>
</coverage>
<php>
<env name="SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT" value="1" />
</php>
Expand Down
Loading

0 comments on commit 7b0e148

Please sign in to comment.