Skip to content

Commit

Permalink
Add support for Github Actions output
Browse files Browse the repository at this point in the history
Fixes #2678
  • Loading branch information
muglug committed Jan 23, 2020
1 parent dc80880 commit fa65ab8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/shepherd.yml
Expand Up @@ -15,4 +15,4 @@ jobs:
COMPOSER_ROOT_VERSION: dev-master

- name: Run Psalm
run: ./psalm --threads=2 --shepherd
run: ./psalm --threads=2 --output-format=github --shepherd
5 changes: 5 additions & 0 deletions src/Psalm/IssueBuffer.php
Expand Up @@ -18,6 +18,7 @@
use Psalm\Report\CompactReport;
use Psalm\Report\ConsoleReport;
use Psalm\Report\EmacsReport;
use Psalm\Report\GithubActionsReport;
use Psalm\Report\JsonReport;
use Psalm\Report\JsonSummaryReport;
use Psalm\Report\JunitReport;
Expand Down Expand Up @@ -673,6 +674,10 @@ public static function getOutput(
case Report::TYPE_CONSOLE:
$output = new ConsoleReport($normalized_data, self::$fixable_issue_counts, $report_options);
break;

case Report::TYPE_GITHUB_ACTIONS:
$output = new GithubActionsReport($normalized_data, self::$fixable_issue_counts, $report_options);
break;
}

return $output->create();
Expand Down
2 changes: 2 additions & 0 deletions src/Psalm/Report.php
Expand Up @@ -16,6 +16,7 @@ abstract class Report
const TYPE_JUNIT = 'junit';
const TYPE_CHECKSTYLE = 'checkstyle';
const TYPE_TEXT = 'text';
const TYPE_GITHUB_ACTIONS = 'github';

const SUPPORTED_OUTPUT_TYPES = [
self::TYPE_COMPACT,
Expand All @@ -29,6 +30,7 @@ abstract class Report
self::TYPE_JUNIT,
self::TYPE_CHECKSTYLE,
self::TYPE_TEXT,
self::TYPE_GITHUB_ACTIONS,
];

/**
Expand Down
29 changes: 29 additions & 0 deletions src/Psalm/Report/GithubActionsReport.php
@@ -0,0 +1,29 @@
<?php
namespace Psalm\Report;

use Psalm\Config;
use Psalm\Report;
use function sprintf;

class GithubActionsReport extends Report
{
/**
* {@inheritdoc}
*/
public function create(): string
{
$output = '';
foreach ($this->issues_data as $issue_data) {
$output .= sprintf(
'::%s file=%s,line=%s,col=%s::%s',
($issue_data['severity'] === Config::REPORT_ERROR ? 'error' : 'warning'),
$issue_data['file_name'],
$issue_data['line_from'],
$issue_data['column_from'],
$issue_data['message']
) . "\n";
}

return $output;
}
}
2 changes: 1 addition & 1 deletion src/command_functions.php
Expand Up @@ -334,7 +334,7 @@ function getPsalmHelpText(): string
--output-format=console
Changes the output format.
Available formats: compact, console, emacs, json, pylint, xml, checkstyle, junit, sonarqube
Available formats: compact, console, emacs, json, pylint, xml, checkstyle, junit, sonarqube, github
--no-progress
Disable the progress indicator
Expand Down

0 comments on commit fa65ab8

Please sign in to comment.