Skip to content

Commit

Permalink
Add option to disable status check (#532)
Browse files Browse the repository at this point in the history
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
  • Loading branch information
TurnrDev and EnricoMi authored Dec 19, 2023
1 parent dd65627 commit d764099
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ jobs:
-e "INPUT_DEDUPLICATE_CLASSES_BY_FILE_NAME" \
-e "INPUT_LARGE_FILES" \
-e "INPUT_IGNORE_RUNS" \
-e "INPUT_CHECK_RUN" \
-e "INPUT_JOB_SUMMARY" \
-e "INPUT_COMPARE_TO_EARLIER_COMMIT" \
-e "INPUT_PULL_REQUEST_BUILD" \
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ Those are highlighted in pull request comments to easily spot unintended test re

***Note:** This requires `check_run_annotations` to be set to `all tests, skipped tests`.*

Comments can be disabled with `comment_mode: off`.

### Commit and pull request checks

The checks section of a commit and related pull requests list a short summary (here `1 fail, 1 skipped, …`),
Expand All @@ -198,6 +200,8 @@ Pull request checks:

![pull request checks example](misc/github-pull-request-checks.png)

Check runs can be disabled with `check_run: false`.

### Commit and pull request annotations

Each failing test produces an annotation with failure details in the checks section of a commit:
Expand All @@ -213,6 +217,8 @@ Use option `test_file_prefix` to add a prefix to, or remove a prefix from these

***Note:** Only the first failure of a test is shown. If you want to see all failures, set `report_individual_runs: "true"`.*

Check run annotations can be disabled with `ignore_runs: true`.

### GitHub Actions job summary

The results are added to the job summary page of the workflow that runs this action:
Expand All @@ -223,12 +229,16 @@ In presence of failures or errors, the job summary links to the respective [chec

***Note:** Job summary requires [GitHub Actions runner v2.288.0](https://github.com/actions/runner/releases/tag/v2.288.0) or above.*

Job summaries can be disabled with `job_summary: false`.

### GitHub Actions check summary of a commit

Test results are published in the GitHub Actions check summary of the respective commit:

![checks comment example](misc/github-checks-comment.png)

Check runs can be disabled with `check_run: false`.

## The symbols
[comment]: <> (This heading is linked to from method get_link_and_tooltip_label_md)

Expand Down Expand Up @@ -295,6 +305,7 @@ The list of most notable options:
|:-----|:-----:|:----------|
|`time_unit`|`seconds`|Time values in the test result files have this unit. Supports `seconds` and `milliseconds`.|
|`test_file_prefix`|`none`|Paths in the test result files should be relative to the git repository for annotations to work best. This prefix is added to (if starting with "+"), or remove from (if starting with "-") test file paths. Examples: "+src/" or "-/opt/actions-runner".|
|`check_run`|`true`|Set to `true`, the results are published as a check run, but it may not be associated with the workflow that ran this action.|
|`job_summary`|`true`|Set to `true`, the results are published as part of the [job summary page](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/) of the workflow run.|
|`compare_to_earlier_commit`|`true`|Test results are compared to results of earlier commits to show changes:<br/>`false` - disable comparison, `true` - compare across commits.'|
|`test_changes_limit`|`10`|Limits the number of removed or skipped tests reported on pull request comments. This report can be disabled with a value of `0`.|
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ inputs:
description: 'Does not collect test run information from the test result files, which is useful for very large files. This disables any check run annotations.'
default: 'false'
required: false
check_run:
description: 'Set to "true", the results are published as a check run, but it may not be associated with the workflow that ran this action.'
default: 'true'
required: false
job_summary:
description: 'Set to "true", the results are published as part of the job summary page of the workflow run.'
default: 'true'
Expand Down
5 changes: 5 additions & 0 deletions composite/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ inputs:
description: 'Does not collect test run information from the test result files, which is useful for very large files. This disables any check run annotations.'
default: 'false'
required: false
check_run:
description: 'Set to "true", the results are published as a check run, but it may not be associated with the workflow that ran this action.'
default: 'true'
required: false
job_summary:
description: 'Set to "true", the results are published as part of the job summary page of the workflow run.'
default: 'true'
Expand Down Expand Up @@ -293,6 +297,7 @@ runs:
JSON_THOUSANDS_SEPARATOR: ${{ inputs.json_thousands_separator }}
JSON_SUITE_DETAILS: ${{ inputs.json_suite_details }}
JSON_TEST_CASE_RESULTS: ${{ inputs.json_test_case_results }}
CHECK_RUN: ${{ inputs.check_run }}
JOB_SUMMARY: ${{ inputs.job_summary }}
SEARCH_PULL_REQUESTS: ${{ inputs.search_pull_requests }}
# not documented
Expand Down
34 changes: 18 additions & 16 deletions python/publish/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Settings:
check_name: str
comment_title: str
comment_mode: str
check_run: bool
job_summary: bool
compare_earlier: bool
pull_request_build: str
Expand Down Expand Up @@ -196,21 +197,22 @@ def publish(self,
if logger.isEnabledFor(logging.DEBUG):
logger.debug(f'Publishing {stats}')

if self._settings.is_fork:
# running on a fork, we cannot publish the check, but we can still read before_check_run
# bump the version if you change the target of this link (if it did not exist already) or change the section
logger.info('This action is running on a pull_request event for a fork repository. '
'Pull request comments and check runs cannot be created, so disabling these features. '
'To fully run the action on fork repository pull requests, see '
f'https://github.com/EnricoMi/publish-unit-test-result-action/blob/{__version__}/README.md#support-fork-repositories-and-dependabot-branches')
check_run = None
before_check_run = None
if self._settings.compare_earlier:
before_commit_sha = get_json_path(self._settings.event, 'before')
logger.debug(f'comparing against before={before_commit_sha}')
before_check_run = self.get_check_run(before_commit_sha)
else:
check_run, before_check_run = self.publish_check(stats, cases, conclusion)
check_run = None
before_check_run = None
if self._settings.check_run:
if self._settings.is_fork:
# running on a fork, we cannot publish the check, but we can still read before_check_run
# bump the version if you change the target of this link (if it did not exist already) or change the section
logger.info('This action is running on a pull_request event for a fork repository. '
'Pull request comments and check runs cannot be created, so disabling these features. '
'To fully run the action on fork repository pull requests, see '
f'https://github.com/EnricoMi/publish-unit-test-result-action/blob/{__version__}/README.md#support-fork-repositories-and-dependabot-branches')
if self._settings.compare_earlier:
before_commit_sha = get_json_path(self._settings.event, 'before')
logger.debug(f'comparing against before={before_commit_sha}')
before_check_run = self.get_check_run(before_commit_sha)
else:
check_run, before_check_run = self.publish_check(stats, cases, conclusion)

if self._settings.job_summary:
self.publish_job_summary(self._settings.comment_title, stats, check_run, before_check_run)
Expand Down Expand Up @@ -468,7 +470,7 @@ def publish_json(self, data: PublishData):
def publish_job_summary(self,
title: str,
stats: UnitTestRunResults,
check_run: CheckRun,
check_run: Optional[CheckRun],
before_check_run: Optional[CheckRun]):
before_stats = self.get_stats_from_check_run(before_check_run) if before_check_run is not None else None
stats_with_delta = get_stats_delta(stats, before_stats, 'earlier') if before_stats is not None else stats
Expand Down
2 changes: 2 additions & 0 deletions python/publish_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def get_settings(options: dict, gha: GithubAction) -> Settings:
event = json.load(f)

repo = get_var('GITHUB_REPOSITORY', options)
check_run = get_bool_var('CHECK_RUN', options, default=True)
job_summary = get_bool_var('JOB_SUMMARY', options, default=True)
comment_mode = get_var('COMMENT_MODE', options) or comment_mode_always

Expand Down Expand Up @@ -475,6 +476,7 @@ def get_settings(options: dict, gha: GithubAction) -> Settings:
check_name=check_name,
comment_title=get_var('COMMENT_TITLE', options) or check_name,
comment_mode=comment_mode,
check_run=check_run,
job_summary=job_summary,
compare_earlier=get_bool_var('COMPARE_TO_EARLIER_COMMIT', options, default=True),
pull_request_build=get_var('PULL_REQUEST_BUILD', options) or 'merge',
Expand Down
11 changes: 11 additions & 0 deletions python/test/test_action_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def get_settings(token='token',
check_name='check name',
comment_title='title',
comment_mode=comment_mode_always,
check_run=True,
job_summary=True,
compare_earlier=True,
test_changes_limit=10,
Expand Down Expand Up @@ -233,6 +234,7 @@ def get_settings(token='token',
check_name=check_name,
comment_title=comment_title,
comment_mode=comment_mode,
check_run=check_run,
job_summary=job_summary,
compare_earlier=compare_earlier,
pull_request_build=pull_request_build,
Expand Down Expand Up @@ -456,6 +458,15 @@ def test_get_settings_compare_to_earlier_commit(self):
self.do_test_get_settings(COMPARE_TO_EARLIER_COMMIT='foo', expected=self.get_settings(compare_earlier=True), warning=warning, exception=RuntimeError)
self.do_test_get_settings(COMPARE_TO_EARLIER_COMMIT=None, expected=self.get_settings(compare_earlier=True))

def test_get_settings_check_run(self):
warning = 'Option check_run has to be boolean, so either "true" or "false": foo'
self.do_test_get_settings(CHECK_RUN='false', expected=self.get_settings(check_run=False))
self.do_test_get_settings(CHECK_RUN='False', expected=self.get_settings(check_run=False))
self.do_test_get_settings(CHECK_RUN='true', expected=self.get_settings(check_run=True))
self.do_test_get_settings(CHECK_RUN='True', expected=self.get_settings(check_run=True))
self.do_test_get_settings(CHECK_RUN='foo', expected=self.get_settings(check_run=True), warning=warning, exception=RuntimeError)
self.do_test_get_settings(CHECK_RUN=None, expected=self.get_settings(check_run=True))

def test_get_settings_job_summary(self):
warning = 'Option job_summary has to be boolean, so either "true" or "false": foo'
self.do_test_get_settings(JOB_SUMMARY='false', expected=self.get_settings(job_summary=False))
Expand Down
18 changes: 18 additions & 0 deletions python/test/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def create_github_pr(repo: str,
@staticmethod
def create_settings(actor='actor',
comment_mode=comment_mode_always,
check_run=True,
job_summary=True,
compare_earlier=True,
report_individual_runs=False,
Expand Down Expand Up @@ -124,6 +125,7 @@ def create_settings(actor='actor',
check_name='Check Name',
comment_title='Comment Title',
comment_mode=comment_mode,
check_run=check_run,
job_summary=job_summary,
compare_earlier=compare_earlier,
pull_request_build=pull_request_build,
Expand Down Expand Up @@ -491,6 +493,22 @@ def test_publish_without_job_summary_and_comment(self):
self.assertEqual((self.stats, self.cases, 'success'), args)
self.assertEqual({}, kwargs)

def test_publish_without_job_summary_and_comment_on_fork(self):
settings = self.create_settings(is_fork=True, comment_mode=comment_mode_off, job_summary=False)
mock_calls = self.call_mocked_publish(settings, prs=[object()])

self.assertEqual(1, len(mock_calls))
(method, args, kwargs) = mock_calls[0]
self.assertEqual('get_check_run', method)
self.assertEqual(('before', ), args)
self.assertEqual({}, kwargs)

def test_publish_without_check_run_job_summary_and_comment(self):
settings = self.create_settings(comment_mode=comment_mode_off, job_summary=False, check_run=False)
mock_calls = self.call_mocked_publish(settings, prs=[object()])

self.assertEqual(0, len(mock_calls))

def test_publish_with_comment_without_pr(self):
settings = self.create_settings()
mock_calls = self.call_mocked_publish(settings, prs=[])
Expand Down

0 comments on commit d764099

Please sign in to comment.