Skip to content
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

feat: lock plugins and integrations version by default #1956

Draft
wants to merge 15 commits into
base: hotfix/lock-components
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
155 changes: 77 additions & 78 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ env:
NODE_OPTIONS: "--no-warnings"
CACHE_CONTROL_NO_STORE: "\"no-store\""
CACHE_CONTROL_MAX_AGE: "\"max-age=3600\""
INTEGRATIONS_ZIP_FILE: "all_integration_sdks.tar.gz"
PLUGINS_ZIP_FILE: "all_plugins.tar.gz"
INTEGRATIONS_ARTIFACTS_BASE_PATH: "packages/analytics-js-integrations/dist/cdn"
PLUGINS_ARTIFACTS_BASE_PATH: "packages/analytics-js-plugins/dist/cdn"
CORE_ARTIFACTS_BASE_PATH: "packages/analytics-js/dist/cdn"
INTEGRATIONS_HTML_FILE: "list.html"
PLUGINS_HTML_FILE: "list.html"

jobs:
deploy:
Expand Down Expand Up @@ -103,17 +110,35 @@ jobs:
REMOTE_MODULES_BASE_PATH: 'https://cdn.rudderlabs.com/${{ inputs.s3_dir_path }}/modern/plugins'
BUGSNAG_API_KEY: ${{ secrets.BUGSNAG_API_KEY }}
BUGSNAG_RELEASE_STAGE: ${{ inputs.bugsnag_release_stage }}
LOCK_DEPS_VERSION: ${{ inputs.environment == 'production' && 'true' || 'false' }}
run: |
npm run setup:ci

- name: Build artifacts
env:
BUGSNAG_API_KEY: ${{ secrets.BUGSNAG_API_KEY }}
BUGSNAG_RELEASE_STAGE: ${{ inputs.bugsnag_release_stage }}
LOCK_DEPS_VERSION: ${{ inputs.environment == 'production' && 'true' || 'false' }}
run: |
npm run build:browser
npm run build:browser:modern

- name: Generate zip files for integrations and plugins
run: |
# Generate a zip file of all the integrations
tmp_file="/tmp/legacy_${{ env.INTEGRATIONS_ZIP_FILE }}"
tar -czvf "$tmp_file" -C "${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/legacy/js-integrations/" .
mv "$tmp_file" "${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/legacy/js-integrations/${{ env.INTEGRATIONS_ZIP_FILE }}"

tmp_file="/tmp/modern_${{ env.INTEGRATIONS_ZIP_FILE }}"
tar -czvf "$tmp_file" -C "${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/modern/js-integrations/" .
mv "$tmp_file" "${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/modern/js-integrations/${{ env.INTEGRATIONS_ZIP_FILE }}"

# Generate a zip file of all the plugins
tmp_file="/tmp/${{ env.PLUGINS_ZIP_FILE }}"
tar -czvf "$tmp_file" -C ${{ env.PLUGINS_ARTIFACTS_BASE_PATH }}/modern/plugins/ .
mv "$tmp_file" "${{ env.PLUGINS_ARTIFACTS_BASE_PATH }}/modern/plugins/${{ env.PLUGINS_ZIP_FILE }}"

- name: Copy assets to S3
if: ${{ inputs.environment == 'production' }}
run: |
Expand All @@ -135,106 +160,81 @@ jobs:
echo "CACHE_CONTROL=${{ env.CACHE_CONTROL_MAX_AGE }}" >> $GITHUB_ENV
fi

- name: Copy SDK artifacts to S3
# IMPORTANT: We're deliberately copying the artifacts to versioned directory ahead of
# of the common production paths to avoid any downtime in production
- name: Copy SDK plugins and integrations artifacts to S3 (versioned directory)
if: ${{ inputs.environment == 'production' }}
run: |
core_sdk_path_prefix="packages/analytics-js/dist/cdn"
integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn"
plugins_path_prefix="packages/analytics-js-plugins/dist/cdn"
s3_relative_path_prefix="${{ inputs.s3_dir_path }}"
s3_relative_path_prefix="${{ env.CURRENT_VERSION_VALUE }}"
s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/$s3_relative_path_prefix"
copy_recursive_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}"
copy_args="--cache-control ${{ env.CACHE_CONTROL }}"

integration_sdks_zip_file="all_integration_sdks.tar.gz"
plugins_zip_file="all_plugins.tar.gz"

integration_sdks_html_file="list.html"
plugins_html_file="list.html"

# Generate a zip file of all the integrations
tmp_file="/tmp/legacy_$integration_sdks_zip_file"
tar -czvf "$tmp_file" -C "$integration_sdks_path_prefix/legacy/js-integrations/" .
mv "$tmp_file" "$integration_sdks_path_prefix/legacy/js-integrations/$integration_sdks_zip_file"

tmp_file="/tmp/modern_$integration_sdks_zip_file"
tar -czvf "$tmp_file" -C "$integration_sdks_path_prefix/modern/js-integrations/" .
mv "$tmp_file" "$integration_sdks_path_prefix/modern/js-integrations/$integration_sdks_zip_file"

# Generate a zip file of all the plugins
tmp_file="/tmp/$plugins_zip_file"
tar -czvf "$tmp_file" -C $plugins_path_prefix/modern/plugins/ .
mv "$tmp_file" "$plugins_path_prefix/modern/plugins/$plugins_zip_file"

# Upload all the files to S3
aws s3 cp $core_sdk_path_prefix/legacy/iife/ $s3_path_prefix/legacy/ $copy_recursive_args
aws s3 cp $core_sdk_path_prefix/modern/iife/ $s3_path_prefix/modern/ $copy_recursive_args

aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_recursive_args
aws s3 cp $plugins_path_prefix/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_recursive_args
aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_recursive_args
copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL_MAX_AGE }}"

# Generate the HTML file to list all the integrations
./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/legacy/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/legacy/js-integrations "Device Mode Integrations (Legacy)" $integration_sdks_zip_file
./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/legacy/js-integrations ${{ env.INTEGRATIONS_HTML_FILE }} ${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/legacy/js-integrations "Device Mode Integrations (Legacy)" ${{ env.INTEGRATIONS_ZIP_FILE }}

./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/modern/js-integrations "Device Mode Integrations (Modern)" $integration_sdks_zip_file
./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/js-integrations ${{ env.INTEGRATIONS_HTML_FILE }} ${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/modern/js-integrations "Device Mode Integrations (Modern)" ${{ env.INTEGRATIONS_ZIP_FILE }}

# Generate the HTML file to list all the plugins
./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/plugins $plugins_html_file $plugins_path_prefix/modern/plugins "Plugins" $plugins_zip_file

# Copy the HTML files to S3
aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/$integration_sdks_html_file $s3_path_prefix/legacy/js-integrations/$integration_sdks_html_file $copy_args
aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/$integration_sdks_html_file $s3_path_prefix/modern/js-integrations/$integration_sdks_html_file $copy_args
aws s3 cp $plugins_path_prefix/modern/plugins/$plugins_html_file $s3_path_prefix/modern/plugins/$plugins_html_file $copy_args

- name: Invalidate CloudFront cache for all the SDK artifacts
run: |
invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ inputs.s3_dir_path }}/*" --query "Invalidation.Id" --output text)
./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/plugins ${{ env.PLUGINS_HTML_FILE }} ${{ env.PLUGINS_ARTIFACTS_BASE_PATH }}/modern/plugins "Plugins" ${{ env.PLUGINS_ZIP_FILE }}

aws cloudfront wait invalidation-completed --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --id "$invalidation_id"
# Copy all the files to S3
aws s3 cp ${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_args
aws s3 cp ${{ env.PLUGINS_ARTIFACTS_BASE_PATH }}/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_args
aws s3 cp ${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args

- name: Copy SDK artifacts to S3 (versioned directory)
- name: Copy SDK core artifacts to S3 (versioned directory)
if: ${{ inputs.environment == 'production' }}
run: |
core_sdk_path_prefix="packages/analytics-js/dist/cdn"
integration_sdks_path_prefix="packages/analytics-js-integrations/dist/cdn"
plugins_path_prefix="packages/analytics-js-plugins/dist/cdn"
s3_relative_path_prefix="${{ env.CURRENT_VERSION_VALUE }}"
s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/$s3_relative_path_prefix"
copy_recursive_args="--recursive --cache-control ${{ env.CACHE_CONTROL_MAX_AGE }}"
copy_args="--cache-control ${{ env.CACHE_CONTROL_MAX_AGE }}"

integration_sdks_zip_file="all_integration_sdks.tar.gz"
plugins_zip_file="all_plugins.tar.gz"

integration_sdks_html_file="list.html"
plugins_html_file="list.html"
copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL_MAX_AGE }}"

# Copy all the files to S3
aws s3 cp $core_sdk_path_prefix/legacy/iife/ $s3_path_prefix/legacy/ $copy_recursive_args
aws s3 cp $core_sdk_path_prefix/modern/iife/ $s3_path_prefix/modern/ $copy_recursive_args
aws s3 cp ${{ env.CORE_ARTIFACTS_BASE_PATH }}/legacy/iife/ $s3_path_prefix/legacy/ $copy_args
aws s3 cp ${{ env.CORE_ARTIFACTS_BASE_PATH }}/modern/iife/ $s3_path_prefix/modern/ $copy_args

- name: Invalidate CloudFront cache for all the SDK artifacts (versioned directory)
if: ${{ inputs.environment == 'production' }}
run: |
invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ env.CURRENT_VERSION_VALUE }}/*" --query "Invalidation.Id" --output text)

aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_recursive_args
aws s3 cp $plugins_path_prefix/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_recursive_args
aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_recursive_args
aws cloudfront wait invalidation-completed --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --id "$invalidation_id"

- name: Copy SDK plugins and integrations artifacts to S3
# IMPORTANT: We're deliberately avoid copying latest artifacts to the common production paths
if: ${{ inputs.environment != 'production' }}
run: |
s3_relative_path_prefix="${{ inputs.s3_dir_path }}"
s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/$s3_relative_path_prefix"
copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}"

# Generate the HTML file to list all the integrations
./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/legacy/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/legacy/js-integrations "Device Mode Integrations (Legacy)" $integration_sdks_zip_file
./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/legacy/js-integrations ${{ env.INTEGRATIONS_HTML_FILE }} ${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/legacy/js-integrations "Device Mode Integrations (Legacy)" ${{ env.INTEGRATIONS_ZIP_FILE }}

./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/js-integrations $integration_sdks_html_file $integration_sdks_path_prefix/modern/js-integrations "Device Mode Integrations (Modern)" $integration_sdks_zip_file
./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/js-integrations ${{ env.INTEGRATIONS_HTML_FILE }} ${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/modern/js-integrations "Device Mode Integrations (Modern)" ${{ env.INTEGRATIONS_ZIP_FILE }}

# Generate the HTML file to list all the plugins
./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/plugins $plugins_html_file $plugins_path_prefix/modern/plugins "Plugins" $plugins_zip_file

# Copy all the HTML files to S3
aws s3 cp $integration_sdks_path_prefix/legacy/js-integrations/$integration_sdks_html_file $s3_path_prefix/legacy/js-integrations/$integration_sdks_html_file $copy_args
aws s3 cp $integration_sdks_path_prefix/modern/js-integrations/$integration_sdks_html_file $s3_path_prefix/modern/js-integrations/$integration_sdks_html_file $copy_args
aws s3 cp $plugins_path_prefix/modern/plugins/$plugins_html_file $s3_path_prefix/modern/plugins/$plugins_html_file $copy_args
./scripts/list-sdk-components.sh ${{ secrets.AWS_S3_BUCKET_NAME }} $s3_relative_path_prefix/modern/plugins ${{ env.PLUGINS_HTML_FILE }} ${{ env.PLUGINS_ARTIFACTS_BASE_PATH }}/modern/plugins "Plugins" ${{ env.PLUGINS_ZIP_FILE }}

- name: Invalidate CloudFront cache for all the SDK artifacts (versioned directory)
if: ${{ inputs.environment == 'production' }}
# Copy all the files to S3
aws s3 cp ${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/legacy/js-integrations/ $s3_path_prefix/legacy/js-integrations/ $copy_args
aws s3 cp ${{ env.PLUGINS_ARTIFACTS_BASE_PATH }}/modern/plugins/ $s3_path_prefix/modern/plugins/ $copy_args
aws s3 cp ${{ env.INTEGRATIONS_ARTIFACTS_BASE_PATH }}/modern/js-integrations/ $s3_path_prefix/modern/js-integrations/ $copy_args

- name: Copy SDK core artifacts to S3
run: |
invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ env.CURRENT_VERSION_VALUE }}/*" --query "Invalidation.Id" --output text)
s3_relative_path_prefix="${{ inputs.s3_dir_path }}"
s3_path_prefix="s3://${{ secrets.AWS_S3_BUCKET_NAME }}/$s3_relative_path_prefix"
copy_args="--recursive --cache-control ${{ env.CACHE_CONTROL }}"

# Copy all the files to S3
aws s3 cp ${{ env.CORE_ARTIFACTS_BASE_PATH }}/legacy/iife/ $s3_path_prefix/legacy/ $copy_args
aws s3 cp ${{ env.CORE_ARTIFACTS_BASE_PATH }}/modern/iife/ $s3_path_prefix/modern/ $copy_args

- name: Invalidate CloudFront cache for all the SDK artifacts
run: |
invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ inputs.s3_dir_path }}/*" --query "Invalidation.Id" --output text)

aws cloudfront wait invalidation-completed --distribution-id ${{ secrets.AWS_CF_DISTRIBUTION_ID }} --id "$invalidation_id"

- name: Send message to Slack channel
Expand Down Expand Up @@ -279,8 +279,7 @@ jobs:
]
}

# Below steps are for v1.1 SDK (legacy)

# All the below steps are for v1.1 SDK (legacy)
- name: Copy legacy SDK artifacts to S3
run: |
core_sdk_path_prefix="packages/analytics-v1.1/dist/cdn"
Expand Down
1 change: 1 addition & 0 deletions jest/jest.setup-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ global.window.document.body.innerHTML = documentHTML;
global.window.innerWidth = 1680;
global.window.innerHeight = 1024;
global.window.__BUNDLE_ALL_PLUGINS__ = false;
global.window.__LOCK_DEPS_VERSION__ = false;
global.window.__IS_LEGACY_BUILD__ = false;
global.window.__IS_DYNAMIC_CUSTOM_BUNDLE__ = false;
global.PromiseRejectionEvent = function (reason) {
Expand Down
10 changes: 8 additions & 2 deletions packages/analytics-js-common/src/types/LoadOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,14 @@ export type LoadOptions = {
anonymousIdOptions?: AnonymousIdOptions;
setCookieDomain?: string; // defaults to current domain.
sameSiteCookie?: CookieSameSite; // defaults to Lax.
lockIntegrationsVersion?: boolean; // defaults to false.
lockPluginsVersion?: boolean; // defaults to false.
/**
* @deprecated Integrations version are locked by default. We do not recommend using this option.
*/
lockIntegrationsVersion?: boolean; // defaults to true.
/**
* @deprecated Plugins version are locked by default. We do not recommend using this option.
*/
lockPluginsVersion?: boolean; // defaults to true.
polyfillIfRequired?: boolean; // defaults to true. Controls whether the SDK should polyfill unsupported browser API's if they are detected as missing
onLoaded?: OnLoadedCallback;
uaChTrackLevel?: UaChTrackLevel;
Expand Down
3 changes: 2 additions & 1 deletion packages/analytics-js/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Variables required for the example
WRITE_KEY=
DATAPLANE_URL=
TEST_FILE_PATH=

# Optional variables
CONFIG_SERVER_HOST=
DEST_SDK_BASE_URL=
REMOTE_MODULES_BASE_PATH=
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics-js/.size-limit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default [
name: 'Core (Bundled) - Legacy - NPM (CJS)',
path: 'dist/npm/legacy/bundled/cjs/index.cjs',
import: '*',
limit: '49.1 KiB',
limit: '49.5 KiB',
},
{
name: 'Core (Bundled) - Legacy - NPM (UMD)',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/deprecation */
import { effect, signal } from '@preact/signals-core';
import { http, HttpResponse } from 'msw';
import { defaultHttpClient } from '../../../src/services/HttpClient';
Expand All @@ -8,7 +9,7 @@ import { state, resetState } from '../../../src/state';
import { getSDKUrl } from '../../../src/components/configManager/util/commonUtil';
import { server } from '../../../__fixtures__/msw.server';
import { dummySourceConfigResponse } from '../../../__fixtures__/fixtures';
import {
import type {
ConfigResponseDestinationItem,
SourceConfigResponse,
} from '../../../src/components/configManager/types';
Expand Down
Loading
Loading