Skip to content

Commit 7440126

Browse files
Improve PR number handling in workflow (microsoft#3302)
* Improve PR number handling in workflow Refine PR number extraction and validation method. * Update .github/workflows/python-test-coverage-report.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix error message for invalid PR number --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f8c84d4 commit 7440126

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

.github/workflows/python-test-coverage-report.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ jobs:
3434
# because the workflow_run event does not have access to the PR number
3535
# The PR number is needed to post the comment on the PR
3636
run: |
37-
PR_NUMBER=$(cat pr_number)
38-
echo "PR number: $PR_NUMBER"
39-
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
37+
if [ ! -s pr_number ]; then
38+
echo "PR number file 'pr_number' is missing or empty"
39+
exit 1
40+
fi
41+
PR_NUMBER=$(head -1 pr_number | tr -dc '0-9')
42+
if [ -z "$PR_NUMBER" ]; then
43+
echo "PR number file 'pr_number' does not contain a valid PR number"
44+
exit 1
45+
fi
46+
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV"
4047
- name: Pytest coverage comment
4148
id: coverageComment
4249
uses: MishaKav/pytest-coverage-comment@v1.2.0

0 commit comments

Comments
 (0)