Skip to content

Commit b01d000

Browse files
authored
Upload html summary before updating status (#8224)
1 parent 6b0e4a4 commit b01d000

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

.github/actions/test_ya/action.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ runs:
334334
IS_LAST_RETRY=1
335335
fi
336336

337-
s3cmd sync --follow-symlinks --acl-public --no-progress --stats --no-check-md5 "$PUBLIC_DIR/" "$S3_BUCKET_PATH/"
338-
339337
if [ $FAILED_TESTS_COUNT -gt 500 ]; then
340338
IS_LAST_RETRY=1
341339
TOO_MANY_FAILED="Too many tests failed, NOT going to retry"
@@ -351,9 +349,17 @@ runs:
351349
--status_report_file statusrep.txt \
352350
--is_retry $IS_RETRY \
353351
--is_last_retry $IS_LAST_RETRY \
352+
--comment_color_file summary_color.txt \
353+
--comment_text_file summary_text.txt \
354354
"Tests" $CURRENT_PUBLIC_DIR/ya-test.html "$CURRENT_JUNIT_XML_PATH"
355355
fi
356-
356+
357+
s3cmd sync --follow-symlinks --acl-public --no-progress --stats --no-check-md5 "$PUBLIC_DIR/" "$S3_BUCKET_PATH/"
358+
359+
if [ "${{ inputs.run_tests }}" = "true" ]; then
360+
cat summary_text.txt | GITHUB_TOKEN="${{ github.token }}" .github/scripts/tests/comment-pr.py --color `cat summary_color.txt`
361+
fi
362+
357363
# upload tests results to YDB
358364
ydb_upload_run_name="${TESTMO_RUN_NAME// /"_"}"
359365
result=`.github/scripts/upload_tests_results.py --test-results-file ${CURRENT_JUNIT_XML_PATH} --run-timestamp $(date +%s) --commit $(git rev-parse HEAD) --build-type ${BUILD_PRESET} --pull $ydb_upload_run_name --job-name "${{ github.workflow }}" --job-id "${{ github.run_id }}" --branch ${GITHUB_REF_NAME}`

.github/scripts/tests/comment-pr.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ def main():
3232
event = json.load(fp)
3333

3434
pr = gh.create_from_raw_data(PullRequest, event["pull_request"])
35-
update_pr_comment_text(pr, build_preset, run_number, color, args.text.read().rstrip(), args.rewrite)
35+
text = args.text.read()
36+
if text.endswith("\n"):
37+
# dirty hack because echo adds a new line
38+
# and 'echo | comment-pr.py' leads to an extra newline
39+
text = text[:-1]
40+
41+
update_pr_comment_text(pr, build_preset, run_number, color, text, args.rewrite)
3642

3743

3844
if __name__ == "__main__":

.github/scripts/tests/generate-summary.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
#!/usr/bin/env python3
22
import argparse
33
import dataclasses
4-
import datetime
5-
import json
64
import os
7-
import re
85
import sys
96
import traceback
10-
from github import Github, Auth as GithubAuth
11-
from github.PullRequest import PullRequest
127
from enum import Enum
138
from operator import attrgetter
14-
from typing import List, Optional, Dict
9+
from typing import List, Dict
1510
from jinja2 import Environment, FileSystemLoader, StrictUndefined
1611
from junit_utils import get_property_value, iter_xml_files
17-
from gh_status import update_pr_comment_text
1812
from get_test_history import get_test_history
1913

2014

@@ -328,7 +322,7 @@ def gen_summary(public_dir, public_dir_url, paths, is_retry: bool, build_preset)
328322
return summary
329323

330324

331-
def get_comment_text(pr: PullRequest, summary: TestSummary, summary_links: str, is_last_retry: bool)->tuple[str, list[str]]:
325+
def get_comment_text(summary: TestSummary, summary_links: str, is_last_retry: bool)->tuple[str, list[str]]:
332326
color = "red"
333327
if summary.is_failed:
334328
color = "red" if is_last_retry else "yellow"
@@ -379,6 +373,8 @@ def main():
379373
parser.add_argument('--status_report_file', required=False)
380374
parser.add_argument('--is_retry', required=True, type=int)
381375
parser.add_argument('--is_last_retry', required=True, type=int)
376+
parser.add_argument('--comment_color_file', required=True)
377+
parser.add_argument('--comment_text_file', required=True)
382378
parser.add_argument("args", nargs="+", metavar="TITLE html_out path")
383379
args = parser.parse_args()
384380

@@ -397,21 +393,17 @@ def main():
397393
else:
398394
overall_status = "success"
399395

400-
if os.environ.get("GITHUB_EVENT_NAME") in ("pull_request", "pull_request_target"):
401-
gh = Github(auth=GithubAuth.Token(os.environ["GITHUB_TOKEN"]))
402-
run_number = int(os.environ.get("GITHUB_RUN_NUMBER"))
396+
color, text = get_comment_text(summary, args.summary_links, is_last_retry=bool(args.is_last_retry))
403397

404-
with open(os.environ["GITHUB_EVENT_PATH"]) as fp:
405-
event = json.load(fp)
398+
with open(args.comment_color_file, "w") as f:
399+
f.write(color)
406400

407-
pr = gh.create_from_raw_data(PullRequest, event["pull_request"])
408-
color, text = get_comment_text(pr, summary, args.summary_links, is_last_retry=bool(args.is_last_retry))
401+
with open(args.comment_text_file, "w") as f:
402+
f.write('\n'.join(text))
403+
f.write('\n')
409404

410-
update_pr_comment_text(pr, args.build_preset, run_number, color, text='\n'.join(text), rewrite=False)
411-
412-
if args.status_report_file:
413-
with open(args.status_report_file, 'w') as fo:
414-
fo.write(overall_status)
405+
with open(args.status_report_file, "w") as f:
406+
f.write(overall_status)
415407

416408

417409
if __name__ == "__main__":

0 commit comments

Comments
 (0)