Skip to content

Commit 7943190

Browse files
authored
Clearer comments (#8229)
1 parent 1e567c0 commit 7943190

File tree

4 files changed

+38
-59
lines changed

4 files changed

+38
-59
lines changed

.github/actions/build_and_test_ya/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ runs:
6868
# tricky: we are searching job with name that contains build_preset
6969
check_url=$(curl -s $jobs_url | jq --arg n "$BUILD_PRESET" -r '.jobs[] | select(.name | contains($n)) | .html_url')
7070
71-
echo "Pre-commit [check]($check_url) for $(git rev-parse HEAD) has started." | .github/scripts/tests/comment-pr.py --rewrite
71+
platform_name="$(echo "$(uname -s)-$(uname -p)" | tr '[:upper:]' '[:lower:]')-$BUILD_PRESET"
72+
echo "Pre-commit [check]($check_url) **$platform_name** for $(git rev-parse HEAD) has started." | .github/scripts/tests/comment-pr.py --rewrite
7273
7374
curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
7475
https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \

.github/actions/test_ya/action.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,12 @@ runs:
273273
echo "10 [Test history](${TESTMO_HISTORY_URL})" >> $SUMMARY_LINKS
274274
fi
275275

276-
CURRENT_MESSAGE="**{platform_name}-${BUILD_PRESET}** is running..."
276+
CURRENT_MESSAGE="ya make is running..."
277277
if [ $IS_RETRY = 0 ]; then
278-
CURRENT_MESSAGE="Check $CURRENT_MESSAGE"
278+
CURRENT_MESSAGE="$CURRENT_MESSAGE"
279279
RERUN_FAILED_OPT=""
280280
else
281-
CURRENT_MESSAGE="Failed tests rerun (try $RETRY) $CURRENT_MESSAGE"
281+
CURRENT_MESSAGE="$CURRENT_MESSAGE (failed tests rerun, try $RETRY)"
282282
RERUN_FAILED_OPT="-X"
283283
fi
284284

@@ -337,7 +337,7 @@ runs:
337337
if [ $FAILED_TESTS_COUNT -gt 500 ]; then
338338
IS_LAST_RETRY=1
339339
TOO_MANY_FAILED="Too many tests failed, NOT going to retry"
340-
echo $TOO_MANY_FAILED | GITHUB_TOKEN="${{ github.token }}" .github/scripts/tests/comment-pr.py --fail
340+
echo $TOO_MANY_FAILED | GITHUB_TOKEN="${{ github.token }}" .github/scripts/tests/comment-pr.py --color red
341341
fi
342342

343343
if [ "${{ inputs.run_tests }}" = "true" ]; then
@@ -421,12 +421,12 @@ runs:
421421
curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
422422
https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
423423
-d '{"state":"failure","description":"The check has been failed","context":"build_${{inputs.build_preset}}"}'
424-
echo "Build failed. see the [logs]($YA_MAKE_OUTPUT_URL)." | .github/scripts/tests/comment-pr.py --fail
424+
echo "Build failed. see the [logs]($YA_MAKE_OUTPUT_URL)." | .github/scripts/tests/comment-pr.py --color red
425425
else
426426
curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
427427
https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
428428
-d '{"state":"success","description":"The check has been completed successfully","context":"build_${{inputs.build_preset}}"}'
429-
echo "Build successful." | .github/scripts/tests/comment-pr.py --ok
429+
echo "Build successful." | .github/scripts/tests/comment-pr.py --color green
430430
fi
431431
432432

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,50 @@
11
#!/usr/bin/env python
2+
import datetime
23
import os
34
import json
45
import argparse
56
from github import Github, Auth as GithubAuth
67
from github.PullRequest import PullRequest
7-
from gh_status import update_pr_comment_text
8+
9+
10+
def update_pr_comment_text(pr: PullRequest, build_preset: str, run_number: int, color: str, text: str, rewrite: bool):
11+
header = f"<!-- status pr={pr.number}, preset={build_preset}, run={run_number} -->"
12+
13+
body = comment = None
14+
for c in pr.get_issue_comments():
15+
if c.body.startswith(header):
16+
print(f"found comment id={c.id}")
17+
comment = c
18+
if not rewrite:
19+
body = [c.body]
20+
break
21+
22+
if body is None:
23+
body = [header]
24+
25+
indicator = f":{color}_circle:"
26+
timestamp_str = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
27+
body.append(f"{indicator} `{timestamp_str}` {text}")
28+
29+
body = "\n".join(body)
30+
31+
if comment is None:
32+
print(f"post new comment")
33+
pr.create_issue_comment(body)
34+
else:
35+
print(f"edit comment")
36+
comment.edit(body)
837

938

1039
def main():
1140
parser = argparse.ArgumentParser()
1241
parser.add_argument("--rewrite", dest="rewrite", action="store_true")
1342
parser.add_argument("--color", dest="color", default="white")
14-
parser.add_argument("--fail", dest="fail", action="store_true")
15-
parser.add_argument("--ok", dest="ok", action="store_true")
1643
parser.add_argument("text", type=argparse.FileType("r"), nargs="?", default="-")
1744

1845
args = parser.parse_args()
1946
color = args.color
2047

21-
if args.ok:
22-
color = 'green'
23-
elif args.fail:
24-
color = 'red'
25-
2648
run_number = int(os.environ.get("GITHUB_RUN_NUMBER"))
2749
build_preset = os.environ["BUILD_PRESET"]
2850

.github/scripts/tests/gh_status.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)