ci: Fix commenting of bundle size (#9539)

PR number couldn't be retrieved properly before, so we were never
commenting. Move jobs to one file to mitigate it.
This commit is contained in:
Wojciech Tyczyński
2025-12-23 14:55:29 +01:00
committed by GitHub
parent 9e5c1a95e8
commit 10bf3115d2
2 changed files with 42 additions and 58 deletions
@@ -1,58 +0,0 @@
name: Comment Bundle Size
# Runs when Measure Bundle Size workflow completes.
# This will run with full privileges.
on:
workflow_run:
workflows: [Measure Bundle Size]
types: [completed]
jobs:
comment:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download report artifact
uses: actions/download-artifact@v4
with:
name: bundle-report
path: artifact
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.SHAKA_BOT_TOKEN }}
- name: Add or Update PR Comment
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.SHAKA_BOT_TOKEN }}
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
COMMENT_INCLUDES: "Bundle Size Report"
COMMENT_USER: "shaka-bot"
run: |
if [ -z "$PR_NUMBER" ]; then
echo "No PR found."
exit 0
fi
MESSAGE=$(cat artifact/report.md)
echo "$MESSAGE"
# Find existing bot 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
echo "Creating new bundle size comment"
gh api \
--method POST \
/repos/${{ github.repository }}/issues/$PR_NUMBER/comments \
-f "body=$MESSAGE"
else
echo "Updating existing bundle size comment"
gh api \
--method PATCH \
/repos/${{ github.repository }}/issues/comments/$(cat old-comment-id) \
-f "body=$MESSAGE"
fi
@@ -74,3 +74,45 @@ jobs:
name: bundle-report
path: report.md
retention-days: 1
comment:
runs-on: ubuntu-latest
needs: bundle-size
steps:
- name: Download report artifact
uses: actions/download-artifact@v4
with:
name: bundle-report
path: artifact
- name: Add or Update PR Comment
shell: bash
env:
GH_TOKEN: ${{ secrets.SHAKA_BOT_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
COMMENT_INCLUDES: "Bundle Size Report"
COMMENT_USER: "shaka-bot"
run: |
MESSAGE=$(cat artifact/report.md)
echo "$MESSAGE"
# Find existing bot 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
echo "Creating new bundle size comment"
gh api \
--method POST \
/repos/${{ github.repository }}/issues/$PR_NUMBER/comments \
-f "body=$MESSAGE"
else
echo "Updating existing bundle size comment"
gh api \
--method PATCH \
/repos/${{ github.repository }}/issues/comments/$(cat old-comment-id) \
-f "body=$MESSAGE"
fi