-
Notifications
You must be signed in to change notification settings - Fork 673
Add CI check for telemetry tree-shaking validation #8623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3110dd9
abe4973
97a038f
dce9ead
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| name: 'CI: Telemetry Tree-Shaking Validation' | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches-ignore: [wip/*, draft/*, temp/*] | ||
| push: | ||
| branches: [main, dev*] | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| validate-tree-shaking: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Setup frontend | ||
| uses: ./.github/actions/setup-frontend | ||
| - name: Build project | ||
| run: pnpm build | ||
| env: | ||
| DISTRIBUTION: localhost | ||
| - name: Check for telemetry code in dist | ||
| run: | | ||
| # Check for GTM/GA code that should NOT appear in dist | ||
| # Note: Mixpanel uses conditional dynamic imports and is expected in dist as a lazy chunk | ||
| FOUND_VIOLATIONS=0 | ||
|
|
||
| echo '🔍 Checking dist for telemetry code that should be tree-shaken...' | ||
| echo '' | ||
|
|
||
| # Verify dist/ directory exists and is not empty | ||
| if [ ! -d "dist" ]; then | ||
| echo "❌ ERROR: dist/ directory does not exist!" | ||
| echo "Build may have failed or produced no output." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -z "$(ls -A dist)" ]; then | ||
| echo "❌ ERROR: dist/ directory is empty!" | ||
| echo "Build may have failed or produced no output." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check for Google Tag Manager / Google Analytics | ||
| echo "Checking for GTM/GA code..." | ||
| # Exclude source maps and credit files | ||
| # Use extended regex (-E) for explicit pattern matching | ||
| if grep -rEi --exclude='*.map' --exclude='CREDIT.txt' \ | ||
| -e 'googletagmanager' \ | ||
| -e 'gtm\.js' \ | ||
| -e 'analytics\.js' \ | ||
| -e "gtag\(['\"]config" \ | ||
| -e "gtag\(['\"]event" \ | ||
| dist/; then | ||
| echo "❌ ERROR: Found GTM/GA code in dist files!" | ||
| echo "Google Tag Manager / Google Analytics must be properly tree-shaken from OSS builds." | ||
| FOUND_VIOLATIONS=1 | ||
| else | ||
| echo "✓ No GTM/GA code found" | ||
| fi | ||
|
Comment on lines
+46
to
+62
|
||
|
|
||
| if [ $FOUND_VIOLATIONS -eq 1 ]; then | ||
| echo '' | ||
| echo '============================================' | ||
| echo '❌ Telemetry tree-shaking validation FAILED' | ||
| echo '============================================' | ||
| echo '' | ||
| echo 'GTM/GA telemetry code was found in the compiled dist.' | ||
| echo 'This code must be properly tree-shaken from OSS builds.' | ||
| echo '' | ||
| echo 'To fix this:' | ||
| echo '1. Use the TelemetryProvider pattern (see src/platform/telemetry/)' | ||
| echo '2. Call telemetry via useTelemetry() hook' | ||
| echo '3. Avoid top-level imports of GTM/GA libraries' | ||
| echo '4. Use conditional dynamic imports behind isCloud checks' | ||
| echo '' | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo '' | ||
| echo '✅ Telemetry tree-shaking validation passed!' | ||
| echo 'No GTM/GA telemetry code found in dist files.' | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow doesn't explicitly set the DISTRIBUTION environment variable during the build step. While the vite.config.mts defaults to 'localhost' when DISTRIBUTION is unset (which is correct for OSS builds), it's safer to be explicit to prevent future issues or changes to default behavior.
Consider adding an explicit environment variable:
This makes the intent clear and ensures the test validates the correct build configuration.