@smoothbricks/cli 0.10.14 → 0.10.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -54,7 +54,7 @@ export interface GithubCiNxDeployOptions {
|
|
|
54
54
|
verify?: boolean;
|
|
55
55
|
}
|
|
56
56
|
export interface GithubCiNxDeployDependencies {
|
|
57
|
-
listProjects?: (root: string, target: string, mode: 'affected' | 'run-many') => Promise<string[]>;
|
|
57
|
+
listProjects?: (root: string, target: string, mode: 'affected' | 'run-many', stage: DeploymentStage) => Promise<string[]>;
|
|
58
58
|
runNx?: (args: string[], root: string) => Promise<number>;
|
|
59
59
|
appendSummary?: (summaryPath: string, content: string) => Promise<void>;
|
|
60
60
|
appendOutput?: (outputPath: string, content: string) => Promise<void>;
|
|
@@ -65,7 +65,7 @@ export interface GithubCiNxDeployDependencies {
|
|
|
65
65
|
}
|
|
66
66
|
export declare function githubCiNxDeploy(root: string, options: GithubCiNxDeployOptions, dependencies?: GithubCiNxDeployDependencies): Promise<void>;
|
|
67
67
|
export declare function resolveDeploymentStage(explicit: string | undefined, environment: NodeJS.ProcessEnv, event: GithubActionsEventPayload | undefined): DeploymentStage;
|
|
68
|
-
export declare function selectStageDeployProjects(candidates: string[], loadProject: (project: string) => Promise<unknown>): Promise<string[]>;
|
|
68
|
+
export declare function selectStageDeployProjects(candidates: string[], stage: DeploymentStage, loadProject: (project: string) => Promise<unknown>): Promise<string[]>;
|
|
69
69
|
export interface GithubApiProcessResult {
|
|
70
70
|
exitCode: number;
|
|
71
71
|
stdout: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/github-ci/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,cAAc,EAAsB,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,KAAK,eAAe,EAA8D,MAAM,sBAAsB,CAAC;AACxH,OAAO,KAAK,EAAE,WAAW,EA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(() => {
|
|
26
26
|
const _ip0 = input => true;
|
|
27
|
-
const _io0 = input => undefined === input.targets || "object" === typeof input.targets && null !== input.targets && false === Array.isArray(input.targets) && _io1(input.targets);
|
|
27
|
+
const _io0 = input => true && (undefined === input.targets || "object" === typeof input.targets && null !== input.targets && false === Array.isArray(input.targets) && _io1(input.targets));
|
|
28
28
|
const _io1 = input => undefined === input.deploy || "object" === typeof input.deploy && null !== input.deploy && false === Array.isArray(input.deploy) && _io2(input.deploy);
|
|
29
29
|
const _io2 = input => _ip0(input) && (undefined === input.options || "object" === typeof input.options && null !== input.options && false === Array.isArray(input.options) && _io3(input.options));
|
|
30
30
|
const _io3 = input => _ip0(input);
|
|
@@ -32,7 +32,7 @@ const isNxProjectDeployTarget = (() => {
|
|
|
32
32
|
})();
|
|
33
33
|
const parseNxProjectDeployTarget = (() => {
|
|
34
34
|
const _ip0 = input => true;
|
|
35
|
-
const _io0 = input => undefined === input.targets || "object" === typeof input.targets && null !== input.targets && false === Array.isArray(input.targets) && _io1(input.targets);
|
|
35
|
+
const _io0 = input => true && (undefined === input.targets || "object" === typeof input.targets && null !== input.targets && false === Array.isArray(input.targets) && _io1(input.targets));
|
|
36
36
|
const _io1 = input => undefined === input.deploy || "object" === typeof input.deploy && null !== input.deploy && false === Array.isArray(input.deploy) && _io2(input.deploy);
|
|
37
37
|
const _io2 = input => _ip0(input) && (undefined === input.options || "object" === typeof input.options && null !== input.options && false === Array.isArray(input.options) && _io3(input.options));
|
|
38
38
|
const _io3 = input => _ip0(input);
|
|
@@ -333,7 +333,7 @@ export async function githubCiNxDeploy(root, options, dependencies = {}) {
|
|
|
333
333
|
const mode = resolveNxSmartMode(options.mode ?? 'run-many');
|
|
334
334
|
const listProjects = dependencies.listProjects ?? listNxProjectsWithTarget;
|
|
335
335
|
const runNx = dependencies.runNx ?? ((args, commandRoot) => runStatus('nx', args, commandRoot));
|
|
336
|
-
const projects = await listProjects(root, 'deploy', mode);
|
|
336
|
+
const projects = await listProjects(root, 'deploy', mode, stage);
|
|
337
337
|
if (projects.length === 0) {
|
|
338
338
|
console.log(`No ${mode} deploy projects; skipping ${stage}.`);
|
|
339
339
|
await setStatus('success');
|
|
@@ -347,7 +347,7 @@ export async function githubCiNxDeploy(root, options, dependencies = {}) {
|
|
|
347
347
|
'-t',
|
|
348
348
|
target,
|
|
349
349
|
`--projects=${projectList}`,
|
|
350
|
-
|
|
350
|
+
`--exclude=${deployExclusions(stage)}`,
|
|
351
351
|
`--parallel=${NX_PARALLEL}`,
|
|
352
352
|
];
|
|
353
353
|
if (target === 'deploy') {
|
|
@@ -454,19 +454,25 @@ function readGithubActionsEvent(environment) {
|
|
|
454
454
|
return undefined;
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
|
-
|
|
457
|
+
function deployExclusions(stage) {
|
|
458
|
+
const tags = ['tag:permanent-deploy-target'];
|
|
459
|
+
if (stage !== 'staging')
|
|
460
|
+
tags.push('tag:staging-deploy-target');
|
|
461
|
+
return tags.join(',');
|
|
462
|
+
}
|
|
463
|
+
async function listNxProjectsWithTarget(root, target, mode, stage) {
|
|
458
464
|
const listArgs = ['show', 'projects'];
|
|
459
465
|
if (mode === 'affected')
|
|
460
466
|
listArgs.push('--affected');
|
|
461
467
|
listArgs.push('--withTarget', target);
|
|
462
468
|
if (target === 'deploy')
|
|
463
|
-
listArgs.push(
|
|
469
|
+
listArgs.push(`--exclude=${deployExclusions(stage)}`);
|
|
464
470
|
listArgs.push('--json');
|
|
465
471
|
const result = await $ `nx ${listArgs}`.cwd(root).quiet();
|
|
466
472
|
const candidates = nxProjectList(decode(result.stdout)).sort((left, right) => left.localeCompare(right));
|
|
467
473
|
if (target !== 'deploy')
|
|
468
474
|
return candidates;
|
|
469
|
-
return selectStageDeployProjects(candidates, async (project) => {
|
|
475
|
+
return selectStageDeployProjects(candidates, stage, async (project) => {
|
|
470
476
|
const projectResult = await $ `nx show project ${project} --json`.cwd(root).quiet();
|
|
471
477
|
const parsed = parseNxProjectDeployTarget(decode(projectResult.stdout));
|
|
472
478
|
if (!parsed)
|
|
@@ -474,7 +480,7 @@ async function listNxProjectsWithTarget(root, target, mode) {
|
|
|
474
480
|
return parsed;
|
|
475
481
|
});
|
|
476
482
|
}
|
|
477
|
-
export async function selectStageDeployProjects(candidates, loadProject) {
|
|
483
|
+
export async function selectStageDeployProjects(candidates, stage, loadProject) {
|
|
478
484
|
const selected = [];
|
|
479
485
|
for (const project of candidates) {
|
|
480
486
|
const definition = await loadProject(project);
|
|
@@ -482,7 +488,13 @@ export async function selectStageDeployProjects(candidates, loadProject) {
|
|
|
482
488
|
continue;
|
|
483
489
|
const deploy = definition.targets?.deploy;
|
|
484
490
|
const commandValue = deploy?.options?.command ?? deploy?.command;
|
|
485
|
-
|
|
491
|
+
const tags = Array.isArray(definition.tags)
|
|
492
|
+
? definition.tags.filter((tag) => typeof tag === 'string')
|
|
493
|
+
: [];
|
|
494
|
+
const isStageDerived = tags.includes('stage-deploy-target') ||
|
|
495
|
+
(typeof commandValue === 'string' && commandValue.includes('smoo wrangler deploy-stage'));
|
|
496
|
+
const isStagingOnly = tags.includes('staging-deploy-target');
|
|
497
|
+
if (isStageDerived || (stage === 'staging' && isStagingOnly)) {
|
|
486
498
|
selected.push(project);
|
|
487
499
|
}
|
|
488
500
|
}
|
package/package.json
CHANGED
|
@@ -573,7 +573,7 @@ describe('event-aware stage deployment', () => {
|
|
|
573
573
|
).toThrow(/same-repository/);
|
|
574
574
|
});
|
|
575
575
|
|
|
576
|
-
it('selects
|
|
576
|
+
it('selects stage-derived deploy targets plus staging-only infrastructure on staging', async () => {
|
|
577
577
|
const definitions: Record<string, unknown> = {
|
|
578
578
|
'conloca-app': {
|
|
579
579
|
targets: {
|
|
@@ -581,19 +581,37 @@ describe('event-aware stage deployment', () => {
|
|
|
581
581
|
},
|
|
582
582
|
},
|
|
583
583
|
'conloca-app-backend': {
|
|
584
|
-
|
|
584
|
+
tags: ['stage-deploy-target'],
|
|
585
|
+
targets: { deploy: { command: 'bun scripts/deploy-backend.ts --stage={args.stage}' } },
|
|
586
|
+
},
|
|
587
|
+
'conloca-e2e-mail-capture': {
|
|
588
|
+
tags: ['staging-deploy-target'],
|
|
589
|
+
targets: { deploy: { options: { command: 'bun scripts/deploy.ts --stage={args.stage}' } } },
|
|
585
590
|
},
|
|
586
591
|
'conloca-oauth-redirect': {
|
|
592
|
+
tags: ['permanent-deploy-target'],
|
|
587
593
|
targets: { deploy: { options: { command: 'wrangler deploy --config wrangler.toml' } } },
|
|
588
594
|
},
|
|
589
595
|
'conloca-website': {
|
|
590
596
|
targets: { deploy: { options: { command: 'bun scripts/deploy-website.ts' } } },
|
|
591
597
|
},
|
|
592
598
|
};
|
|
599
|
+
const candidates = Object.keys(definitions);
|
|
600
|
+
const loadProject = async (project: string) => definitions[project];
|
|
593
601
|
|
|
594
|
-
await expect(
|
|
595
|
-
|
|
596
|
-
|
|
602
|
+
await expect(selectStageDeployProjects(candidates, 'staging', loadProject)).resolves.toEqual([
|
|
603
|
+
'conloca-app',
|
|
604
|
+
'conloca-app-backend',
|
|
605
|
+
'conloca-e2e-mail-capture',
|
|
606
|
+
]);
|
|
607
|
+
await expect(selectStageDeployProjects(candidates, 'pr123', loadProject)).resolves.toEqual([
|
|
608
|
+
'conloca-app',
|
|
609
|
+
'conloca-app-backend',
|
|
610
|
+
]);
|
|
611
|
+
await expect(selectStageDeployProjects(candidates, 'production', loadProject)).resolves.toEqual([
|
|
612
|
+
'conloca-app',
|
|
613
|
+
'conloca-app-backend',
|
|
614
|
+
]);
|
|
597
615
|
});
|
|
598
616
|
|
|
599
617
|
it('publishes GitHub deployment JSON through a real stdin process seam', async () => {
|
|
@@ -658,7 +676,7 @@ describe('event-aware stage deployment', () => {
|
|
|
658
676
|
|
|
659
677
|
it('deploys app/backend, publishes PR metadata, and emits the resolved stage', async () => {
|
|
660
678
|
const nxCalls: string[][] = [];
|
|
661
|
-
const listCalls: Array<[string, string]> = [];
|
|
679
|
+
const listCalls: Array<[string, string, string]> = [];
|
|
662
680
|
const summaries: string[] = [];
|
|
663
681
|
const deployments: Array<[string, string]> = [];
|
|
664
682
|
const outputs: string[] = [];
|
|
@@ -678,8 +696,8 @@ describe('event-aware stage deployment', () => {
|
|
|
678
696
|
repository: { full_name: 'owner/repo' },
|
|
679
697
|
pull_request: { number: 123, head: { repo: { full_name: 'owner/repo' } } },
|
|
680
698
|
},
|
|
681
|
-
listProjects: async (_root, target, mode) => {
|
|
682
|
-
listCalls.push([target, mode]);
|
|
699
|
+
listProjects: async (_root, target, mode, stage) => {
|
|
700
|
+
listCalls.push([target, mode, stage]);
|
|
683
701
|
return ['conloca-app', 'conloca-app-backend'];
|
|
684
702
|
},
|
|
685
703
|
runNx: async (args) => {
|
|
@@ -698,10 +716,10 @@ describe('event-aware stage deployment', () => {
|
|
|
698
716
|
},
|
|
699
717
|
);
|
|
700
718
|
|
|
701
|
-
expect(listCalls).toEqual([['deploy', 'run-many']]);
|
|
719
|
+
expect(listCalls).toEqual([['deploy', 'run-many', 'pr123']]);
|
|
702
720
|
expect(nxCalls).toHaveLength(1);
|
|
703
721
|
expect(nxCalls[0]).toContain('--projects=conloca-app,conloca-app-backend');
|
|
704
|
-
expect(nxCalls[0]).toContain('--exclude=tag:permanent-deploy-target');
|
|
722
|
+
expect(nxCalls[0]).toContain('--exclude=tag:permanent-deploy-target,tag:staging-deploy-target');
|
|
705
723
|
expect(nxCalls[0]).toContain('--stage=pr123');
|
|
706
724
|
expect(nxCalls[0]).not.toContain('e2e-deployment');
|
|
707
725
|
expect(summaries).toEqual(['## pr123 deployment\n\n[View deployment](https://app.pr123.conloca.com)\n']);
|
package/src/github-ci/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ export interface GithubActionsEventPayload {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
interface NxProjectDeployTarget {
|
|
30
|
+
tags?: unknown;
|
|
30
31
|
targets?: {
|
|
31
32
|
deploy?: {
|
|
32
33
|
command?: unknown;
|
|
@@ -404,7 +405,12 @@ export interface GithubCiNxDeployOptions {
|
|
|
404
405
|
}
|
|
405
406
|
|
|
406
407
|
export interface GithubCiNxDeployDependencies {
|
|
407
|
-
listProjects?: (
|
|
408
|
+
listProjects?: (
|
|
409
|
+
root: string,
|
|
410
|
+
target: string,
|
|
411
|
+
mode: 'affected' | 'run-many',
|
|
412
|
+
stage: DeploymentStage,
|
|
413
|
+
) => Promise<string[]>;
|
|
408
414
|
runNx?: (args: string[], root: string) => Promise<number>;
|
|
409
415
|
appendSummary?: (summaryPath: string, content: string) => Promise<void>;
|
|
410
416
|
appendOutput?: (outputPath: string, content: string) => Promise<void>;
|
|
@@ -432,7 +438,7 @@ export async function githubCiNxDeploy(
|
|
|
432
438
|
const mode = resolveNxSmartMode(options.mode ?? 'run-many');
|
|
433
439
|
const listProjects = dependencies.listProjects ?? listNxProjectsWithTarget;
|
|
434
440
|
const runNx = dependencies.runNx ?? ((args: string[], commandRoot: string) => runStatus('nx', args, commandRoot));
|
|
435
|
-
const projects = await listProjects(root, 'deploy', mode);
|
|
441
|
+
const projects = await listProjects(root, 'deploy', mode, stage);
|
|
436
442
|
if (projects.length === 0) {
|
|
437
443
|
console.log(`No ${mode} deploy projects; skipping ${stage}.`);
|
|
438
444
|
await setStatus('success');
|
|
@@ -447,7 +453,7 @@ export async function githubCiNxDeploy(
|
|
|
447
453
|
'-t',
|
|
448
454
|
target,
|
|
449
455
|
`--projects=${projectList}`,
|
|
450
|
-
|
|
456
|
+
`--exclude=${deployExclusions(stage)}`,
|
|
451
457
|
`--parallel=${NX_PARALLEL}`,
|
|
452
458
|
];
|
|
453
459
|
if (target === 'deploy') {
|
|
@@ -565,20 +571,27 @@ function readGithubActionsEvent(environment: NodeJS.ProcessEnv): GithubActionsEv
|
|
|
565
571
|
}
|
|
566
572
|
}
|
|
567
573
|
|
|
574
|
+
function deployExclusions(stage: DeploymentStage): string {
|
|
575
|
+
const tags = ['tag:permanent-deploy-target'];
|
|
576
|
+
if (stage !== 'staging') tags.push('tag:staging-deploy-target');
|
|
577
|
+
return tags.join(',');
|
|
578
|
+
}
|
|
579
|
+
|
|
568
580
|
async function listNxProjectsWithTarget(
|
|
569
581
|
root: string,
|
|
570
582
|
target: string,
|
|
571
583
|
mode: 'affected' | 'run-many',
|
|
584
|
+
stage: DeploymentStage,
|
|
572
585
|
): Promise<string[]> {
|
|
573
586
|
const listArgs = ['show', 'projects'];
|
|
574
587
|
if (mode === 'affected') listArgs.push('--affected');
|
|
575
588
|
listArgs.push('--withTarget', target);
|
|
576
|
-
if (target === 'deploy') listArgs.push(
|
|
589
|
+
if (target === 'deploy') listArgs.push(`--exclude=${deployExclusions(stage)}`);
|
|
577
590
|
listArgs.push('--json');
|
|
578
591
|
const result = await $`nx ${listArgs}`.cwd(root).quiet();
|
|
579
592
|
const candidates = nxProjectList(decode(result.stdout)).sort((left, right) => left.localeCompare(right));
|
|
580
593
|
if (target !== 'deploy') return candidates;
|
|
581
|
-
return selectStageDeployProjects(candidates, async (project) => {
|
|
594
|
+
return selectStageDeployProjects(candidates, stage, async (project) => {
|
|
582
595
|
const projectResult = await $`nx show project ${project} --json`.cwd(root).quiet();
|
|
583
596
|
const parsed = parseNxProjectDeployTarget(decode(projectResult.stdout));
|
|
584
597
|
if (!parsed) throw new Error(`nx show project ${project} returned invalid JSON.`);
|
|
@@ -588,6 +601,7 @@ async function listNxProjectsWithTarget(
|
|
|
588
601
|
|
|
589
602
|
export async function selectStageDeployProjects(
|
|
590
603
|
candidates: string[],
|
|
604
|
+
stage: DeploymentStage,
|
|
591
605
|
loadProject: (project: string) => Promise<unknown>,
|
|
592
606
|
): Promise<string[]> {
|
|
593
607
|
const selected: string[] = [];
|
|
@@ -596,7 +610,14 @@ export async function selectStageDeployProjects(
|
|
|
596
610
|
if (!isNxProjectDeployTarget(definition)) continue;
|
|
597
611
|
const deploy = definition.targets?.deploy;
|
|
598
612
|
const commandValue = deploy?.options?.command ?? deploy?.command;
|
|
599
|
-
|
|
613
|
+
const tags = Array.isArray(definition.tags)
|
|
614
|
+
? definition.tags.filter((tag): tag is string => typeof tag === 'string')
|
|
615
|
+
: [];
|
|
616
|
+
const isStageDerived =
|
|
617
|
+
tags.includes('stage-deploy-target') ||
|
|
618
|
+
(typeof commandValue === 'string' && commandValue.includes('smoo wrangler deploy-stage'));
|
|
619
|
+
const isStagingOnly = tags.includes('staging-deploy-target');
|
|
620
|
+
if (isStageDerived || (stage === 'staging' && isStagingOnly)) {
|
|
600
621
|
selected.push(project);
|
|
601
622
|
}
|
|
602
623
|
}
|