Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .github/workflows/ci-telemetry-tree-shaking.yaml
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

Copilot AI Feb 6, 2026

Copy link

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:

- name: Build project
  run: pnpm build
  env:
    DISTRIBUTION: localhost

This makes the intent clear and ensures the test validates the correct build configuration.

Suggested change
run: pnpm build
run: pnpm build
env:
DISTRIBUTION: localhost

Copilot uses AI. Check for mistakes.
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

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow only checks for GTM/GA telemetry code but doesn't verify that Mixpanel code is properly lazy-loaded as expected. While the comment on line 25 mentions Mixpanel is expected in dist as a lazy chunk, the workflow doesn't validate this expectation.

Consider adding a check to ensure Mixpanel appears only as a dynamic import and not as a top-level import. This could prevent regressions where Mixpanel might be accidentally bundled instead of lazy-loaded:

For example, check that 'mixpanel-browser' appears only in specific lazy-loaded chunk patterns and not in main bundles.

Copilot uses AI. Check for mistakes.

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