Skip to content

Commit

Permalink
Update the status check to success if all tests pass (#4)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
NasAmin authored Oct 15, 2020
1 parent 1ce4d3c commit 98c6c9e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
46 changes: 29 additions & 17 deletions action.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 98c6c9e

Please sign in to comment.