Skip to content

chore: display bundle size table at end of build-all-examples script#1037

Merged
redfish4ktc merged 5 commits intomainfrom
chore/build-examples-script_display_table_size
Apr 1, 2026
Merged

chore: display bundle size table at end of build-all-examples script#1037
redfish4ktc merged 5 commits intomainfrom
chore/build-examples-script_display_table_size

Conversation

@redfish4ktc
Copy link
Copy Markdown

@redfish4ktc redfish4ktc commented Apr 1, 2026

Add --help option, Markdown table and CSV output of bundle sizes for easy copy-paste into PR descriptions and release notes.
The example list is inferred dynamically by detecting which packages produce JS bundles in their dist/ directory.

Summary by CodeRabbit

  • New Features

    • Added a --help option to show script usage.
    • Added bundle-size reporting with a Markdown table and CSV output summarizing current JS bundle sizes per example.
  • Chores

    • Improved argument parsing and error handling for unsupported options.
    • CI updated to trigger builds when the build script changes and made job matrix behavior less prone to cancelling parallel runs.

Add --help option, Markdown table and CSV output of bundle sizes for easy copy-paste into PR descriptions and release notes.
The example list is inferred dynamically by detecting which packages produce JS bundles in their dist/ directory.
@redfish4ktc redfish4ktc added the chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...) label Apr 1, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

Walkthrough

Reworked example build script to add usage/help and robust option parsing, discover built JS examples under packages/js-example* and packages/ts-example*, compute per-example max JS bundle sizes and emit a Markdown table plus CSV; CI workflow path filters updated to include the script and fail-fast: false added to job matrices.

Changes

Cohort / File(s) Summary
Build script enhancements
scripts/build-all-examples.bash
Added usage() and --help handling; replaced ad-hoc flag check with case parsing and [[ ... ]] tests; implemented discovery of packages/js-example* and packages/ts-example* directories containing dist/*.js; aggregated per-example max JS file size (kB, two decimals) into BUNDLE_SIZES; output a Markdown table (Example
CI workflow trigger
.github/workflows/build.yml
Added scripts/build-all-examples.bash to on.push.paths and on.pull_request.paths filters so edits to the script trigger the Build workflow; set fail-fast: false on build matrix jobs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete; it lacks a PR checklist, issue reference, and proper structure from the template. Fill out the PR checklist, reference the issue (closes #xxxx), confirm tests/screenshots are included, and follow the template's Overview section structure.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely describes the main change: adding bundle size table display to the build script output.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (4)
scripts/build-all-examples.bash (4)

8-16: Consider adding an explicit return statement.

SonarCloud flags the missing explicit return. While echo returns 0 on success, adding return 0 improves clarity.

Proposed fix
 usage() {
   echo "Usage: $0 [OPTIONS]"
   echo
   echo "Build all examples and display bundle sizes."
   echo
   echo "Options:"
   echo "  --list-size-only  Skip building, only display bundle sizes from existing dist/ directories"
   echo "  --help            Show this help message"
+  return 0
 }

46-52: Use [[ instead of [ for conditional tests.

SonarCloud flags this at line 49. The [[ construct is safer (handles word splitting and glob expansion automatically) and more feature-rich in bash.

Proposed fix
 # Infer examples that produce JS bundles (frontend applications only)
 EXAMPLES_FOR_TABLE=()
 for dir in packages/js-example* packages/ts-example*; do
-  if [ -d "$dir/dist" ] && find "$dir/dist" -name "*.js" -type f -print -quit | grep -q .; then
+  if [[ -d "$dir/dist" ]] && find "$dir/dist" -name "*.js" -type f -print -quit | grep -q .; then
     EXAMPLES_FOR_TABLE+=("$(basename "$dir")")
   fi
 done

75-85: Use [[ instead of [ for conditional tests.

SonarCloud flags this at line 79. Apply the same fix as suggested for line 49.

Proposed fix
 # Collect bundle sizes (largest JS file per example = the one containing maxGraph)
 declare -A BUNDLE_SIZES
 for example in "${EXAMPLES_FOR_TABLE[@]}"; do
   dir="packages/$example"
-  if [ -d "$dir/dist" ]; then
+  if [[ -d "$dir/dist" ]]; then
     BUNDLE_SIZES[$example]=$(find "$dir/dist" -name "*.js" -type f -exec ls -l {} \; | LC_NUMERIC=C awk '
       { if ($5 > max) max = $5 }
       END { printf "%.2f", max / 1000 }
     ')
   fi
 done

87-102: Use [[ instead of [ for conditional tests.

SonarCloud flags this at line 97. Apply the same fix for consistency.

Proposed fix
 for example in "${EXAMPLES_FOR_TABLE[@]}"; do
   size="${BUNDLE_SIZES[$example]:-}"
-  if [ -n "$size" ]; then
+  if [[ -n "$size" ]]; then
     echo "| $example | kB | $size kB |"
   else
     echo "| $example | kB | N/A |"
   fi
 done

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 289df1c6-d12a-4775-a10f-0fba52fd8f26

📥 Commits

Reviewing files that changed from the base of the PR and between 50cb652 and d950b15.

📒 Files selected for processing (1)
  • scripts/build-all-examples.bash

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 1, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/build-all-examples.bash (1)

33-40: ⚠️ Potential issue | 🟠 Major

Build loop exits on first failure, preventing the final size table from being printed.

With set -euo pipefail, a failing npm run build aborts the script immediately, skipping all subsequent output (lines 47–122), including the Markdown table and CSV summary that are core to the script's stated purpose.

Capture build failures and continue processing to ensure the end-of-run output is always produced:

Proposed fix
+BUILD_FAILED=false
 for dir in packages/ts-example* packages/js-example*; do
   if [[ -d "$dir" ]]; then
     echo
     echo "##################################################"
     echo "Building $dir"
     echo "##################################################"
-      (cd "$dir" && npm run build)
+      if ! (cd "$dir" && npm run build); then
+        echo "Build failed for $dir; continuing with next example." >&2
+        BUILD_FAILED=true
+      fi
    fi
  done

-  echo "All examples built successfully."
+  if [[ "$BUILD_FAILED" = true ]]; then
+    echo "One or more example builds failed." >&2
+  else
+    echo "All examples built successfully."
+  fi
 fi
 
 # Infer examples that produce JS bundles (frontend applications only)
@@ -120,3 +130,7 @@ for i in "${!EXAMPLES_FOR_TABLE[@]}"; do
 done
 echo "$csv_header"
 echo "$csv_values"
+
+if [[ "${BUILD_FAILED:-false}" = true ]]; then
+  exit 1
+fi

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 248a4237-33f8-442f-b002-cc8c42a84768

📥 Commits

Reviewing files that changed from the base of the PR and between 82d20de and 3da58dd.

📒 Files selected for processing (2)
  • .github/workflows/build.yml
  • scripts/build-all-examples.bash
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/build.yml

@redfish4ktc redfish4ktc merged commit 9f8381b into main Apr 1, 2026
12 checks passed
@redfish4ktc redfish4ktc deleted the chore/build-examples-script_display_table_size branch April 1, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants