Skip to content

Commit

Permalink
Added support for failing github check status if tests fail (#3)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
NasAmin authored Oct 9, 2020
1 parent 36f1624 commit 1ce4d3c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
required: false
gist_name:
required: false
fail_check_on_failed_tests:
required: false
#push:
#release:
# types: published
Expand Down
36 changes: 22 additions & 14 deletions action.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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)``"
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1ce4d3c

Please sign in to comment.