Skip to content

Bundle Size Comment #916

Bundle Size Comment

Bundle Size Comment #916

name: Bundle Size Comment
on:
workflow_run:
workflows: ["Check"]
types:
- completed
concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true
permissions: {}
jobs:
comment:
name: Bundle
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
permissions:
actions: read
pull-requests: write
timeout-minutes: 1
steps:
- name: Download Artifact
uses: actions/download-artifact@v8
with:
name: bundle-stats
path: bundle-stats
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Get stats
id: stats
run: |
max_bytes=48000
max_lines=500
safe_stats="$(mktemp)"
tr '\140' '\047' < bundle-stats/stats.txt > "${safe_stats}"
byte_count="$(wc -c < "${safe_stats}")"
line_count="$(awk 'END { print NR }' "${safe_stats}")"
delimiter="EOF_$(openssl rand -hex 16)"
{
echo "stats<<${delimiter}"
echo '```text'
head -n "${max_lines}" "${safe_stats}" | head -c "${max_bytes}" | iconv -c -f UTF-8 -t UTF-8 2>/dev/null || true
echo
if [ "${byte_count}" -gt "${max_bytes}" ] || [ "${line_count}" -gt "${max_lines}" ]; then
echo "[output truncated at ${max_lines} lines or ${max_bytes} bytes]"
fi
echo '```'
echo "${delimiter}"
} >> "${GITHUB_OUTPUT}"
rm "${safe_stats}"
# https://github.com/orgs/community/discussions/25220#discussioncomment-11300118
- name: Get PR number
id: pr-context
env:
GH_TOKEN: ${{ github.token }}
PR_TARGET_REPO: ${{ github.repository }}
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
run: gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" --json 'number' --jq '"number=\(.number)"' >> "${GITHUB_OUTPUT}"
- name: Find Comment
id: find-comment
uses: peter-evans/find-comment@v4
with:
issue-number: ${{ steps.pr-context.outputs.number }}
comment-author: "github-actions[bot]"
body-includes: <!-- This comment was auto-generated by GitHub Actions to display bundle size statistics -->
- name: Create Comment
id: comment
uses: peter-evans/create-or-update-comment@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUNDLE_STATS: "${{ steps.stats.outputs.stats }}"
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.pr-context.outputs.number }}
edit-mode: replace
body: |
<!-- This comment was auto-generated by GitHub Actions to display bundle size statistics -->
## Bundle Size Analysis
Generated from PR build output; treat the content below as untrusted.
${{ env.BUNDLE_STATS }}