From 1ce4d3c90f3365b7fab12d707615b6975e7fc8c9 Mon Sep 17 00:00:00 2001 From: Nasir Amin Date: Fri, 9 Oct 2020 12:42:32 +0100 Subject: [PATCH] Added support for failing github check status if tests fail (#3) * Set check conclusion to failure if failed tests are found * Added an input flag for failing git status check if at least one test fails * Added missing input variable in action.yml * Set correct field for the check api payload --- .github/workflows/test-action.yml | 2 ++ action.ps1 | 36 +++++++++++++++++++------------ action.yml | 6 ++++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 452657e..83149fc 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -8,6 +8,8 @@ on: required: false gist_name: required: false + fail_check_on_failed_tests: + required: false #push: #release: # types: published diff --git a/action.ps1 b/action.ps1 index 73ddfab..7e07525 100644 --- a/action.ps1 +++ b/action.ps1 @@ -16,19 +16,20 @@ Import-Module GitHubActions . $PSScriptRoot/action_helpers.ps1 $inputs = @{ - test_results_path = Get-ActionInput test_results_path - project_path = Get-ActionInput project_path - no_restore = Get-ActionInput no_restore - msbuild_configuration = Get-ActionInput msbuild_configuration - msbuild_verbosity = Get-ActionInput msbuild_verbosity - report_name = Get-ActionInput report_name - report_title = Get-ActionInput report_title - github_token = Get-ActionInput github_token -Required - skip_check_run = Get-ActionInput skip_check_run - gist_name = Get-ActionInput gist_name - gist_badge_label = Get-ActionInput gist_badge_label - gist_badge_message = Get-ActionInput gist_badge_message - gist_token = Get-ActionInput gist_token -Required + test_results_path = Get-ActionInput test_results_path + project_path = Get-ActionInput project_path + no_restore = Get-ActionInput no_restore + msbuild_configuration = Get-ActionInput msbuild_configuration + msbuild_verbosity = Get-ActionInput msbuild_verbosity + report_name = Get-ActionInput report_name + report_title = Get-ActionInput report_title + github_token = Get-ActionInput github_token -Required + skip_check_run = Get-ActionInput skip_check_run + gist_name = Get-ActionInput gist_name + gist_badge_label = Get-ActionInput gist_badge_label + gist_badge_message = Get-ActionInput gist_badge_message + gist_token = Get-ActionInput gist_token -Required + fail_check_on_failed_tests = Get-ActionInput fail_check_on_failed_tests } $tmpDir = Join-Path $PWD _TMP @@ -84,6 +85,13 @@ function Publish-ToCheckRun { Write-ActionInfo "Resolve Repo Full Name as $repoFullName" Write-ActionInfo "Adding Check Run" + $conclusion = 'neutral' + if ($testResult.ResultSummary_outcome -eq "Failed" -and $inputs.fail_check_on_failed_tests) { + Write-ActionWarning "Found failing tests" + $conclusion = 'failure' + + } + $url = "https://api.github.com/repos/$repoFullName/check-runs" $hdr = @{ Accept = 'application/vnd.github.antiope-preview+json' @@ -93,7 +101,7 @@ function Publish-ToCheckRun { name = $report_name head_sha = $ref status = 'completed' - conclusion = 'neutral' + conclusion = $conclusion output = @{ title = $report_title summary = "This run completed at ``$([datetime]::Now)``" diff --git a/action.yml b/action.yml index 1f93209..665fed7 100644 --- a/action.yml +++ b/action.yml @@ -111,6 +111,12 @@ inputs: You can control which account is used to actually store the state by generating a token associated with the target account. + fail_check_on_failed_tests: + description: | + If set to true, GitHub check status will be set to 'failure' + if at least one test fails + + ## Here you describe your *formal* outputs. outputs: