diff --git a/.github/workflows/shepherd.yml b/.github/workflows/shepherd.yml index edfecc972..886ccab46 100644 --- a/.github/workflows/shepherd.yml +++ b/.github/workflows/shepherd.yml @@ -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 diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index 809f76cbc..f11ddee74 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -18,6 +18,7 @@ use Psalm\Report\CheckstyleReport; 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; @@ -673,6 +674,10 @@ class IssueBuffer 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(); diff --git a/src/Psalm/Report.php b/src/Psalm/Report.php index 2989ebf45..b4b8467a9 100644 --- a/src/Psalm/Report.php +++ b/src/Psalm/Report.php @@ -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, @@ -29,6 +30,7 @@ abstract class Report self::TYPE_JUNIT, self::TYPE_CHECKSTYLE, self::TYPE_TEXT, + self::TYPE_GITHUB_ACTIONS, ]; /** diff --git a/src/Psalm/Report/GithubActionsReport.php b/src/Psalm/Report/GithubActionsReport.php new file mode 100644 index 000000000..19f93c3fe --- /dev/null +++ b/src/Psalm/Report/GithubActionsReport.php @@ -0,0 +1,29 @@ +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; + } +} diff --git a/src/command_functions.php b/src/command_functions.php index 6273edba5..56ce1f88f 100644 --- a/src/command_functions.php +++ b/src/command_functions.php @@ -334,7 +334,7 @@ Output: --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