Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer output format from GITHUB_ACTIONS env #9982

Merged
merged 12 commits into from
Jul 2, 2023
13 changes: 13 additions & 0 deletions src/Psalm/Internal/Cli/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use function array_merge;
use function array_slice;
use function array_sum;
use function array_unshift;
use function array_values;
use function chdir;
use function count;
Expand Down Expand Up @@ -183,6 +184,14 @@ public static function run(array $argv): void
throw new RuntimeException('Failed to parse CLI options');
}

// debug CI environment
if (!in_array('--debug', $options, true)
&& 'true' === getenv('GITHUB_ACTIONS')
&& '1' === getenv('RUNNER_DEBUG')
) {
array_unshift($options, '--debug');
}

self::forwardCliCall($options, $argv);

self::validateCliArguments($args);
Expand Down Expand Up @@ -416,6 +425,10 @@ private static function findDefaultOutputFormat(): string
return Report::TYPE_PHP_STORM;
}

if ('true' === getenv('GITHUB_ACTIONS')) {
return Report::TYPE_GITHUB_ACTIONS;
}

return Report::TYPE_CONSOLE;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/EndToEnd/PsalmRunnerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Symfony\Component\Process\Process;

use function array_merge;
use function array_unshift;
use function in_array;

trait PsalmRunnerTrait
{
Expand All @@ -22,6 +24,11 @@ private function runPsalm(
bool $shouldFail = false,
bool $relyOnConfigDir = true
): array {
// Ensure CI agnostic output
if (!in_array('--init', $args, true) && !in_array('--alter', $args, true)) {
array_unshift($args, '--output-format=console');
}

// As config files all contain `resolveFromConfigFile="true"` Psalm
// shouldn't need to be run from the same directory that the code being
// analysed exists in.
Expand Down