Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make GithubErrorFormatter the default when running in GitHub Actions
  • Loading branch information
ondrejmirtes committed Jul 1, 2020
1 parent 6e7d5f6 commit 6fd85e3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -401,7 +401,7 @@ jobs:
cd compiler && \
composer install --no-interaction && \
vendor/bin/phpunit -c tests/phpunit.xml tests && \
../bin/phpstan analyse -l 8 src tests --error-format github && \
../bin/phpstan analyse -l 8 src tests && \
php bin/compile && \
../tmp/phpstan.phar
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -20,7 +20,7 @@
"nette/schema": "^1.0",
"nette/utils": "^3.1.1",
"nikic/php-parser": "^4.5.0",
"ondram/ci-detector": "^3.1",
"ondram/ci-detector": "^3.4.0",
"ondrejmirtes/better-reflection": "^4.3.12",
"phpdocumentor/type-resolver": "1.0.1",
"phpstan/phpdoc-parser": "^0.4.8",
Expand Down
17 changes: 16 additions & 1 deletion src/Command/AnalyseCommand.php
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Command;

use OndraM\CiDetector\CiDetector;
use PHPStan\Command\ErrorFormatter\BaselineNeonErrorFormatter;
use PHPStan\Command\ErrorFormatter\ErrorFormatter;
use PHPStan\Command\Symfony\SymfonyOutput;
Expand Down Expand Up @@ -51,7 +52,7 @@ protected function configure(): void
new InputOption(ErrorsConsoleStyle::OPTION_NO_PROGRESS, null, InputOption::VALUE_NONE, 'Do not show progress bar, only results'),
new InputOption('debug', null, InputOption::VALUE_NONE, 'Show debug information - which file is analysed, do not catch internal errors'),
new InputOption('autoload-file', 'a', InputOption::VALUE_REQUIRED, 'Project\'s additional autoload file path'),
new InputOption('error-format', null, InputOption::VALUE_REQUIRED, 'Format in which to print the result of the analysis', 'table'),
new InputOption('error-format', null, InputOption::VALUE_REQUIRED, 'Format in which to print the result of the analysis', null),
new InputOption('generate-baseline', null, InputOption::VALUE_OPTIONAL, 'Path to a file where the baseline should be saved', false),
new InputOption('memory-limit', null, InputOption::VALUE_REQUIRED, 'Memory limit for analysis'),
new InputOption('xdebug', null, InputOption::VALUE_NONE, 'Allow running with XDebug for debugging purposes'),
Expand Down Expand Up @@ -136,6 +137,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
throw new \PHPStan\ShouldNotHappenException();
}

if ($errorFormat === null) {
$errorFormat = 'table';
$ciDetector = new CiDetector();

try {
$ci = $ciDetector->detect();
if ($ci->getCiName() === CiDetector::CI_GITHUB_ACTIONS) {
$errorFormat = 'github';
}
} catch (\OndraM\CiDetector\Exception\CiNotDetectedException $e) {
// pass
}
}

$container = $inceptionResult->getContainer();
$errorFormatterServiceName = sprintf('errorFormatter.%s', $errorFormat);
if (!$container->hasService($errorFormatterServiceName)) {
Expand Down

0 comments on commit 6fd85e3

Please sign in to comment.