Skip to content

Commit

Permalink
Merge pull request #9982 from ro0NL/patch-1
Browse files Browse the repository at this point in the history
Infer output format from GITHUB_ACTIONS env
  • Loading branch information
orklah committed Jul 2, 2023
2 parents 086b943 + b525f9c commit 3c3d184
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Psalm/Internal/Cli/Psalm.php
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
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

0 comments on commit 3c3d184

Please sign in to comment.