Compare commits

...

4 Commits

Author SHA1 Message Date
snomiao
dce9ead0e6 fix: improve grep pattern robustness and add explicit DISTRIBUTION env
- Use extended regex (-E) with explicit character class for quote matching
- Change gtag patterns to use ['"] instead of . for clarity
- Add DISTRIBUTION=localhost env var to make OSS build intent explicit
- Addresses Copilot review comments #2772985998 and #2772986021

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-09 10:11:07 +00:00
snomiao
97a038f667 fix: make gtag patterns quote-agnostic in tree-shaking check
- Use regex pattern 'gtag(.config' to match both single and double quotes
- Remove unnecessary --exclude='mixpanel.module-*.js' since we're not searching for mixpanel
- Ensures validation catches GTM code regardless of minifier quote normalization

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 06:31:12 +00:00
snomiao
abe497394f fix: improve telemetry tree-shaking validation check
- Add dist/ directory existence check before running validation
- Update grep patterns to focus on GTM/GA code (not Mixpanel)
- Exclude source maps and credit files from search
- Use more specific patterns to avoid false positives (e.g., 'toStringTag')
- Mixpanel uses conditional dynamic imports and is expected in dist

Addresses CodeRabbit review feedback.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 06:31:12 +00:00
snomiao
3110dd9843 feat: add CI check for telemetry tree-shaking validation
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 06:31:12 +00:00

View File

@@ -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
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.'