mirror of
https://github.com/apache/superset.git
synced 2026-08-05 13:32:41 +00:00
Superset's frontend bundle size is a recurring complaint, but until now
there's been no ongoing visibility into it -- only periodic manual cleanup
efforts. This adds a `bundle-size` job to superset-frontend.yml that builds
the real production bundle (npm run build), reduces its per-entrypoint
sizes to a few headline numbers, and tracks them over time via
benchmark-action/github-action-benchmark, posting a PR comment when a
change regresses past 110% of the last recorded baseline.
Reuses the already-built CI Docker image (same image sharded-jest-tests /
lint-frontend / etc. already download), so the only new cost is the
production webpack build itself -- and that's cheap after the first run:
webpack's persistent filesystem cache (already configured in
webpack.config.js) makes warm rebuilds ~20s locally vs several minutes
cold, confirmed by hand against this repo's real build.
webpack.config.js gains a BUNDLE_SIZE_STATS env-gated stats override
(mirrors the existing BUNDLE_ANALYZER pattern). The default `stats:
'minimal'` omits per-asset sizes entirely; `--stats=normal` includes them
but also serializes the full ~15k-module dependency graph, producing a
560+MB stats.json for this app -- large enough to exceed Node's max
string length on a plain fs.readFileSync. The env-gated override requests
just `{ assets: true, entrypoints: true }`, verified end-to-end against a
minimal synthetic webpack project (same webpack/webpack-cli versions) and
against real stats pulled from this repo's actual production build.
History storage deliberately avoids the gh-pages branch (benchmark-action's
usual default) since that branch is the live Helm chart index published by
superset-helm-release.yml, not free real estate. Instead uses
external-data-json-path with actions/cache: restored on every run (PR or
push) so PRs get a same-baseline comparison and regression comment, but
only saved back to the cache on push to master, so an unmerged PR's numbers
never become the shared baseline. No gh-pages branch is touched in any
code path, and no PAT/GitHub App is needed -- comment-on-alert only needs
the default per-job GITHUB_TOKEN.
270 lines
8.8 KiB
YAML
270 lines
8.8 KiB
YAML
name: "Frontend Build CI (unit tests, linting & sanity checks)"
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "master"
|
|
- "[0-9].[0-9]*"
|
|
pull_request:
|
|
types: [synchronize, opened, reopened, ready_for_review]
|
|
|
|
# cancel previous workflow jobs for PRs
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
TAG: apache/superset:GHA-${{ github.run_id }}
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
frontend-build:
|
|
runs-on: ubuntu-26.04
|
|
timeout-minutes: 30
|
|
outputs:
|
|
should-run: ${{ steps.check.outputs.frontend }}
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
fetch-depth: 0
|
|
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
|
|
|
|
- name: Check for File Changes
|
|
id: check
|
|
uses: ./.github/actions/change-detector/
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build Docker Image
|
|
if: steps.check.outputs.frontend
|
|
shell: bash
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
echo "git rev-parse --short HEAD"
|
|
git rev-parse --short HEAD
|
|
echo "git show -s --format=raw HEAD"
|
|
git show -s --format=raw HEAD
|
|
docker buildx build \
|
|
-t $TAG \
|
|
--cache-from=type=registry,ref=apache/superset-cache:3.11-slim-trixie \
|
|
--target superset-node-ci \
|
|
.
|
|
|
|
- name: Save Docker Image as Artifact
|
|
if: steps.check.outputs.frontend
|
|
run: |
|
|
docker save $TAG | zstd -3 --threads=0 > docker-image.tar.zst
|
|
|
|
- name: Upload Docker Image Artifact
|
|
if: steps.check.outputs.frontend
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
|
with:
|
|
name: docker-image
|
|
path: docker-image.tar.zst
|
|
|
|
sharded-jest-tests:
|
|
needs: frontend-build
|
|
if: needs.frontend-build.outputs.should-run == 'true'
|
|
strategy:
|
|
matrix:
|
|
shard: [1, 2, 3, 4, 5, 6, 7, 8]
|
|
fail-fast: false
|
|
runs-on: ubuntu-26.04
|
|
timeout-minutes: 20
|
|
steps:
|
|
- name: Download Docker Image Artifact
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: docker-image
|
|
|
|
- name: Load Docker Image
|
|
run: |
|
|
zstd -d < docker-image.tar.zst | docker load
|
|
|
|
- name: npm run test with coverage
|
|
run: |
|
|
mkdir -p ${{ github.workspace }}/superset-frontend/coverage
|
|
docker run \
|
|
-v ${{ github.workspace }}/superset-frontend/coverage:/app/superset-frontend/coverage \
|
|
--rm $TAG \
|
|
bash -c \
|
|
"npm run test -- --coverage --shard=${{ matrix.shard }}/8 --coverageReporters=json"
|
|
|
|
- name: Upload Coverage Artifact
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
|
with:
|
|
name: coverage-artifacts-${{ matrix.shard }}
|
|
path: superset-frontend/coverage
|
|
|
|
report-coverage:
|
|
needs: [sharded-jest-tests]
|
|
if: needs.frontend-build.outputs.should-run == 'true'
|
|
runs-on: ubuntu-26.04
|
|
timeout-minutes: 15
|
|
permissions:
|
|
id-token: write
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
fetch-depth: 0
|
|
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
|
|
|
|
- name: Download Coverage Artifacts
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
pattern: coverage-artifacts-*
|
|
path: coverage/
|
|
|
|
- name: Upload Code Coverage
|
|
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
|
|
with:
|
|
flags: javascript
|
|
use_oidc: true
|
|
verbose: true
|
|
directory: coverage
|
|
slug: apache/superset
|
|
|
|
lint-frontend:
|
|
needs: frontend-build
|
|
if: needs.frontend-build.outputs.should-run == 'true'
|
|
runs-on: ubuntu-26.04
|
|
timeout-minutes: 20
|
|
steps:
|
|
- name: Download Docker Image Artifact
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: docker-image
|
|
|
|
- name: Load Docker Image
|
|
run: |
|
|
zstd -d < docker-image.tar.zst | docker load
|
|
|
|
- name: lint
|
|
run: |
|
|
docker run --rm $TAG bash -c \
|
|
"npm i && npm run lint"
|
|
|
|
- name: tsc
|
|
run: |
|
|
docker run --rm $TAG bash -c \
|
|
"npm i && npm run plugins:build && npm run type"
|
|
|
|
validate-frontend:
|
|
needs: frontend-build
|
|
if: needs.frontend-build.outputs.should-run == 'true'
|
|
runs-on: ubuntu-26.04
|
|
timeout-minutes: 20
|
|
steps:
|
|
- name: Download Docker Image Artifact
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: docker-image
|
|
|
|
- name: Load Docker Image
|
|
run: |
|
|
zstd -d < docker-image.tar.zst | docker load
|
|
|
|
- name: Build Plugins Packages
|
|
run: |
|
|
docker run --rm $TAG bash -c \
|
|
"npm run plugins:build"
|
|
|
|
test-storybook:
|
|
needs: frontend-build
|
|
if: needs.frontend-build.outputs.should-run == 'true'
|
|
runs-on: ubuntu-26.04
|
|
timeout-minutes: 25
|
|
steps:
|
|
- name: Download Docker Image Artifact
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: docker-image
|
|
|
|
- name: Load Docker Image
|
|
run: |
|
|
zstd -d < docker-image.tar.zst | docker load
|
|
|
|
- name: Build Storybook and Run Tests
|
|
run: |
|
|
docker run --rm $TAG bash -c \
|
|
"npm run build-storybook && npx playwright install-deps && npx playwright install chromium && npm run test-storybook:ci"
|
|
|
|
bundle-size:
|
|
needs: frontend-build
|
|
if: needs.frontend-build.outputs.should-run == 'true'
|
|
runs-on: ubuntu-26.04
|
|
timeout-minutes: 15
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Download Docker Image Artifact
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: docker-image
|
|
|
|
- name: Load Docker Image
|
|
run: |
|
|
zstd -d < docker-image.tar.zst | docker load
|
|
|
|
# Only ever pull the last recorded data point off the cache, keyed by
|
|
# run ID -- `restore-keys` prefix-matches the most recently created
|
|
# entry. Absent on the very first run ever; benchmark-action starts a
|
|
# fresh history in that case.
|
|
- name: Restore bundle size history
|
|
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
with:
|
|
path: bundle-size-history.json
|
|
key: bundle-size-history-${{ github.run_id }}
|
|
restore-keys: |
|
|
bundle-size-history-
|
|
|
|
- name: Build production bundle with stats
|
|
run: |
|
|
mkdir -p ${{ github.workspace }}/superset-frontend/bundle-stats
|
|
docker run \
|
|
-v ${{ github.workspace }}/superset-frontend/bundle-stats:/app/superset-frontend/bundle-stats \
|
|
--rm $TAG \
|
|
bash -c \
|
|
"npm i && BUNDLE_SIZE_STATS=true npm run build -- --json=bundle-stats/stats.json"
|
|
|
|
- name: Summarize bundle size
|
|
run: |
|
|
node superset-frontend/scripts/bundle-size-summary.js \
|
|
superset-frontend/bundle-stats/stats.json > bundle-size-summary.json
|
|
rm -rf superset-frontend/bundle-stats
|
|
|
|
- name: Track bundle size
|
|
uses: benchmark-action/github-action-benchmark@52576c92bccf6ac60c8223ec7eb2565637cae9ba # v1.22.1
|
|
with:
|
|
tool: customSmallerIsBetter
|
|
output-file-path: bundle-size-summary.json
|
|
external-data-json-path: bundle-size-history.json
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
comment-on-alert: true
|
|
alert-threshold: "110%"
|
|
fail-on-alert: false
|
|
summary-always: true
|
|
|
|
# Only the trunk's own bundle size becomes the baseline everyone else
|
|
# is compared against -- an unmerged PR's numbers (including ones that
|
|
# regress on purpose to test something) never get persisted.
|
|
- name: Save bundle size history
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
|
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
with:
|
|
path: bundle-size-history.json
|
|
key: bundle-size-history-${{ github.run_id }}
|