Skip to content

Commit 6fd85e3

Browse files
committed
Make GithubErrorFormatter the default when running in GitHub Actions
1 parent 6e7d5f6 commit 6fd85e3

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ jobs:
401401
cd compiler && \
402402
composer install --no-interaction && \
403403
vendor/bin/phpunit -c tests/phpunit.xml tests && \
404-
../bin/phpstan analyse -l 8 src tests --error-format github && \
404+
../bin/phpstan analyse -l 8 src tests && \
405405
php bin/compile && \
406406
../tmp/phpstan.phar
407407

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"nette/schema": "^1.0",
2121
"nette/utils": "^3.1.1",
2222
"nikic/php-parser": "^4.5.0",
23-
"ondram/ci-detector": "^3.1",
23+
"ondram/ci-detector": "^3.4.0",
2424
"ondrejmirtes/better-reflection": "^4.3.12",
2525
"phpdocumentor/type-resolver": "1.0.1",
2626
"phpstan/phpdoc-parser": "^0.4.8",

src/Command/AnalyseCommand.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Command;
44

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

140+
if ($errorFormat === null) {
141+
$errorFormat = 'table';
142+
$ciDetector = new CiDetector();
143+
144+
try {
145+
$ci = $ciDetector->detect();
146+
if ($ci->getCiName() === CiDetector::CI_GITHUB_ACTIONS) {
147+
$errorFormat = 'github';
148+
}
149+
} catch (\OndraM\CiDetector\Exception\CiNotDetectedException $e) {
150+
// pass
151+
}
152+
}
153+
139154
$container = $inceptionResult->getContainer();
140155
$errorFormatterServiceName = sprintf('errorFormatter.%s', $errorFormat);
141156
if (!$container->hasService($errorFormatterServiceName)) {

0 commit comments

Comments
 (0)