Skip to content

Commit edf2983

Browse files
Add running time check on ci (#2165)
# Summary - This PR started as an attempt to make CI use the `@size-limit/time` plugin to measure the execution time of each client bundle and ensure it doesn't exceed the base branch execution time by more than 20%. - Later, found that the `@size-limit/time` plugin is not good at all at detecting that because of the runtime noise on CI. - So, CI will only look for the `download time` of chunks at the browser for now, until finding another tool that run the code multiple time on CI and get average execution time to get rid of runtime noise. - However, the following changes are made: - The feature of measring the execution time and comparing it to the base branch is already added to the `bin/compare-bundle-sizes` script, so if you can run it locally with a noise mitigated environment you can do that by changing the `running` values at `.size-limit.json` file to `true`. - Removed the `compare` command from the `scripts/bundle-size.mjs` script as it's not needed and used the default comparison behavior at the `size-limit` package.
1 parent fdb9082 commit edf2983

File tree

7 files changed

+80
-230
lines changed

7 files changed

+80
-230
lines changed

.github/workflows/bundle-size.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
echo "skip=false" >> $GITHUB_OUTPUT
3434
fi
3535
36-
size:
36+
check-bundle-size:
3737
needs: check-skip
3838
if: needs.check-skip.outputs.skip != 'true'
3939
runs-on: ubuntu-22.04
@@ -105,11 +105,14 @@ jobs:
105105
- name: Set dynamic limits (base + 0.5KB)
106106
run: node scripts/bundle-size.mjs set-limits --base /tmp/base-sizes.json
107107

108+
- name: Copy .size-limit.json file with limits to tmp directory
109+
run: cp .size-limit.json /tmp/.size-limit-with-limits.json
110+
108111
# 4. Run the action with dynamic limits
109112
- name: Check bundle size
110113
uses: andresz1/size-limit-action@v1
111114
with:
112115
github_token: ${{ secrets.GITHUB_TOKEN }}
113116
package_manager: pnpm
114-
build_script: build
117+
build_script: build-for-size-limit
115118
skip_step: install

.size-limit.json

Lines changed: 16 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,58 @@
11
[
2-
{
3-
"name": "react-on-rails (raw)",
4-
"path": "packages/react-on-rails/lib/*.js",
5-
"webpack": false,
6-
"gzip": false,
7-
"brotli": false
8-
},
9-
{
10-
"name": "react-on-rails (gzip)",
11-
"path": "packages/react-on-rails/lib/*.js",
12-
"webpack": false,
13-
"gzip": true
14-
},
15-
{
16-
"name": "react-on-rails (brotli)",
17-
"path": "packages/react-on-rails/lib/*.js",
18-
"webpack": false,
19-
"brotli": true
20-
},
21-
{
22-
"name": "react-on-rails-pro (raw)",
23-
"path": "packages/react-on-rails-pro/lib/*.js",
24-
"webpack": false,
25-
"gzip": false,
26-
"brotli": false
27-
},
28-
{
29-
"name": "react-on-rails-pro (gzip)",
30-
"path": "packages/react-on-rails-pro/lib/*.js",
31-
"webpack": false,
32-
"gzip": true
33-
},
34-
{
35-
"name": "react-on-rails-pro (brotli)",
36-
"path": "packages/react-on-rails-pro/lib/*.js",
37-
"webpack": false,
38-
"brotli": true
39-
},
40-
{
41-
"name": "react-on-rails-pro-node-renderer (raw)",
42-
"path": "packages/react-on-rails-pro-node-renderer/lib/*.js",
43-
"webpack": false,
44-
"gzip": false,
45-
"brotli": false
46-
},
47-
{
48-
"name": "react-on-rails-pro-node-renderer (gzip)",
49-
"path": "packages/react-on-rails-pro-node-renderer/lib/*.js",
50-
"webpack": false,
51-
"gzip": true
52-
},
53-
{
54-
"name": "react-on-rails-pro-node-renderer (brotli)",
55-
"path": "packages/react-on-rails-pro-node-renderer/lib/*.js",
56-
"webpack": false,
57-
"brotli": true
58-
},
592
{
603
"name": "react-on-rails/client bundled (gzip)",
614
"path": "packages/react-on-rails/lib/ReactOnRails.client.js",
625
"import": "ReactOnRails",
63-
"gzip": true
6+
"gzip": true,
7+
"running": false
648
},
659
{
6610
"name": "react-on-rails/client bundled (brotli)",
6711
"path": "packages/react-on-rails/lib/ReactOnRails.client.js",
6812
"import": "ReactOnRails",
69-
"brotli": true
13+
"brotli": true,
14+
"running": false
7015
},
7116
{
7217
"name": "react-on-rails-pro/client bundled (gzip)",
7318
"path": "packages/react-on-rails-pro/lib/ReactOnRails.client.js",
7419
"import": "ReactOnRails",
75-
"gzip": true
20+
"gzip": true,
21+
"running": false
7622
},
7723
{
7824
"name": "react-on-rails-pro/client bundled (brotli)",
7925
"path": "packages/react-on-rails-pro/lib/ReactOnRails.client.js",
8026
"import": "ReactOnRails",
81-
"brotli": true
27+
"brotli": true,
28+
"running": false
8229
},
8330
{
8431
"name": "registerServerComponent/client bundled (gzip)",
8532
"path": "packages/react-on-rails-pro/lib/registerServerComponent/client.js",
8633
"import": "registerServerComponent",
87-
"gzip": true
34+
"gzip": true,
35+
"running": false
8836
},
8937
{
9038
"name": "registerServerComponent/client bundled (brotli)",
9139
"path": "packages/react-on-rails-pro/lib/registerServerComponent/client.js",
9240
"import": "registerServerComponent",
93-
"brotli": true
41+
"brotli": true,
42+
"running": false
9443
},
9544
{
9645
"name": "wrapServerComponentRenderer/client bundled (gzip)",
9746
"path": "packages/react-on-rails-pro/lib/wrapServerComponentRenderer/client.js",
9847
"import": "wrapServerComponentRenderer",
99-
"gzip": true
48+
"gzip": true,
49+
"running": false
10050
},
10151
{
10252
"name": "wrapServerComponentRenderer/client bundled (brotli)",
10353
"path": "packages/react-on-rails-pro/lib/wrapServerComponentRenderer/client.js",
10454
"import": "wrapServerComponentRenderer",
105-
"brotli": true
55+
"brotli": true,
56+
"running": false
10657
}
10758
]

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Changes since the last non-beta release.
2525

2626
#### Added
2727

28+
- **Download Time CI Monitoring**: Added automated download time tracking to CI using size-limit. Compares PR client import download times against the base branch and fails if any import increases by more than 10%. And added ability to compare the total execution time (download + running time) to the `bin/compare-bundle-sizes` script. [PR 2160](https://github.com/shakacode/react_on_rails/pull/2160) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
29+
2830
- **Bundle Size CI Monitoring**: Added automated bundle size tracking to CI using size-limit. Compares PR bundle sizes against the base branch and fails if any package increases by more than 0.5KB. Includes local comparison tool (`bin/compare-bundle-sizes`) and bypass mechanism (`bin/skip-bundle-size-check`) for intentional size increases. [PR 2149](https://github.com/shakacode/react_on_rails/pull/2149) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
2931

3032
- **Service Dependency Checking for bin/dev**: Added optional `.dev-services.yml` configuration to validate required external services (Redis, PostgreSQL, Elasticsearch, etc.) are running before `bin/dev` starts the development server. Provides clear error messages with start commands and install hints when services are missing. Zero impact if not configured - backwards compatible with all existing installations. [PR 2098](https://github.com/shakacode/react_on_rails/pull/2098) by [justin808](https://github.com/justin808).

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ This script automatically:
334334
1. Stashes any uncommitted changes
335335
2. Checks out and builds the base branch (default: `master`)
336336
3. Checks out and builds your current branch
337-
4. Compares the sizes and shows a detailed report
337+
4. Compares the size and total execution time (loading + running) and shows a detailed report
338338

339339
Options:
340340

bin/compare-bundle-sizes

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ BLUE='\033[0;34m'
2525
NC='\033[0m' # No Color
2626

2727
cleanup() {
28+
git restore .size-limit.json
2829
echo -e "\n${BLUE}Cleaning up...${NC}"
2930
git checkout "$CURRENT_BRANCH" --quiet 2>/dev/null || true
3031
if [ "$STASHED" = true ]; then
@@ -62,8 +63,8 @@ git checkout "$CURRENT_BRANCH" --quiet
6263
pnpm install --frozen-lockfile 2>&1 | grep -v "^$" | head -5 || true
6364
pnpm run build 2>&1 | grep -v "^$" | tail -3 || true
6465

65-
echo -e "${BLUE}Measuring current branch sizes...${NC}"
66-
pnpm exec size-limit --json > /tmp/current-sizes.json
66+
echo -e "${BLUE}Updating limits of current branch relative to the results of the base branch...${NC}"
67+
node scripts/bundle-size.mjs set-limits --base /tmp/base-sizes.json
6768

68-
# Compare sizes using the bundle-size script
69-
node scripts/bundle-size.mjs compare --base /tmp/base-sizes.json --current /tmp/current-sizes.json
69+
# Run size-limit that will use the dynamic limits created after checking base branch results
70+
pnpm exec size-limit

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"start": "nps",
7777
"nps": "nps",
7878
"build": "pnpm --filter react-on-rails run build && pnpm --filter react-on-rails-pro run build && pnpm --filter react-on-rails-pro-node-renderer run build",
79+
"build-for-size-limit": "cp /tmp/.size-limit-with-limits.json .size-limit.json && pnpm build",
7980
"build-watch": "pnpm -r run build-watch",
8081
"lint": "nps eslint",
8182
"lint:scss": "stylelint \"react_on_rails/spec/dummy/app/assets/stylesheets/**/*.scss\" \"react_on_rails/spec/dummy/client/**/*.scss\"",

0 commit comments

Comments
 (0)