1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Don't output console links in CI env (#7049)

This commit is contained in:
Bruce Weirdan 2021-12-04 19:49:24 +02:00 committed by GitHub
parent 1956b85c41
commit 14dcbc908a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 17 deletions

View File

@ -226,7 +226,7 @@ final class Psalm
$config->setIncludeCollector($include_collector);
$in_ci = self::runningInCI(); // disable progressbar on CI
$in_ci = CliUtils::runningInCI(); // disable progressbar on CI
if ($in_ci) {
$options['long-progress'] = true;
@ -310,7 +310,7 @@ final class Psalm
$progress = self::initProgress($options, $config);
$providers = self::initProviders($options, $config, $current_dir);
$stdout_report_options = self::initStdoutReportOptions($options, $show_info, $output_format);
$stdout_report_options = self::initStdoutReportOptions($options, $show_info, $output_format, $in_ci);
/** @var list<string>|string $report_file_paths type guaranteed by argument to getopt() */
$report_file_paths = $options['report'] ?? [];
@ -776,7 +776,8 @@ final class Psalm
private static function initStdoutReportOptions(
array $options,
bool $show_info,
string $output_format
string $output_format,
bool $in_ci
): ReportOptions {
$stdout_report_options = new \Psalm\Report\ReportOptions();
$stdout_report_options->use_color = !array_key_exists('m', $options);
@ -788,6 +789,7 @@ final class Psalm
$stdout_report_options->format = $output_format;
$stdout_report_options->show_snippet = !isset($options['show-snippet']) || $options['show-snippet'] !== "false";
$stdout_report_options->pretty = isset($options['pretty-print']) && $options['pretty-print'] !== "false";
$stdout_report_options->in_ci = $in_ci;
return $stdout_report_options;
}
@ -817,17 +819,6 @@ final class Psalm
exit;
}
private static function runningInCI(): bool
{
return isset($_SERVER['TRAVIS'])
|| isset($_SERVER['CIRCLECI'])
|| isset($_SERVER['APPVEYOR'])
|| isset($_SERVER['JENKINS_URL'])
|| isset($_SERVER['SCRUTINIZER'])
|| isset($_SERVER['GITLAB_CI'])
|| isset($_SERVER['GITHUB_WORKFLOW']);
}
private static function getCurrentDir(array $options): string
{
$cwd = getcwd();

View File

@ -342,9 +342,9 @@ Basic configuration:
--no-diff
Turns off Psalms diff mode, checks all files regardless of whether theyve changed.
--php-version=PHP_VERSION
Explicitly set PHP version to analyse code against.
Explicitly set PHP version to analyse code against.
Surfacing issues:
--show-info[=BOOLEAN]
@ -647,4 +647,15 @@ HELP;
$project_analyzer->setPhpVersion($version, $source);
}
}
public static function runningInCI(): bool
{
return isset($_SERVER['TRAVIS'])
|| isset($_SERVER['CIRCLECI'])
|| isset($_SERVER['APPVEYOR'])
|| isset($_SERVER['JENKINS_URL'])
|| isset($_SERVER['SCRUTINIZER'])
|| isset($_SERVER['GITLAB_CI'])
|| isset($_SERVER['GITHUB_WORKFLOW']);
}
}

View File

@ -65,6 +65,9 @@ abstract class Report
/** @var bool */
protected $pretty;
/** @var bool */
protected $in_ci;
/** @var int */
protected $mixed_expression_count;
@ -98,6 +101,7 @@ abstract class Report
$this->show_snippet = $report_options->show_snippet;
$this->show_info = $report_options->show_info;
$this->pretty = $report_options->pretty;
$this->in_ci = $report_options->in_ci;
$this->mixed_expression_count = $mixed_expression_count;
$this->total_expression_count = $total_expression_count;

View File

@ -129,6 +129,10 @@ class ConsoleReport extends Report
. "\033[0m"
;
if ($this->in_ci) {
return $reference;
}
if (null === $this->link_format) {
// if xdebug is not enabled, use `get_cfg_var` to get the value directly from php.ini
$this->link_format = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')

View File

@ -39,4 +39,7 @@ class ReportOptions
* @var bool
*/
public $show_suggestions = true;
/** @var bool */
public $in_ci = false;
}

View File

@ -42,7 +42,7 @@ trait PsalmRunnerTrait
$process->mustRun();
} else {
$process->run();
$this->assertEquals(2, $process->getExitCode());
$this->assertEquals(2, $process->getExitCode(), 'Expected Psalm to report errors');
}
return [

View File

@ -1074,6 +1074,7 @@ INFO: PossiblyUndefinedGlobalVariable - somefile.php:17:6 - Possibly undefined g
$console_report_options = new Report\ReportOptions();
$console_report_options->show_snippet = false;
$console_report_options->use_color = true;
$console_report_options->in_ci = false; // we don't output links in CI
$output = IssueBuffer::getOutput(IssueBuffer::getIssuesData(), $console_report_options);
@ -1083,6 +1084,23 @@ INFO: PossiblyUndefinedGlobalVariable - somefile.php:17:6 - Possibly undefined g
);
}
public function testConsoleReportLinksAreDisabledInCI(): void
{
$this->analyzeFileForReport();
$console_report_options = new Report\ReportOptions();
$console_report_options->show_snippet = false;
$console_report_options->use_color = true;
$console_report_options->in_ci = true;
$output = IssueBuffer::getOutput(IssueBuffer::getIssuesData(), $console_report_options);
$this->assertStringNotContainsString(
"\033]8;;file://somefile.php#L3\033\\",
$output
);
}
public function testCompactReport(): void
{
$this->analyzeFileForReport();