Browse Source

Clearer comments (#8229)

Maxim Yurchuk 6 months ago
parent
commit
794319067b

+ 2 - 1
.github/actions/build_and_test_ya/action.yml

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

+ 6 - 6
.github/actions/test_ya/action.yml

@@ -273,12 +273,12 @@ runs:
             echo "10 [Test history](${TESTMO_HISTORY_URL})" >> $SUMMARY_LINKS
             echo "10 [Test history](${TESTMO_HISTORY_URL})" >> $SUMMARY_LINKS
           fi
           fi
 
 
-          CURRENT_MESSAGE="**{platform_name}-${BUILD_PRESET}** is running..." 
+          CURRENT_MESSAGE="ya make is running..." 
           if [ $IS_RETRY = 0 ]; then
           if [ $IS_RETRY = 0 ]; then
-            CURRENT_MESSAGE="Check $CURRENT_MESSAGE"
+            CURRENT_MESSAGE="$CURRENT_MESSAGE"
             RERUN_FAILED_OPT=""
             RERUN_FAILED_OPT=""
           else
           else
-            CURRENT_MESSAGE="Failed tests rerun (try $RETRY) $CURRENT_MESSAGE"
+            CURRENT_MESSAGE="$CURRENT_MESSAGE (failed tests rerun, try $RETRY)"
             RERUN_FAILED_OPT="-X"
             RERUN_FAILED_OPT="-X"
           fi
           fi
 
 
@@ -337,7 +337,7 @@ runs:
           if [ $FAILED_TESTS_COUNT -gt 500 ]; then 
           if [ $FAILED_TESTS_COUNT -gt 500 ]; then 
             IS_LAST_RETRY=1
             IS_LAST_RETRY=1
             TOO_MANY_FAILED="Too many tests failed, NOT going to retry"
             TOO_MANY_FAILED="Too many tests failed, NOT going to retry"
-            echo $TOO_MANY_FAILED | GITHUB_TOKEN="${{ github.token }}" .github/scripts/tests/comment-pr.py --fail
+            echo $TOO_MANY_FAILED | GITHUB_TOKEN="${{ github.token }}" .github/scripts/tests/comment-pr.py --color red
           fi
           fi
 
 
           if [ "${{ inputs.run_tests }}" = "true" ]; then
           if [ "${{ inputs.run_tests }}" = "true" ]; then
@@ -421,12 +421,12 @@ runs:
           curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
           curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
             https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
             https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
             -d '{"state":"failure","description":"The check has been failed","context":"build_${{inputs.build_preset}}"}'
             -d '{"state":"failure","description":"The check has been failed","context":"build_${{inputs.build_preset}}"}'
-          echo "Build failed. see the [logs]($YA_MAKE_OUTPUT_URL)." | .github/scripts/tests/comment-pr.py --fail
+          echo "Build failed. see the [logs]($YA_MAKE_OUTPUT_URL)." | .github/scripts/tests/comment-pr.py --color red
         else
         else
           curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
           curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
             https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
             https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
             -d '{"state":"success","description":"The check has been completed successfully","context":"build_${{inputs.build_preset}}"}'
             -d '{"state":"success","description":"The check has been completed successfully","context":"build_${{inputs.build_preset}}"}'
-          echo "Build successful." | .github/scripts/tests/comment-pr.py --ok
+          echo "Build successful." | .github/scripts/tests/comment-pr.py --color green
         fi
         fi
     
     
 
 

+ 30 - 8
.github/scripts/tests/comment-pr.py

@@ -1,28 +1,50 @@
 #!/usr/bin/env python
 #!/usr/bin/env python
+import datetime
 import os
 import os
 import json
 import json
 import argparse
 import argparse
 from github import Github, Auth as GithubAuth
 from github import Github, Auth as GithubAuth
 from github.PullRequest import PullRequest
 from github.PullRequest import PullRequest
-from gh_status import update_pr_comment_text
+
+
+def update_pr_comment_text(pr: PullRequest, build_preset: str, run_number: int, color: str, text: str, rewrite: bool):
+    header = f"<!-- status pr={pr.number}, preset={build_preset}, run={run_number} -->"
+
+    body = comment = None
+    for c in pr.get_issue_comments():
+        if c.body.startswith(header):
+            print(f"found comment id={c.id}")
+            comment = c
+            if not rewrite:
+                body = [c.body]
+            break
+
+    if body is None:
+        body = [header]
+
+    indicator = f":{color}_circle:"
+    timestamp_str = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
+    body.append(f"{indicator} `{timestamp_str}` {text}")
+
+    body = "\n".join(body)
+
+    if comment is None:
+        print(f"post new comment")
+        pr.create_issue_comment(body)
+    else:
+        print(f"edit comment")
+        comment.edit(body)
 
 
 
 
 def main():
 def main():
     parser = argparse.ArgumentParser()
     parser = argparse.ArgumentParser()
     parser.add_argument("--rewrite", dest="rewrite", action="store_true")
     parser.add_argument("--rewrite", dest="rewrite", action="store_true")
     parser.add_argument("--color", dest="color", default="white")
     parser.add_argument("--color", dest="color", default="white")
-    parser.add_argument("--fail", dest="fail", action="store_true")
-    parser.add_argument("--ok", dest="ok", action="store_true")
     parser.add_argument("text", type=argparse.FileType("r"), nargs="?", default="-")
     parser.add_argument("text", type=argparse.FileType("r"), nargs="?", default="-")
 
 
     args = parser.parse_args()
     args = parser.parse_args()
     color = args.color
     color = args.color
 
 
-    if args.ok:
-        color = 'green'
-    elif args.fail:
-        color = 'red'
-
     run_number = int(os.environ.get("GITHUB_RUN_NUMBER"))
     run_number = int(os.environ.get("GITHUB_RUN_NUMBER"))
     build_preset = os.environ["BUILD_PRESET"]
     build_preset = os.environ["BUILD_PRESET"]
 
 

+ 0 - 44
.github/scripts/tests/gh_status.py

@@ -1,44 +0,0 @@
-import datetime
-import platform
-from github.PullRequest import PullRequest
-
-
-def get_timestamp():
-    return datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
-
-
-def get_platform_name():
-    return f'{platform.system().lower()}-{platform.machine()}'
-
-
-def update_pr_comment_text(pr: PullRequest, build_preset: str, run_number: int, color: str, text: str, rewrite: bool):
-    platform_name = get_platform_name()
-    header = f"<!-- status pr={pr.number}, preset={platform_name}-{build_preset}, run={run_number} -->"
-
-    body = comment = None
-    for c in pr.get_issue_comments():
-        if c.body.startswith(header):
-            print(f"found comment id={c.id}")
-            comment = c
-            if not rewrite:
-                body = [c.body]
-            break
-
-    if body is None:
-        body = [header]
-
-    indicator = f":{color}_circle:"
-    body.append(f"{indicator} `{get_timestamp()}` {text}")
-
-    body = "\n".join(body)
-
-    if '{platform_name}' in body:
-        # input can contain '{platform_name}'
-        body = body.replace('{platform_name}', platform_name)
-
-    if comment is None:
-        print(f"post new comment")
-        pr.create_issue_comment(body)
-    else:
-        print(f"edit comment")
-        comment.edit(body)