Skip to content

Commit bd9a770

Browse files
authored
[ci]: Add workflow to guard against growing bundle size (jaegertracing#2586)
## Which problem is this PR solving? - fixes jaegertracing#2581 ## Description of the changes This GH Workflow would go through the following steps: 1. Calculate the actual bundle size by using `build` directory generated when we run `npm run build` 2. Save that size to a `new_bundle_size.txt` file 3. Now fetch the `bundle_size.txt` file from cache, if present. 4. If cache hits, compare the `bundle_size.txt` (contains old size) with the `new_bundle_size.txt` (contains new size). 5. If its more than 2%, fail the CI 6. Else pass it. 7. If cache miss, save the `bundle_size.txt` to cache 8. Finally, if everything's alright, save the current bundle size file to cache. (but only on pushes to main branch) ## How was this change tested? - Example run: https://github.com/hari45678/jaeger-ui/actions/runs/12724047648/job/35469797958#step:8:27 ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Hariom Gupta <[email protected]>
1 parent 43d832b commit bd9a770

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

Diff for: .github/workflows/check_bundle.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Bundle Size Check
2+
on:
3+
pull_request:
4+
branches: [main]
5+
6+
push:
7+
branches: [main]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build-and-check:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
18+
- name: Setup Node.js
19+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
20+
with:
21+
node-version-file: '.nvmrc'
22+
cache: 'npm'
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Build
28+
run: npm run build
29+
30+
- name: Calculate bundle size
31+
run: |
32+
TOTAL_SIZE=$(du -sb packages/jaeger-ui/build | cut -f1)
33+
echo "$TOTAL_SIZE" > new_bundle_size.txt
34+
echo "Total bundle size: $TOTAL_SIZE bytes"
35+
36+
- name: Restore previous bundle size
37+
id: cache-bundle-size
38+
uses: actions/cache/restore@v4
39+
with:
40+
path: bundle_size.txt
41+
key: jaeger-ui-bundle-size
42+
43+
- name: Compare bundle sizes
44+
if: steps.cache-bundle-size.outputs.cache-hit == 'true'
45+
run: |
46+
OLD_BUNDLE_SIZE=$(cat bundle_size.txt)
47+
NEW_BUNDLE_SIZE=$(cat new_bundle_size.txt)
48+
echo "Previous bundle size: $OLD_BUNDLE_SIZE bytes"
49+
echo "New bundle size: $NEW_BUNDLE_SIZE bytes"
50+
51+
SIZE_CHANGE=$(( $NEW_BUNDLE_SIZE - $OLD_BUNDLE_SIZE ))
52+
PERCENTAGE_CHANGE=$(( SIZE_CHANGE * 100 / $OLD_BUNDLE_SIZE ))
53+
echo "Size change: $PERCENTAGE_CHANGE%"
54+
if [ $PERCENTAGE_CHANGE -gt 2 ]; then
55+
echo "❌ Bundle size increased by more than 2% ($PERCENTAGE_CHANGE%)"
56+
exit 1
57+
else
58+
echo "✅ Bundle size change is within acceptable range ($PERCENTAGE_CHANGE%)"
59+
fi
60+
61+
- name: Update bundle size file
62+
run: mv new_bundle_size.txt bundle_size.txt
63+
64+
- name: Save new bundle size
65+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
66+
uses: actions/cache/save@v4
67+
with:
68+
path: bundle_size.txt
69+
key: jaeger-ui-bundle-size

0 commit comments

Comments
 (0)