Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Use GitHub API directly to post PR coverage comments #7758

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions .github/workflows/report-incremental-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,30 @@ jobs:
--run-id ${{ github.event.workflow_run.id }}

- name: Report incremental code coverage
uses: thollander/actions-comment-pull-request@686ab1cab89e0f715a44a0d04b9fdfdd4f33d751
with:
message: "Incremental code coverage: ${{ steps.compute.outputs.coverage }}"
comment_includes: "Incremental code coverage: "
pr_number: ${{ steps.compute.outputs.pr_number }}
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.SHAKA_BOT_TOKEN }}
PR_NUMBER: ${{ steps.compute.outputs.pr_number }}
MESSAGE: "Incremental code coverage: ${{ steps.compute.outputs.coverage }}"
COMMENT_INCLUDES: "Incremental code coverage: "
COMMENT_USER: "shaka-bot"
run: |
# Look for an old comment
jq_filter=".[] | select((.user.login == \"$COMMENT_USER\") and (.body | startswith(\"$COMMENT_INCLUDES\"))) | .id"
gh api \
/repos/${{ github.repository }}/issues/$PR_NUMBER/comments \
| jq "$jq_filter" > old-comment-id

if [[ -z "$(cat old-comment-id)" ]]; then
# Create a new comment
gh api \
--method POST \
/repos/${{ github.repository }}/issues/$PR_NUMBER/comments \
-F "body=$MESSAGE"
else
# Update an old comment
gh api \
--method PATCH \
/repos/${{ github.repository }}/issues/comments/$(cat old-comment-id) \
-F "body=$MESSAGE"
fi
Loading