Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,35 @@ jobs:

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

- name: "Install PHP with extensions"
uses: "shivammathur/setup-php@1.8.1"
uses: "shivammathur/setup-php@v1"
with:
coverage: "none"
extensions: "simplexml"
php-version: "7.0"

- name: "Cache dependencies installed with composer"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted this unnecessary complexity, because the build is wicked fast without caching

uses: "actions/cache@v1.0.3"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"

- name: "Install dependencies with composer"
run: "composer install --no-interaction --no-progress --no-suggest"

- name: "Run friendsofphp/php-cs-fixer"
run: "vendor/bin/php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --dry-run --verbose"

tests:
name: "Tests"

runs-on: "ubuntu-latest"

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

- name: "Install PHP with extensions"
uses: "shivammathur/setup-php@v1"
with:
coverage: "none"
extensions: "simplexml"
php-version: "7.0"

- run: php tests/tests.php
35 changes: 23 additions & 12 deletions cs2pr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error_reporting(E_ALL);
ini_set('display_errors', 'stderr');
gc_disable();

$version = '1.0-dev';
$version = '1.0.2';

if ($argc === 1) {
$xml = stream_get_contents(STDIN);
Expand All @@ -29,21 +29,32 @@ if ($argc === 1) {
exit(9);
}

$root = @simplexml_load_string($xml);

if (!$root) {
$errors = libxml_get_errors();
if ($errors) {
fwrite(STDERR, $errors[0]->message.' on line '.$errors[0]->line.', column '.$errors[0]->column);
} elseif (stripos($xml, '<?xml') !== 0) {
fwrite(STDERR, 'expecting xml stream starting with a xml opening tag.');
} else {
fwrite(STDERR, 'unknown error. expecting checkstyle formatted xml input.');
}
exit(2);
}

$exit = 0;
$root = simplexml_load_string($xml);

if ($root) {
foreach ($root as $file) {
$filename = (string)$file['name'];
foreach ($root as $file) {
$filename = (string)$file['name'];

foreach ($file as $error) {
$type = (string) $error['severity'];
$line = (string) $error['line'];
$message = (string) $error['message'];
foreach ($file as $error) {
$type = (string) $error['severity'];
$line = (string) $error['line'];
$message = (string) $error['message'];

annotateCheck(annotateType($type), relativePath($filename), $line, $message);
$exit = 1;
}
annotateCheck(annotateType($type), relativePath($filename), $line, $message);
$exit = 1;
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/errors/minimal.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::error file=redaxo\src\addons\2factor_auth\boot.php,line=6::Call to static method getInstance() on an unknown class rex_one_time_password.
::error file=redaxo\src\addons\2factor_auth\boot.php,line=9::Call to static method getInstance() on an unknown class rex_minibar.
::error file=redaxo\src\addons\2factor_auth\lib\one_time_password.php,line=0::Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly.
10 changes: 10 additions & 0 deletions tests/errors/minimal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle>
<file name="redaxo\src\addons\2factor_auth\boot.php">
<error line="6" column="1" severity="error" message="Call to static method getInstance() on an unknown class rex_one_time_password." />
<error line="9" column="1" severity="error" message="Call to static method getInstance() on an unknown class rex_minibar." />
</file>
<file name="redaxo\src\addons\2factor_auth\lib\one_time_password.php">
<error line="0" column="1" severity="error" message="Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly." />
</file>
</checkstyle>
Empty file added tests/fail/empty.xml
Empty file.
1 change: 1 addition & 0 deletions tests/fail/invalid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
17 changes: 17 additions & 0 deletions tests/fail/multiple-suites.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle>
<file name="redaxo\src\addons\2factor_auth\boot.php">
<error line="6" column="1" severity="error" message="Call to static method getInstance() on an unknown class rex_one_time_password." />
<error line="9" column="1" severity="error" message="Call to static method getInstance() on an unknown class rex_minibar." />
</file>
</checkstyle>
<checkstyle>
<file name="redaxo\src\addons\thincache\src\thincache\CacheKeyStatic.php">
<error line="0" column="1" severity="error" message="Class CacheKeyStatic was not found while trying to analyse it - autoloading is probably not configured properly." />
</file>
</checkstyle>
<checkstyle>
<file name="redaxo\src\addons\thincache\src\thincache\CacheKeyStatic.php">
<error line="0" column="1" severity="error" message="Class CacheKeyStatic was not found while trying to analyse it - autoloading is probably not configured properly." />
</file>
</checkstyle>
Empty file.
3 changes: 3 additions & 0 deletions tests/noerrors/only-header.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle>
</checkstyle>
46 changes: 46 additions & 0 deletions tests/tests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* Turns checkstyle based XML-Reports into Github Pull Request Annotations via the Checks API. This script is meant for use within your GithubAction.
*
* (c) Markus Staab <markus.staab@redaxo.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://github.com/staabm/annotate-pull-request-from-checkstyle
*/

function testXml($xmlPath, $expectedExit, $expectedOutput = null)
{
exec('cat '.$xmlPath .' | php '. __DIR__ .'/../cs2pr 2>&1', $output, $exit);
$output = implode("\n", $output);

if ($exit != $expectedExit) {
var_dump($output);

throw new Exception('Test with ' . $xmlPath . ' failed, expected exit-code ' . $expectedExit . ' got ' . $exit);
} elseif ($expectedOutput && $expectedOutput != $output) {
echo "EXPECTED:\n";
var_dump($expectedOutput);
echo "\n";

echo "GOT:\n";
var_dump($output);
echo "\n";

throw new Exception('Test with ' . $xmlPath . ' failed, output mismatch');
} else {
echo "success: $xmlPath\n\n";
}
}


testXml(__DIR__.'/fail/empty.xml', 2);
testXml(__DIR__.'/fail/invalid.xml', 2);

testXml(__DIR__.'/fail/multiple-suites.xml', 2);

testXml(__DIR__.'/errors/minimal.xml', 1, file_get_contents(__DIR__.'/errors/minimal.expect'));

testXml(__DIR__.'/noerrors/only-header.xml', 0, file_get_contents(__DIR__.'/noerrors/only-header.expect'));