ci: report size change + always check single file build#320
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
Caution Review failedThe pull request is closed. WalkthroughThe pull request introduces a new GitHub Actions workflow for managing bundle statistics and extends the CI pipeline with additional steps. The "Bundle Stats" workflow, triggered via Changes
Sequence Diagram(s)sequenceDiagram
participant CI as CI Pipeline
participant BS as Bundle Stats Workflow
participant FS as File System (/tmp/bundle-stats.json)
participant GS as Gist Service
CI->>BS: Invoke workflow_call with (mode, branch)
alt Mode is "store"
BS->>FS: Read bundle stats JSON file
BS->>GS: getGistContent(gistID)
GS-->>BS: Return current stats
BS->>GS: updateGistContent(new stats)
BS-->>CI: Return updated stats output
else Mode is "compare"
BS->>FS: Read bundle stats JSON file
BS->>GS: getGistContent(gistID)
GS-->>BS: Return current stats
BS->>BS: Compare current vs new stats
BS-->>CI: Return comparison string as output
end
sequenceDiagram
participant CI as CI Step
participant BS as Bundle Stats Workflow
participant PR as Pull Request API
CI->>CI: Create zip package & parse bundle stats
CI->>BS: Invoke Bundle Stats workflow (store/compare)
BS-->>CI: Return stats result
CI->>PR: Update PR Description with bundle stats
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||
There was a problem hiding this comment.
Actionable comments posted: 3
🔭 Outside diff range comments (1)
.github/workflows/bundle-stats.yml (1)
45-58: 🛠️ Refactor suggestionAdd error handling for Gist operations
The current implementation doesn't handle potential errors when interacting with Gists or when parsing the JSON data. Adding proper error handling would make this more robust.
if ('${{ inputs.mode }}' === 'store') { - const stats = require('/tmp/bundle-stats.json'); - const content = await getGistContent(); - content['${{ inputs.branch }}'] = stats; - await updateGistContent(content); + try { + const stats = require('/tmp/bundle-stats.json'); + const content = await getGistContent(); + content['${{ inputs.branch }}'] = stats; + await updateGistContent(content); + console.log(`Successfully stored bundle stats for branch: ${{ inputs.branch }}`); + } catch (error) { + core.setFailed(`Failed to store bundle stats: ${error.message}`); + } } else { - const content = await getGistContent(); - const baseStats = content['${{ inputs.branch }}']; - const newStats = require('/tmp/bundle-stats.json'); - - const comparison = `minecraft.html (normal build gzip)\n${baseStats.total}MB (${baseStats.gzipped}MB compressed) -> ${newStats.total}MB (${newStats.gzipped}MB compressed)`; - core.setOutput('stats', comparison); + try { + const content = await getGistContent(); + const baseStats = content['${{ inputs.branch }}']; + + if (!baseStats) { + throw new Error(`No baseline stats found for branch: ${{ inputs.branch }}`); + } + + const newStats = require('/tmp/bundle-stats.json'); + const comparison = `minecraft.html (normal build gzip)\n${baseStats.total}MB (${baseStats.gzipped}MB compressed) -> ${newStats.total}MB (${newStats.gzipped}MB compressed)`; + core.setOutput('stats', comparison); + console.log(`Successfully compared bundle stats for branch: ${{ inputs.branch }}`); + } catch (error) { + core.setFailed(`Failed to compare bundle stats: ${error.message}`); + // Provide a fallback output so the workflow doesn't fail completely + const newStats = require('/tmp/bundle-stats.json'); + core.setOutput('stats', `Current build: ${newStats.total}MB (${newStats.gzipped}MB compressed) [No baseline for comparison]`); + } }
🧹 Nitpick comments (3)
rsbuild.config.ts (1)
206-211: Improve error handling in the single file build validationThe validation check for the single file build is a good addition, but it could benefit from better error handling in case the directory doesn't exist.
- // check that only index.html is in the dist/single folder - const singleBuildFiles = fs.readdirSync('./dist/single') - if (singleBuildFiles.length !== 1 || singleBuildFiles[0] !== 'index.html') { - throw new Error('Single file build must only have index.html in the dist/single folder. Ensure workers are imported & built correctly.') - } + // check that only index.html is in the dist/single folder + try { + const singleBuildFiles = fs.readdirSync('./dist/single') + if (singleBuildFiles.length !== 1 || singleBuildFiles[0] !== 'index.html') { + throw new Error('Single file build must only have index.html in the dist/single folder. Ensure workers are imported & built correctly.') + } + } catch (error) { + if (error.code === 'ENOENT') { + throw new Error('Single file build directory not found. Build may have failed earlier.') + } + throw error + }.github/workflows/ci.yml (1)
51-58: Improve error handling for bundle stats calculationThe current implementation might fail silently if files don't exist or commands fail. Adding error checking would make this more robust.
- - name: Parse Bundle Stats - run: | - SIZE_BYTES=$(du -s dist/single/minecraft.html 2>/dev/null | cut -f1) - GZIP_BYTES=$(du -s self-host.zip 2>/dev/null | cut -f1) - SIZE=$(echo "scale=2; $SIZE_BYTES/1024/1024" | bc) - GZIP_SIZE=$(echo "scale=2; $GZIP_BYTES/1024/1024" | bc) - echo "{\"total\": ${SIZE}, \"gzipped\": ${GZIP_SIZE}}" > /tmp/bundle-stats.json + - name: Parse Bundle Stats + run: | + if [ ! -f dist/single/minecraft.html ]; then + echo "Error: minecraft.html not found. Using fallback values." + SIZE="0.00" + else + SIZE_BYTES=$(du -s dist/single/minecraft.html | cut -f1) + SIZE=$(echo "scale=2; $SIZE_BYTES/1024/1024" | bc) + fi + + if [ ! -f self-host.zip ]; then + echo "Error: self-host.zip not found. Using fallback values." + GZIP_SIZE="0.00" + else + GZIP_BYTES=$(du -s self-host.zip | cut -f1) + GZIP_SIZE=$(echo "scale=2; $GZIP_BYTES/1024/1024" | bc) + fi + + echo "{\"total\": ${SIZE}, \"gzipped\": ${GZIP_SIZE}}" > /tmp/bundle-stats.json.github/workflows/bundle-stats.yml (1)
55-55: Improve format of the stats outputThe current output format could be improved to provide more context and better readability in the PR description.
- const comparison = `minecraft.html (normal build gzip)\n${baseStats.total}MB (${baseStats.gzipped}MB compressed) -> ${newStats.total}MB (${newStats.gzipped}MB compressed)`; + const totalDiff = (newStats.total - baseStats.total).toFixed(2); + const gzipDiff = (newStats.gzipped - baseStats.gzipped).toFixed(2); + const totalDiffStr = totalDiff > 0 ? `+${totalDiff}` : totalDiff; + const gzipDiffStr = gzipDiff > 0 ? `+${gzipDiff}` : gzipDiff; + const comparison = `minecraft.html bundle size:\n${baseStats.total}MB → ${newStats.total}MB (${totalDiffStr}MB, ${(totalDiff / baseStats.total * 100).toFixed(1)}%)\nCompressed: ${baseStats.gzipped}MB → ${newStats.gzipped}MB (${gzipDiffStr}MB, ${(gzipDiff / baseStats.gzipped * 100).toFixed(1)}%)`;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.github/workflows/bundle-stats.yml(1 hunks).github/workflows/ci.yml(2 hunks)rsbuild.config.ts(1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
rsbuild.config.ts (1)
scripts/build.js (1)
fs(5-5)
🪛 actionlint (1.7.4)
.github/workflows/ci.yml
74-74: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
.github/workflows/bundle-stats.yml
21-21: property "compare" is not defined in object type {gist-ops: {conclusion: string; outcome: string; outputs: object}}
(expression)
23-23: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
| - name: Update PR Description | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| const { data: pr } = await github.rest.pulls.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: context.issue.number | ||
| }); | ||
|
|
||
| let body = pr.body || ''; | ||
| const statsMarker = '### Bundle Size'; | ||
| const comparison = '${{ steps.compare.outputs.stats }}'; | ||
|
|
||
| if (body.includes(statsMarker)) { | ||
| body = body.replace( | ||
| new RegExp(`${statsMarker}[^\n]*\n[^\n]*`), | ||
| `${statsMarker}\n${comparison}` | ||
| ); | ||
| } else { | ||
| body += `\n\n${statsMarker}\n${comparison}`; | ||
| } | ||
|
|
||
| await github.rest.pulls.update({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: context.issue.number, | ||
| body | ||
| }); |
There was a problem hiding this comment.
Update GitHub Actions version and improve regex pattern
According to static analysis, the GitHub Actions runner version is outdated. Also, the regex pattern for updating the PR description could be more robust.
- - name: Update PR Description
- uses: actions/github-script@v6
+ uses: actions/github-script@v7- body = body.replace(
- new RegExp(`${statsMarker}[^\n]*\n[^\n]*`),
- `${statsMarker}\n${comparison}`
- );
+ body = body.replace(
+ new RegExp(`${statsMarker}\\s*\\n[^#]*`, 'g'),
+ `${statsMarker}\n${comparison}`
+ );Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 actionlint (1.7.4)
74-74: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
| outputs: | ||
| stats: ${{ steps.compare.outputs.stats }} | ||
| steps: | ||
| - uses: actions/github-script@v6 |
There was a problem hiding this comment.
Update GitHub Actions version
According to static analysis, the GitHub Actions runner version is outdated.
- - uses: actions/github-script@v6
+ - uses: actions/github-script@v7📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - uses: actions/github-script@v6 | |
| - uses: actions/github-script@v7 |
🧰 Tools
🪛 actionlint (1.7.4)
23-23: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
PR Type
Enhancement, Tests
Description
Added a new GitHub workflow for bundle size comparison and storage.
Enhanced single file build validation in
rsbuild.config.ts.Updated CI workflow to include bundle size parsing and comparison.
Automated PR description updates with bundle size stats.
Changes walkthrough 📝
rsbuild.config.ts
Add validation for single file build outputrsbuild.config.ts
index.htmlexists indist/single.ci.yml
Enhance CI workflow with bundle size comparison.github/workflows/ci.yml
bundle-stats.yml
Introduce bundle stats workflow for size comparison.github/workflows/bundle-stats.yml
Summary by CodeRabbit