diff --git a/python/publish/publisher.py b/python/publish/publisher.py index e299a52c..8291959e 100644 --- a/python/publish/publisher.py +++ b/python/publish/publisher.py @@ -69,6 +69,7 @@ class PublishData: stats: UnitTestRunResults stats_with_delta: Optional[UnitTestRunDeltaResults] annotations: List[Annotation] + check_url: str @classmethod def _format_digit(cls, value: Union[int, Mapping[str, int], Any], thousands_separator: str) -> Union[str, Mapping[str, str], Any]: @@ -311,23 +312,12 @@ def publish_check(self, title = get_short_summary(stats) summary = get_long_summary_md(stats_with_delta) - # create full json - data = PublishData( - title=title, - summary=summary, - conclusion=conclusion, - stats=stats, - stats_with_delta=stats_with_delta if before_stats is not None else None, - annotations=all_annotations - ) - self.publish_json(data) - # we can send only 50 annotations at once, so we split them into chunks of 50 check_run = None summary_with_digest = get_long_summary_with_digest_md(stats_with_delta, stats) - all_annotations = [annotation.to_dict() for annotation in all_annotations] - all_annotations = [all_annotations[x:x+50] for x in range(0, len(all_annotations), 50)] or [[]] - for annotations in all_annotations: + split_annotations = [annotation.to_dict() for annotation in all_annotations] + split_annotations = [split_annotations[x:x+50] for x in range(0, len(split_annotations), 50)] or [[]] + for annotations in split_annotations: output = dict( title=title, summary=summary_with_digest, @@ -346,6 +336,19 @@ def publish_check(self, logger.debug(f'updating check with {len(annotations)} more annotations') check_run.edit(output=output) logger.debug(f'updated check') + + # create full json + data = PublishData( + title=title, + summary=summary, + conclusion=conclusion, + stats=stats, + stats_with_delta=stats_with_delta if before_stats is not None else None, + annotations=all_annotations, + check_url=check_run.html_url + ) + self.publish_json(data) + return check_run, before_check_run def publish_json(self, data: PublishData): diff --git a/python/test/test_publisher.py b/python/test/test_publisher.py index c956c9c8..3cd700e2 100644 --- a/python/test/test_publisher.py +++ b/python/test/test_publisher.py @@ -1338,6 +1338,7 @@ def do_test_publish_check_without_base_stats(self, errors: List[ParseError], ann '"conclusion": "conclusion", ' '"stats": {"files": 1, ' + f'"errors": {len(errors)}, ' + '"suites": 2, "duration": 3, "tests": 22, "tests_succ": 4, "tests_skip": 5, "tests_fail": 6, "tests_error": 7, "runs": 38, "runs_succ": 8, "runs_skip": 9, "runs_fail": 10, "runs_error": 11, "commit": "commit"}, ' f'"annotations": {len(annotations)}, ' + f'"check_url": "{check_run.html_url}", ' '"formatted": {' '"stats": {"files": "1", ' + f'"errors": "{len(errors)}", ' + '"suites": "2", "duration": "3", "tests": "22", "tests_succ": "4", "tests_skip": "5", "tests_fail": "6", "tests_error": "7", "runs": "38", "runs_succ": "8", "runs_skip": "9", "runs_fail": "10", "runs_error": "11", "commit": "commit"}' '}' @@ -1410,6 +1411,7 @@ def do_test_publish_check_with_base_stats(self, errors: List[ParseError]): '"stats": {"files": 1, ' + f'"errors": {len(errors)}, ' + '"suites": 2, "duration": 3, "tests": 22, "tests_succ": 4, "tests_skip": 5, "tests_fail": 6, "tests_error": 7, "runs": 38, "runs_succ": 8, "runs_skip": 9, "runs_fail": 10, "runs_error": 11, "commit": "commit"}, ' '"stats_with_delta": {"files": {"number": 1, "delta": 0}, ' + f'"errors": {len(errors)}, ' + '"suites": {"number": 2, "delta": 0}, "duration": {"duration": 3, "delta": 0}, "tests": {"number": 22, "delta": 1}, "tests_succ": {"number": 4, "delta": -8}, "tests_skip": {"number": 5, "delta": 1}, "tests_fail": {"number": 6, "delta": 4}, "tests_error": {"number": 7, "delta": 4}, "runs": {"number": 38, "delta": 1}, "runs_succ": {"number": 8, "delta": -17}, "runs_skip": {"number": 9, "delta": 2}, "runs_fail": {"number": 10, "delta": 6}, "runs_error": {"number": 11, "delta": 10}, "commit": "commit", "reference_type": "earlier", "reference_commit": "past"}, ' f'"annotations": {4 + len(errors)}, ' + f'"check_url": "{check_run.html_url}", ' '"formatted": {' '"stats": {"files": "1", ' + f'"errors": "{len(errors)}", ' + '"suites": "2", "duration": "3", "tests": "22", "tests_succ": "4", "tests_skip": "5", "tests_fail": "6", "tests_error": "7", "runs": "38", "runs_succ": "8", "runs_skip": "9", "runs_fail": "10", "runs_error": "11", "commit": "commit"}, ' '"stats_with_delta": {"files": {"number": "1", "delta": "0"}, ' + f'"errors": "{len(errors)}", ' + '"suites": {"number": "2", "delta": "0"}, "duration": {"duration": "3", "delta": "0"}, "tests": {"number": "22", "delta": "1"}, "tests_succ": {"number": "4", "delta": "-8"}, "tests_skip": {"number": "5", "delta": "1"}, "tests_fail": {"number": "6", "delta": "4"}, "tests_error": {"number": "7", "delta": "4"}, "runs": {"number": "38", "delta": "1"}, "runs_succ": {"number": "8", "delta": "-17"}, "runs_skip": {"number": "9", "delta": "2"}, "runs_fail": {"number": "10", "delta": "6"}, "runs_error": {"number": "11", "delta": "10"}, "commit": "commit", "reference_type": "earlier", "reference_commit": "past"}' @@ -1591,7 +1593,8 @@ def test_publish_check_with_multiple_annotation_pages(self): message='message', title=f'Error processing result file', raw_details='file' - )] + )], + check_url='http://check-run.url' ) def test_publish_data(self): @@ -1694,7 +1697,8 @@ def test_publish_data(self): 'raw_details': 'file', 'start_column': 3, 'start_line': 1, - 'title': 'Error processing result file'}]}, + 'title': 'Error processing result file'}], + 'check_url': 'http://check-run.url'}, self.publish_data.to_dict(separator)) self.assertEqual({ @@ -1765,7 +1769,8 @@ def test_publish_data(self): 'tests_fail': {'delta': "-7", 'number': "7"}, 'tests_skip': {'delta': "-6", 'number': "6"}, 'tests_succ': {'delta': "-5", 'number': "5"}}}, - 'annotations': 1}, + 'annotations': 1, + 'check_url': 'http://check-run.url'}, self.publish_data.to_reduced_dict(separator)) def test_publish_json(self): @@ -1792,6 +1797,7 @@ def test_publish_json(self): '"stats": {"files": 12345, "errors": [{"file": "file", "message": "message", "line": 1, "column": 2}], "suites": 2, "duration": 3456, "tests": 4, "tests_succ": 5, "tests_skip": 6, "tests_fail": 7, "tests_error": 8901, "runs": 9, "runs_succ": 10, "runs_skip": 11, "runs_fail": 12, "runs_error": 1345, "commit": "commit"}, ' '"stats_with_delta": {"files": {"number": 1234, "delta": -1234}, "errors": [{"file": "file", "message": "message", "line": 1, "column": 2}, {"file": "file2", "message": "message2", "line": 2, "column": 4}], "suites": {"number": 2, "delta": -2}, "duration": {"number": 3456, "delta": -3456}, "tests": {"number": 4, "delta": -4}, "tests_succ": {"number": 5, "delta": -5}, "tests_skip": {"number": 6, "delta": -6}, "tests_fail": {"number": 7, "delta": -7}, "tests_error": {"number": 8, "delta": -8}, "runs": {"number": 9, "delta": -9}, "runs_succ": {"number": 10, "delta": -10}, "runs_skip": {"number": 11, "delta": -11}, "runs_fail": {"number": 12, "delta": -12}, "runs_error": {"number": 1345, "delta": -1345}, "commit": "commit", "reference_type": "type", "reference_commit": "ref"}, ' '"annotations": [{"path": "path", "start_line": 1, "end_line": 2, "start_column": 3, "end_column": 4, "annotation_level": "failure", "message": "message", "title": "Error processing result file", "raw_details": "file"}], ' + '"check_url": "http://check-run.url", ' '"formatted": {' '"stats": {"files": "12' + separator + '345", "errors": [{"file": "file", "message": "message", "line": 1, "column": 2}], "suites": "2", "duration": "3' + separator + '456", "tests": "4", "tests_succ": "5", "tests_skip": "6", "tests_fail": "7", "tests_error": "8' + separator + '901", "runs": "9", "runs_succ": "10", "runs_skip": "11", "runs_fail": "12", "runs_error": "1' + separator + '345", "commit": "commit"}, ' '"stats_with_delta": {"files": {"number": "1' + separator + '234", "delta": "-1' + separator + '234"}, "errors": [{"file": "file", "message": "message", "line": 1, "column": 2}, {"file": "file2", "message": "message2", "line": 2, "column": 4}], "suites": {"number": "2", "delta": "-2"}, "duration": {"number": "3' + separator + '456", "delta": "-3' + separator + '456"}, "tests": {"number": "4", "delta": "-4"}, "tests_succ": {"number": "5", "delta": "-5"}, "tests_skip": {"number": "6", "delta": "-6"}, "tests_fail": {"number": "7", "delta": "-7"}, "tests_error": {"number": "8", "delta": "-8"}, "runs": {"number": "9", "delta": "-9"}, "runs_succ": {"number": "10", "delta": "-10"}, "runs_skip": {"number": "11", "delta": "-11"}, "runs_fail": {"number": "12", "delta": "-12"}, "runs_error": {"number": "1' + separator + '345", "delta": "-1' + separator + '345"}, "commit": "commit", "reference_type": "type", "reference_commit": "ref"}' @@ -1820,6 +1826,7 @@ def test_publish_json(self): "runs_error": {"number": 1345, "delta": -1345}, "commit": "commit", "reference_type": "type", "reference_commit": "ref"}, "annotations": 1, + "check_url": "http://check-run.url", "formatted": { "stats": {"files": "12" + separator + "345", "errors": "1", "suites": "2", "duration": "3" + separator + "456", "tests": "4", "tests_succ": "5", "tests_skip": "6", "tests_fail": "7", "tests_error": "8" + separator + "901", "runs": "9", "runs_succ": "10",