Report Bundle Size #173
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Report Bundle Size | |
| # Renders the bundle-size comment and posts it under the Semantic Bundle Bot | |
| # identity after the Bundle Size workflow completes. | |
| on: | |
| workflow_run: | |
| workflows: [Bundle Size] | |
| branches: ['**'] | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| jobs: | |
| comment: | |
| name: Post bundle-size comment | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' | |
| && github.event.workflow_run.event == 'pull_request' | |
| steps: | |
| # Installation token for the Semantic Bundle Bot GitHub App. Same | |
| # permission surface as GITHUB_TOKEN, but comments post under the bot's | |
| # name and avatar so they read as a suite with the performance bot. | |
| - name: Generate bot token | |
| id: bot-token | |
| uses: actions/create-github-app-token@v3 | |
| with: | |
| client-id: ${{ secrets.SEMANTIC_BUNDLE_BOT_CLIENT_ID }} | |
| private-key: ${{ secrets.SEMANTIC_BUNDLE_BOT_PRIVATE_KEY }} | |
| # check out main: tooling comes from main and the reported sha comes from the event | |
| - uses: actions/checkout@v7 | |
| with: | |
| ref: main | |
| - uses: actions/setup-node@v7 | |
| with: | |
| node-version-file: '.node-version' | |
| # Pin the reporter to main — the PR cannot author the tool that renders | |
| # its own comment (thresholds, headline rule, formatting must be | |
| # author-neutral). No-ops on the bootstrap PR before main has it. | |
| - name: Overlay reporter from main | |
| run: | | |
| git fetch origin main --depth=1 | |
| git checkout origin/main -- tools/ci/size/ 2>/dev/null || true | |
| - name: Download size snapshots | |
| uses: dawidd6/action-download-artifact@v23 | |
| with: | |
| github_token: ${{ steps.bot-token.outputs.token }} | |
| workflow: ${{ github.event.workflow.id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: size-results | |
| # download to a scratch dir, not the workspace, since these artifacts are PR-built | |
| path: ${{ runner.temp }}/size-results | |
| allow_forks: true | |
| - name: Resolve PR number | |
| id: pr | |
| env: | |
| GH_TOKEN: ${{ steps.bot-token.outputs.token }} | |
| HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} | |
| run: | | |
| NUMBER='${{ github.event.workflow_run.pull_requests[0].number }}' | |
| if [ -z "$NUMBER" ] || [ "$NUMBER" = "null" ]; then | |
| NUMBER=$(gh pr list --repo '${{ github.repository }}' \ | |
| --head "$HEAD_BRANCH" --state open --json number --jq '.[0].number // ""') | |
| fi | |
| echo "number=$NUMBER" >> "$GITHUB_OUTPUT" | |
| echo "Resolved PR number: $NUMBER" | |
| - name: Render comment | |
| env: | |
| STARTED: ${{ github.event.workflow_run.created_at }} | |
| ENDED: ${{ github.event.workflow_run.updated_at }} | |
| DISPLAY_TITLE: ${{ github.event.workflow_run.display_title }} | |
| run: | | |
| WALL_CLOCK=$(( $(date -d "$ENDED" +%s) - $(date -d "$STARTED" +%s) )) | |
| node tools/ci/size/reporter.js \ | |
| --results ${{ runner.temp }}/size-results \ | |
| --sha '${{ github.event.workflow_run.head_sha }}' \ | |
| --msg "$DISPLAY_TITLE" \ | |
| --run-url '${{ github.event.workflow_run.html_url }}' \ | |
| --run-id '${{ github.event.workflow_run.id }}' \ | |
| --base-ref 'main' \ | |
| --repo '${{ github.repository }}' \ | |
| --wall-clock "$WALL_CLOCK" \ | |
| --out size-report | |
| - name: Upload size-report.json adjunct | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: size-report | |
| path: size-report/size-report.json | |
| - name: Post or update PR comment | |
| if: steps.pr.outputs.number != '' | |
| uses: ./.github/actions/sticky-bot-comment | |
| with: | |
| token: ${{ steps.bot-token.outputs.token }} | |
| repo: ${{ github.repository }} | |
| pr-number: ${{ steps.pr.outputs.number }} | |
| bot-login: semantic-bundle-bot[bot] | |
| body-file: size-report/comment.md |