From 98c6c9e3394cf6bc9380fa98a324c8acf30464fb Mon Sep 17 00:00:00 2001 From: Nasir Amin Date: Thu, 15 Oct 2020 18:13:27 +0100 Subject: [PATCH] Update the status check to success if all tests pass (#4) * Update the status check to success if all tests pass * Corrected if condition for status check * Set check api status based on test outcome * Updated Readme --- .github/workflows/test-action.yml | 2 +- README.md | 4 +++ action.ps1 | 46 +++++++++++++++++++------------ action.yml | 5 ++-- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 83149fc..8010adc 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -8,7 +8,7 @@ on: required: false gist_name: required: false - fail_check_on_failed_tests: + set_check_status_from_test_outcome: required: false #push: #release: diff --git a/README.md b/README.md index 815bab4..bcc8def 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,10 @@ jobs: --- +### Set check status based on test outcome +By default the [check status](https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-run--parameters) is set to 'neutral'. Set the flag `set_check_status_from_test_outcome: true`. +Note that setting this flag to `true` will fail the check on pull requests if at least one test fails in your project. + ### PowerShell GitHub Action This Action is implemented as a [PowerShell GitHub Action](https://github.com/ebekker/pwsh-github-action-base). diff --git a/action.ps1 b/action.ps1 index 7e07525..bb16309 100644 --- a/action.ps1 +++ b/action.ps1 @@ -16,20 +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 - fail_check_on_failed_tests = Get-ActionInput fail_check_on_failed_tests + 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 + set_check_status_from_test_outcome = Get-ActionInput set_check_status_from_test_outcome } $tmpDir = Join-Path $PWD _TMP @@ -86,10 +86,22 @@ function Publish-ToCheckRun { 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' + + # Set check status based on test result outcome. + if ($inputs.set_check_status_from_test_outcome) { + Write-ActionInfo "Mapping check status to test outcome..." + + if ($testResult.ResultSummary_outcome -eq "Failed") { + + Write-ActionWarning "Found failing tests" + $conclusion = 'failure' + } + elseif ($testResult.ResultSummary_outcome -eq "Completed") { + + Write-ActionInfo "All tests passed" + $conclusion = 'success' + } } $url = "https://api.github.com/repos/$repoFullName/check-runs" diff --git a/action.yml b/action.yml index 665fed7..97ad36d 100644 --- a/action.yml +++ b/action.yml @@ -111,10 +111,11 @@ 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: + set_check_status_from_test_outcome: description: | If set to true, GitHub check status will be set to 'failure' - if at least one test fails + if at least one test fails. If all tests pass then check status will + be set to 'success'