Skip to content

Commit d73acb7

Browse files
committed
Refactor PR comment script to streamline summary handling
This commit modifies the `pr_comment.py` script to simplify the handling of summary files during test completion. The script now reads the summary from a predefined `summary_text.txt` file in the workspace instead of requiring it as a command-line argument. This change enhances usability and reduces the likelihood of errors related to missing summary files. Key changes: - Removed command-line argument for summary file in the completion command. - Implemented logic to read summary content from `summary_text.txt`. - Added warnings for empty or missing summary files to improve feedback during execution.
1 parent 2134fc7 commit d73acb7

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

.github/actions/run_tests/pr_comment.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def format_completion_message(build_preset, test_size, test_targets, summary_con
120120

121121
if __name__ == "__main__":
122122
if len(sys.argv) < 2:
123-
print("::error::Usage: pr_comment.py <start|complete> [summary_file]")
123+
print("::error::Usage: pr_comment.py <start|complete>")
124124
sys.exit(1)
125125

126126
command = sys.argv[1]
@@ -147,24 +147,24 @@ def format_completion_message(build_preset, test_size, test_targets, summary_con
147147
message = format_start_message(build_preset, test_size, test_targets)
148148
create_or_update_comment(pr_number, message, workflow_run_url)
149149
else: # complete
150-
summary_file = sys.argv[2] if len(sys.argv) > 2 else os.environ.get("GITHUB_STEP_SUMMARY")
151-
if not summary_file:
152-
raise ValueError("Summary file path must be provided as argument or GITHUB_STEP_SUMMARY must be set")
153-
154150
status = os.environ.get("TEST_STATUS")
155151
if not status:
156152
raise ValueError("TEST_STATUS environment variable is not set")
157153

158-
if not os.path.exists(summary_file):
159-
raise FileNotFoundError(f"Summary file not found: {summary_file}")
160-
161-
with open(summary_file, 'r', encoding='utf-8') as f:
162-
summary_content = f.read()
154+
# Read summary from summary_text.txt in workspace
155+
workspace = os.environ.get("GITHUB_WORKSPACE", os.getcwd())
156+
summary_text_path = os.path.join(workspace, "summary_text.txt")
163157

164-
if summary_content.strip():
165-
print(f"::notice::Read {len(summary_content)} characters from summary file")
158+
summary_content = ""
159+
if os.path.exists(summary_text_path):
160+
with open(summary_text_path, 'r', encoding='utf-8') as f:
161+
summary_content = f.read()
162+
if summary_content.strip():
163+
print(f"::notice::Read {len(summary_content)} characters from {summary_text_path}")
164+
else:
165+
print(f"::warning::Summary file {summary_text_path} is empty")
166166
else:
167-
print(f"::warning::Summary file is empty")
167+
print(f"::warning::Summary file not found: {summary_text_path}")
168168

169169
message = format_completion_message(
170170
build_preset, test_size, test_targets,

.github/workflows/run_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,4 @@ jobs:
249249
TEST_STATUS: ${{ steps.run_tests.outcome }}
250250
run: |
251251
python3 -m pip install PyGithub -q
252-
python3 ./.github/actions/run_tests/pr_comment.py complete "$GITHUB_STEP_SUMMARY"
252+
python3 ./.github/actions/run_tests/pr_comment.py complete

0 commit comments

Comments
 (0)