Skip to content

Commit 8f900f4

Browse files
saikumarrsCopilot
andauthored
feat(analytics-js): create lite named export (#2745)
* feat(analytics-js): add cloud-only build configurations and update size limits - Introduced new size limits for various cloud-only builds (Legacy and Modern) in `.size-limit.mjs`. - Updated `package.json` to include new entry points for cloud-only builds, specifying types and default exports. - Modified `rollup.config.mjs` to handle cloud-only builds, including exclusion of device mode plugins and adjusting output paths accordingly. * chore: rename to lite * fix(analytics-js): update size limits and adjust plugin bundling logic - Reduced size limits for various Core (Lite) builds in `.size-limit.mjs` to improve performance. - Modified `rollup.config.mjs` to refine the logic for bundling plugins based on build type. * feat(analytics-js): add variant field to event context and optimize lite builds Adds a variant field to context.library that identifies which npm package export or CDN build variant is being used. Variant values for NPM builds: modern, legacy, lite, bundled, content-script, and legacy variants of each. For CDN builds, uses window.rudderAnalyticsBuildType runtime value. Lite Build Optimizations: - Excludes 7 plugins to reduce bundle size by ~10 KB (24% legacy, 22% modern) - Excluded: DeviceModeDestinations, DeviceModeTransformation, NativeDestinationQueue, BeaconQueue, GoogleLinker, StorageEncryptionLegacy, StorageMigrator - Final sizes: Legacy 38 KB, Modern 33 KB (vs Bundled: 50 KB / 42 KB) - GoogleLinker excluded from default plugins list in lite builds - Storage migration disabled by default in lite builds * chore: fix build flags * chore: restore const * chore: add unit tests * chore: clean up * chore: update example app * chore: fix lock file * chore: update packages/analytics-js/__tests__/state/slices/context.test.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: update packages/analytics-js/rollup.config.mjs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: add force deploy confirmation and validate PR status in deployment workflow - Introduced `force_deploy_confirmation` input to allow bypassing all PR checks during deployment. - Added a new job to check for force deploy mode and validate PR status, ensuring that deployments only proceed if PRs are ready for merging unless forced. - Enhanced logging for better visibility during the deployment process. * chore: update deployment workflow to include force deploy mode check - Modified the condition for the 'get-deploy-inputs' job to allow deployment when 'force_deploy_mode' is true, in addition to validating PR status. - This change enhances the flexibility of the deployment process by enabling forced deployments under specific conditions. * chore: refine deployment workflow conditions and add debug logging - Updated the condition for the 'get-deploy-inputs' job to allow deployment when the validation result is 'skipped', in addition to 'success'. - Added a debug step to log the results of the 'find-pr' and 'validate-pr' jobs for improved visibility during the deployment process. * chore: streamline deployment conditions in workflow - Removed debug logging from the deployment workflow to simplify the process. - Updated conditions for deployment jobs to ensure they only run if 'get-deploy-inputs' is successful, enhancing reliability in the deployment process. * chore: enhance deployment workflow with force deploy mode handling - Removed conditional checks for PR validation and deployment jobs to streamline the process. - Added logic to skip PR validation checks when force deploy mode is enabled, improving deployment flexibility. - Updated deployment conditions to focus on essential checks, ensuring a more efficient workflow. * chore: hardcode package publish --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 2001172 commit 8f900f4

26 files changed

Lines changed: 1101 additions & 435 deletions

File tree

.github/workflows/deploy-beta.yml

Lines changed: 128 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ on:
77
description: "Deploy to NPM"
88
type: boolean
99
default: false
10+
force_deploy_confirmation:
11+
description: "Force deploy (bypass ALL PR checks). Type 'FORCE_DEPLOY' to confirm"
12+
type: string
13+
default: ""
14+
required: false
1015

1116
concurrency:
1217
group: ${{ github.workflow }}-${{ github.ref }}
@@ -30,15 +35,14 @@ jobs:
3035
secrets:
3136
PAT: ${{ secrets.PAT }}
3237

33-
get-deploy-inputs:
34-
name: Get Deploy Inputs
38+
find-pr:
39+
name: Find PR for Current Branch
3540
needs: validate-actor
3641
runs-on: [self-hosted, Linux, X64]
3742
outputs:
38-
version_suffix: ${{ steps.deploy-inputs.outputs.version_suffix }}
39-
beta_identifier: ${{ steps.deploy-inputs.outputs.beta_identifier }}
40-
beta_identifier_for_automation_tests: ${{ steps.deploy-inputs.outputs.beta_identifier_for_automation_tests }}
41-
trigger_source: ${{ format('Triggered via PR <{0}|#{1}> by <{2}|{3}>', steps.pr-info.outputs.pr_url, steps.pr-info.outputs.pr_number, format('{0}/{1}', github.server_url, github.actor), github.actor) }}
43+
pr_number: ${{ steps.pr-info.outputs.pr_number }}
44+
pr_url: ${{ steps.pr-info.outputs.pr_url }}
45+
force_deploy_mode: ${{ steps.check-force-deploy.outputs.force_deploy_mode }}
4246
steps:
4347
- name: Harden the runner (Audit all outbound calls)
4448
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
@@ -50,76 +54,145 @@ jobs:
5054
with:
5155
fetch-depth: 0
5256

57+
- name: Check force deploy mode
58+
id: check-force-deploy
59+
run: |
60+
if [ "${{ inputs.force_deploy_confirmation }}" = "FORCE_DEPLOY" ]; then
61+
echo "force_deploy_mode=true" >> $GITHUB_OUTPUT
62+
echo "⚠️ FORCE DEPLOY MODE ENABLED - All PR validation checks will be skipped"
63+
else
64+
echo "force_deploy_mode=false" >> $GITHUB_OUTPUT
65+
fi
66+
5367
- name: Find PR for current branch
5468
id: pr-info
5569
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
5670
with:
5771
script: |
5872
const branch = context.ref.replace('refs/heads/', '');
5973
console.log(`Finding PRs for branch: ${branch}`);
60-
74+
6175
const { data: pullRequests } = await github.rest.pulls.list({
6276
owner: context.repo.owner,
6377
repo: context.repo.repo,
6478
head: `${context.repo.owner}:${branch}`,
6579
base: 'develop',
6680
state: 'open'
6781
});
68-
82+
6983
if (pullRequests.length > 0) {
7084
const pr = pullRequests[0];
7185
const prNumber = pr.number.toString();
7286
const prUrl = pr.html_url;
73-
console.log(`Found PR #${prNumber} for branch ${branch}: https://github.com/${context.repo.owner}/${context.repo.repo}/pull/${prNumber}`);
74-
75-
// Check if PR is in draft state
76-
if (pr.draft) {
77-
core.setFailed(`PR #${prNumber} is in draft state. Please mark it as ready for review before deploying.`);
78-
return;
79-
}
80-
81-
// Get detailed PR information including mergeable state
82-
const { data: prDetails } = await github.rest.pulls.get({
83-
owner: context.repo.owner,
84-
repo: context.repo.repo,
85-
pull_number: prNumber
86-
});
87-
88-
// Check if PR is mergeable and all requirements are satisfied
89-
if (prDetails.mergeable === false) {
90-
core.setFailed(`PR #${prNumber} is not in a mergeable state. Please resolve conflicts before deploying.`);
91-
return;
92-
}
93-
94-
// The mergeable_state can be one of: clean, dirty, blocked, unstable, or unknown
95-
// Only 'clean' means all requirements are met (checks passed, approvals received, no conflicts)
96-
if (prDetails.mergeable_state !== 'clean') {
97-
// Get more details about why it's not clean
98-
let reason = '';
99-
100-
if (prDetails.mergeable_state === 'blocked') {
101-
reason = 'required checks or approvals are missing';
102-
} else if (prDetails.mergeable_state === 'dirty') {
103-
reason = 'there are merge conflicts';
104-
} else if (prDetails.mergeable_state === 'unstable') {
105-
reason = 'required checks are failing';
106-
} else {
107-
reason = `the mergeable state is "${prDetails.mergeable_state}"`;
108-
}
109-
110-
core.setFailed(`PR #${prNumber} is not ready to merge: ${reason}. Please resolve all issues before deploying.`);
111-
return;
112-
}
113-
114-
console.log(`PR #${prNumber} is in a clean mergeable state. All requirements satisfied. Proceeding with beta deployment.`);
115-
87+
console.log(`Found PR #${prNumber} for branch ${branch}: ${prUrl}`);
88+
11689
core.setOutput('pr_number', prNumber);
11790
core.setOutput('pr_url', prUrl);
11891
} else {
11992
core.setFailed(`No open PR found for branch ${branch} targeting develop branch`);
120-
core.setOutput('pr_number', '');
12193
}
12294
95+
validate-pr:
96+
name: Validate PR Status
97+
needs: find-pr
98+
runs-on: [self-hosted, Linux, X64]
99+
steps:
100+
- name: Harden the runner (Audit all outbound calls)
101+
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
102+
with:
103+
egress-policy: audit
104+
105+
- name: Checkout code
106+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
107+
with:
108+
fetch-depth: 0
109+
110+
- name: Validate PR
111+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
112+
with:
113+
script: |
114+
const prNumber = '${{ needs.find-pr.outputs.pr_number }}';
115+
const forceDeployMode = '${{ needs.find-pr.outputs.force_deploy_mode }}' === 'true';
116+
117+
// Skip validation if force deploy is enabled
118+
if (forceDeployMode) {
119+
console.log(`⚠️ FORCE DEPLOY MODE - Skipping all PR validation checks`);
120+
console.log(`PR #${prNumber} validation bypassed by explicit user confirmation`);
121+
return;
122+
}
123+
124+
console.log(`Validating PR #${prNumber}...`);
125+
126+
// Get detailed PR information
127+
const { data: prDetails } = await github.rest.pulls.get({
128+
owner: context.repo.owner,
129+
repo: context.repo.repo,
130+
pull_number: prNumber
131+
});
132+
133+
// Check if PR is in draft state
134+
if (prDetails.draft) {
135+
core.setFailed(`PR #${prNumber} is in draft state. Please mark it as ready for review before deploying.`);
136+
return;
137+
}
138+
139+
// Check if PR is mergeable
140+
if (prDetails.mergeable === false) {
141+
core.setFailed(`PR #${prNumber} is not in a mergeable state. Please resolve conflicts before deploying.`);
142+
return;
143+
}
144+
145+
// Check mergeable_state
146+
if (prDetails.mergeable_state !== 'clean') {
147+
let reason = '';
148+
149+
if (prDetails.mergeable_state === 'blocked') {
150+
reason = 'required checks or approvals are missing';
151+
} else if (prDetails.mergeable_state === 'dirty') {
152+
reason = 'there are merge conflicts';
153+
} else if (prDetails.mergeable_state === 'unstable') {
154+
reason = 'required checks are failing';
155+
} else {
156+
reason = `the mergeable state is "${prDetails.mergeable_state}"`;
157+
}
158+
159+
core.setFailed(`PR #${prNumber} is not ready to merge: ${reason}. Please resolve all issues before deploying.`);
160+
return;
161+
}
162+
163+
console.log(`PR #${prNumber} is in a clean mergeable state. All requirements satisfied.`);
164+
165+
get-deploy-inputs:
166+
name: Get Deploy Inputs
167+
needs: [find-pr, validate-pr]
168+
runs-on: [self-hosted, Linux, X64]
169+
outputs:
170+
version_suffix: ${{ steps.deploy-inputs.outputs.version_suffix }}
171+
beta_identifier: ${{ steps.deploy-inputs.outputs.beta_identifier }}
172+
beta_identifier_for_automation_tests: ${{ steps.deploy-inputs.outputs.beta_identifier_for_automation_tests }}
173+
trigger_source: ${{ steps.set-trigger-source.outputs.trigger_source }}
174+
steps:
175+
- name: Harden the runner (Audit all outbound calls)
176+
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
177+
with:
178+
egress-policy: audit
179+
180+
- name: Checkout code
181+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
182+
with:
183+
fetch-depth: 0
184+
185+
- name: Set trigger source
186+
id: set-trigger-source
187+
run: |
188+
TRIGGER_BASE="Triggered via PR <${{ needs.find-pr.outputs.pr_url }}|#${{ needs.find-pr.outputs.pr_number }}> by <${{ github.server_url }}/${{ github.actor }}|${{ github.actor }}>"
189+
190+
if [ "${{ needs.find-pr.outputs.force_deploy_mode }}" = "true" ]; then
191+
echo "trigger_source=${TRIGGER_BASE} [⚠️ FORCE DEPLOY]" >> $GITHUB_OUTPUT
192+
else
193+
echo "trigger_source=${TRIGGER_BASE}" >> $GITHUB_OUTPUT
194+
fi
195+
123196
- name: Extract deploy inputs
124197
id: deploy-inputs
125198
shell: bash
@@ -130,9 +203,9 @@ jobs:
130203
# - "beta.pr." is a fixed prefix indicating a beta release for a pull request.
131204
# - <PR_NUMBER> is the number of the pull request associated with the branch.
132205
# - <SHORT_COMMIT_HASH> is the first 7 characters of the commit hash for traceability.
133-
echo "version_suffix=beta.pr.${{ steps.pr-info.outputs.pr_number }}.$SHA_SHORT" >> $GITHUB_OUTPUT
134-
echo "beta_identifier=PR-${{ steps.pr-info.outputs.pr_number }}/$SHA_SHORT" >> $GITHUB_OUTPUT
135-
echo "beta_identifier_for_automation_tests=pr-${{ steps.pr-info.outputs.pr_number }}-$SHA_SHORT" >> $GITHUB_OUTPUT
206+
echo "version_suffix=beta.pr.${{ needs.find-pr.outputs.pr_number }}.$SHA_SHORT" >> $GITHUB_OUTPUT
207+
echo "beta_identifier=PR-${{ needs.find-pr.outputs.pr_number }}/$SHA_SHORT" >> $GITHUB_OUTPUT
208+
echo "beta_identifier_for_automation_tests=pr-${{ needs.find-pr.outputs.pr_number }}-$SHA_SHORT" >> $GITHUB_OUTPUT
136209
137210
deploy-cdn:
138211
name: Deploy to CDN

.github/workflows/deploy-npm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ jobs:
171171
TAG_OPTION="--tag=beta"
172172
fi
173173
174-
npx nx release publish --verbose --base=${{ env.last_monorepo_version }} --head=${{ env.current_monorepo_version }} $TAG_OPTION
174+
npx nx release publish --verbose --projects=@rudderstack/analytics-js $TAG_OPTION
175175
176176
# Reset the changes made to package.json
177177
git reset --hard

0 commit comments

Comments
 (0)