|
| 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