@smoothbricks/cli 0.11.17 → 0.11.19
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.
- package/README.md +45 -10
- package/dist/cli.js +10 -7
- package/dist/github-ci/index.d.ts.map +1 -1
- package/dist/github-ci/index.js +6 -20
- package/dist/lib/deploy-tags.d.ts +17 -3
- package/dist/lib/deploy-tags.d.ts.map +1 -1
- package/dist/lib/deploy-tags.js +23 -4
- package/dist/monorepo/ci-workflow.d.ts +56 -0
- package/dist/monorepo/ci-workflow.d.ts.map +1 -1
- package/dist/monorepo/ci-workflow.js +199 -2
- package/dist/monorepo/managed-files.d.ts +28 -2
- package/dist/monorepo/managed-files.d.ts.map +1 -1
- package/dist/monorepo/managed-files.js +74 -22
- package/dist/release/github-release.d.ts +10 -0
- package/dist/release/github-release.d.ts.map +1 -1
- package/dist/release/github-release.js +11 -5
- package/dist/release/index.d.ts.map +1 -1
- package/dist/release/index.js +4 -5
- package/dist/secrets/commands.d.ts +52 -13
- package/dist/secrets/commands.d.ts.map +1 -1
- package/dist/secrets/commands.js +220 -34
- package/dist/secrets/index.d.ts +21 -1
- package/dist/secrets/index.d.ts.map +1 -1
- package/dist/secrets/index.js +110 -4
- package/dist/secrets/repository.d.ts +60 -0
- package/dist/secrets/repository.d.ts.map +1 -0
- package/dist/secrets/repository.js +145 -0
- package/dist/wrangler/cloudflare.d.ts +7 -0
- package/dist/wrangler/cloudflare.d.ts.map +1 -1
- package/dist/wrangler/cloudflare.js +10 -0
- package/dist/wrangler/deploy-stage.d.ts.map +1 -1
- package/dist/wrangler/deploy-stage.js +50 -24
- package/dist/wrangler/stage-secrets.d.ts +57 -0
- package/dist/wrangler/stage-secrets.d.ts.map +1 -0
- package/dist/wrangler/stage-secrets.js +178 -0
- package/managed/raw/tooling/direnv/devenv.smoo.nix +9 -1
- package/managed/raw/tooling/git-hooks/pre-push.sh +30 -29
- package/package.json +2 -2
- package/src/cli.ts +33 -10
- package/src/github-ci/index.test.ts +6 -7
- package/src/github-ci/index.ts +11 -19
- package/src/lib/deploy-tags.ts +22 -4
- package/src/monorepo/__tests__/ci-workflow.test.ts +161 -0
- package/src/monorepo/ci-workflow.ts +277 -2
- package/src/monorepo/managed-files.test.ts +96 -37
- package/src/monorepo/managed-files.ts +94 -23
- package/src/monorepo/package-policy.test.ts +1 -1
- package/src/release/__tests__/github-release.test.ts +8 -4
- package/src/release/github-release.ts +13 -5
- package/src/release/index.ts +4 -4
- package/src/secrets/commands.test.ts +28 -0
- package/src/secrets/commands.ts +237 -35
- package/src/secrets/index.test.ts +118 -1
- package/src/secrets/index.ts +108 -4
- package/src/secrets/repository.test.ts +98 -0
- package/src/secrets/repository.ts +164 -0
- package/src/wrangler/cloudflare.ts +18 -0
- package/src/wrangler/deploy-stage.test.ts +258 -11
- package/src/wrangler/deploy-stage.ts +70 -38
- package/src/wrangler/stage-secrets.ts +146 -0
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/* biome-ignore-all lint/suspicious/noTemplateCurlyInString: GitHub Actions expressions are emitted literally. */
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
cargoCrossTestArchiveFile,
|
|
5
|
+
cargoCrossTestArchiveTargetName,
|
|
6
|
+
cargoCrossTestTargetName,
|
|
7
|
+
} from '@smoothbricks/nx-plugin/cross-check-policy';
|
|
3
8
|
import { PRODUCTION_PUSH_DEPLOY_TAG } from '../lib/deploy-tags.js';
|
|
4
9
|
import type {
|
|
5
10
|
NonEmptyArray,
|
|
@@ -24,6 +29,11 @@ export enum CiWorkflowStepKind {
|
|
|
24
29
|
BrowserTests = 'browser-tests',
|
|
25
30
|
Lint = 'lint',
|
|
26
31
|
UnitTests = 'unit-tests',
|
|
32
|
+
CrossToolchainPreflight = 'cross-toolchain-preflight',
|
|
33
|
+
CrossTestArchives = 'cross-test-archives',
|
|
34
|
+
UploadCrossTestArchives = 'upload-cross-test-archives',
|
|
35
|
+
DownloadCrossTestArchives = 'download-cross-test-archives',
|
|
36
|
+
CrossTests = 'cross-tests',
|
|
27
37
|
ManagedFilesCheck = 'managed-files-check',
|
|
28
38
|
ManagedFilesDispatch = 'managed-files-dispatch',
|
|
29
39
|
Deploy = 'deploy',
|
|
@@ -51,6 +61,23 @@ export interface DeployStepSecretConfig {
|
|
|
51
61
|
deploySecrets?: Record<string, string>;
|
|
52
62
|
}
|
|
53
63
|
|
|
64
|
+
/**
|
|
65
|
+
* One foreign target triple's test archive: what the Linux job cross-builds and
|
|
66
|
+
* a native runner executes.
|
|
67
|
+
*
|
|
68
|
+
* Both fields are DERIVED, never hand-written: the triple comes from the cargo
|
|
69
|
+
* workspace's `[workspace.metadata.smoothbricks.test] cross-targets`, and the
|
|
70
|
+
* path is where the inferred `cargo-cross-test-archive-<triple>` target
|
|
71
|
+
* declares its output. That is why this is not a `smoo.github` key — a triple
|
|
72
|
+
* repeated in CI config could name an archive the graph cannot build, and the
|
|
73
|
+
* workflow would only find out on the runner.
|
|
74
|
+
*/
|
|
75
|
+
export interface CiCrossTestArchive {
|
|
76
|
+
triple: string;
|
|
77
|
+
/** Repository-relative path of the archive file, from the target's output. */
|
|
78
|
+
path: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
54
81
|
export interface CiWorkflowDefinitionOptions extends DeployStepSecretConfig {
|
|
55
82
|
actionsProvider?: PackageSmooGithub['actionsProvider'];
|
|
56
83
|
deploy: boolean;
|
|
@@ -92,6 +119,41 @@ export interface CiWorkflowDefinitionOptions extends DeployStepSecretConfig {
|
|
|
92
119
|
e2eSecrets?: Record<string, string>;
|
|
93
120
|
/** Emit the production-on-push job (some project carries PRODUCTION_PUSH_DEPLOY_TAG). */
|
|
94
121
|
productionOnPush?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Cross-built test archives, one per foreign target triple the cargo
|
|
124
|
+
* workspace declares. The Linux job builds and uploads each one; a second job
|
|
125
|
+
* downloads the `*-apple-darwin` ones and EXECUTES them on `macosRunsOn`,
|
|
126
|
+
* which is how a cross compile gets proved by running rather than by linking.
|
|
127
|
+
*
|
|
128
|
+
* Empty or absent renders exactly what a repository without cross archives
|
|
129
|
+
* renders — no step, no job, no numbering shift.
|
|
130
|
+
*/
|
|
131
|
+
crossTestArchives?: readonly CiCrossTestArchive[];
|
|
132
|
+
/**
|
|
133
|
+
* macOS runner labels for the darwin execution job
|
|
134
|
+
* (`smoo.github.macosRunsOn`, the same labels the publish workflow's macOS
|
|
135
|
+
* legs use). Default macos-latest.
|
|
136
|
+
*
|
|
137
|
+
* A self-hosted label here is one specific machine. That machine being asleep
|
|
138
|
+
* does not skip the job: it queues, and the run FAILS on the job's
|
|
139
|
+
* `timeout-minutes`. That is the trade this opt-in buys — a red run when the
|
|
140
|
+
* Mac is unreachable, in exchange for the darwin binaries being tested by
|
|
141
|
+
* execution at all. `continue-on-error` would buy the green back by making
|
|
142
|
+
* the job unable to report anything, which is worse than not having it.
|
|
143
|
+
*/
|
|
144
|
+
macosRunsOn?: string | string[];
|
|
145
|
+
/**
|
|
146
|
+
* Declared Linux cross-platform producer (`smoo.github.platformProducer`):
|
|
147
|
+
* the toolchain preflight and the environment a foreign-target build needs on
|
|
148
|
+
* a Linux runner. The publish workflow already renders this declaration for
|
|
149
|
+
* its cross artifact job, so the cross test archive reuses it rather than
|
|
150
|
+
* carrying a second copy of one repository's SDK and linker setup.
|
|
151
|
+
*
|
|
152
|
+
* Rendered STEP-scoped here, never as job env: this environment turns the
|
|
153
|
+
* repository's native producers into cross producers, and Validate's other
|
|
154
|
+
* steps are host builds that must stay host builds.
|
|
155
|
+
*/
|
|
156
|
+
platformProducer?: PackageSmooGithub['platformProducer'];
|
|
95
157
|
}
|
|
96
158
|
|
|
97
159
|
type CiWorkflowStepInput = Omit<CiWorkflowStep, 'number'>;
|
|
@@ -117,6 +179,18 @@ export function defineCiWorkflow(options: CiWorkflowDefinitionOptions): CiWorkfl
|
|
|
117
179
|
{ kind: CiWorkflowStepKind.Lint, name: '🔍 Lint' },
|
|
118
180
|
{ kind: CiWorkflowStepKind.UnitTests, name: '🧪 Unit Tests' },
|
|
119
181
|
);
|
|
182
|
+
if (options.crossTestArchives?.length) {
|
|
183
|
+
if (options.platformProducer !== undefined) {
|
|
184
|
+
steps.push({
|
|
185
|
+
kind: CiWorkflowStepKind.CrossToolchainPreflight,
|
|
186
|
+
name: 'Check cross-platform toolchain prerequisites',
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
steps.push(
|
|
190
|
+
{ kind: CiWorkflowStepKind.CrossTestArchives, name: '🎯 Build cross-target test archives' },
|
|
191
|
+
{ kind: CiWorkflowStepKind.UploadCrossTestArchives, name: '📤 Upload cross-target test archives' },
|
|
192
|
+
);
|
|
193
|
+
}
|
|
120
194
|
if (options.browserTests) {
|
|
121
195
|
steps.push({ kind: CiWorkflowStepKind.BrowserTests, name: '🌐 Browser Tests' });
|
|
122
196
|
}
|
|
@@ -135,6 +209,7 @@ export function renderCiWorkflowYaml(options: CiWorkflowDefinitionOptions): stri
|
|
|
135
209
|
return [
|
|
136
210
|
renderCiWorkflowHeader(options),
|
|
137
211
|
renderCiWorkflowSteps(steps, options),
|
|
212
|
+
renderCrossTestExecutionJob(options),
|
|
138
213
|
renderE2eDeploymentJob(options),
|
|
139
214
|
renderProductionDeployJob(options),
|
|
140
215
|
].join('');
|
|
@@ -321,6 +396,61 @@ function yamlLinesForStep(step: CiWorkflowStep, options: CiWorkflowDefinitionOpt
|
|
|
321
396
|
return nxSmartStep(step, 'lint', 'Lint');
|
|
322
397
|
case CiWorkflowStepKind.UnitTests:
|
|
323
398
|
return nxSmartStep(step, 'test', 'Unit Tests');
|
|
399
|
+
case CiWorkflowStepKind.CrossToolchainPreflight:
|
|
400
|
+
// The repository's own preflight, the same one the publish workflow's
|
|
401
|
+
// cross artifact job runs — an SDK to provision, a linker to check.
|
|
402
|
+
// `working-directory: .` because this workflow's steps default to the
|
|
403
|
+
// direnv shell directory while a preflight is repository-relative.
|
|
404
|
+
return [
|
|
405
|
+
` - name: ${step.name}`,
|
|
406
|
+
' working-directory: .',
|
|
407
|
+
...platformProducerStepEnvLines(options),
|
|
408
|
+
' run: |',
|
|
409
|
+
' set -euo pipefail',
|
|
410
|
+
...crossToolchainPreflight(options).map((line) => ` ${line}`),
|
|
411
|
+
];
|
|
412
|
+
case CiWorkflowStepKind.CrossTestArchives:
|
|
413
|
+
// Cross-COMPILES the workspace's test binaries for each declared foreign
|
|
414
|
+
// triple and packs them; runs nothing. `nx-run-many` rather than
|
|
415
|
+
// `nx-smart`, because an affected-graph selection would skip the archive
|
|
416
|
+
// on a commit that changed nothing Rust — and the sibling job that
|
|
417
|
+
// executes it has no way to build one.
|
|
418
|
+
return [
|
|
419
|
+
` - name: ${step.name}`,
|
|
420
|
+
...platformProducerStepEnvLines(options),
|
|
421
|
+
` run: smoo github-ci nx-run-many --targets "${crossArchiveTargetNames(options).join(',')}"`,
|
|
422
|
+
];
|
|
423
|
+
case CiWorkflowStepKind.UploadCrossTestArchives:
|
|
424
|
+
// retention-days: 1 — the only consumer is the sibling job in this same
|
|
425
|
+
// run, and these archives are the whole workspace's test binaries.
|
|
426
|
+
return artifactStepLines(options.actionsProvider, step.name, 'upload', [
|
|
427
|
+
`name: ${CROSS_TEST_ARCHIVE_ARTIFACT}`,
|
|
428
|
+
'path: |',
|
|
429
|
+
...crossTestArchives(options).map((archive) => ` ${archive.path}`),
|
|
430
|
+
// error, not ignore: a missing archive means the cross build silently
|
|
431
|
+
// produced nothing, and the execute job would then have nothing to run
|
|
432
|
+
// and no reason to say so.
|
|
433
|
+
'if-no-files-found: error',
|
|
434
|
+
'retention-days: 1',
|
|
435
|
+
]);
|
|
436
|
+
case CiWorkflowStepKind.DownloadCrossTestArchives:
|
|
437
|
+
// Restores each archive at the path its own Nx target declares as output,
|
|
438
|
+
// which is where the runner target reads it from. upload-artifact roots
|
|
439
|
+
// the artifact at the least common ancestor of what it uploaded, so the
|
|
440
|
+
// download path is that shared directory.
|
|
441
|
+
return artifactStepLines(options.actionsProvider, step.name, 'download', [
|
|
442
|
+
`name: ${CROSS_TEST_ARCHIVE_ARTIFACT}`,
|
|
443
|
+
`path: ${crossTestArchiveDirectory(options)}`,
|
|
444
|
+
]);
|
|
445
|
+
case CiWorkflowStepKind.CrossTests:
|
|
446
|
+
// EXECUTES, and that is all it can do: every one of these targets is
|
|
447
|
+
// `nextest run --archive-file`, which extracts prebuilt binaries into its
|
|
448
|
+
// own temporary directory. nextest never invokes cargo on this path
|
|
449
|
+
// (measured), so nothing here can compile even if a toolchain is present.
|
|
450
|
+
return [
|
|
451
|
+
` - name: ${step.name}`,
|
|
452
|
+
` run: smoo github-ci nx-run-many --targets "${darwinCrossTestTargetNames(options).join(',')}"`,
|
|
453
|
+
];
|
|
324
454
|
case CiWorkflowStepKind.ManagedFilesCheck:
|
|
325
455
|
// The authoritative drift check is nearly free here (devenv is already
|
|
326
456
|
// up). --warn never fails the job and publishes the step output
|
|
@@ -953,6 +1083,10 @@ function renderYamlList(values: string[], spaces: number): string {
|
|
|
953
1083
|
* is GitHub's automatic "Set up job"); every preflight the main job runs also
|
|
954
1084
|
* runs here before SetupDevenv, so the middle and cleanup anchors shift with
|
|
955
1085
|
* the configuration instead of baking a fixed step number.
|
|
1086
|
+
*
|
|
1087
|
+
* `middle` is the FIRST of the job's own steps. A job with more than one — the
|
|
1088
|
+
* cross-test job downloads before it runs — passes how many it has, so the
|
|
1089
|
+
* cleanup anchor stays the number of the step GitHub will actually report.
|
|
956
1090
|
*/
|
|
957
1091
|
interface FollowUpStepNumbers {
|
|
958
1092
|
cargo: number | undefined;
|
|
@@ -962,12 +1096,13 @@ interface FollowUpStepNumbers {
|
|
|
962
1096
|
cleanup: number;
|
|
963
1097
|
}
|
|
964
1098
|
|
|
965
|
-
function followUpStepNumbers(options: CiWorkflowDefinitionOptions): FollowUpStepNumbers {
|
|
1099
|
+
function followUpStepNumbers(options: CiWorkflowDefinitionOptions, middleSteps = 1): FollowUpStepNumbers {
|
|
966
1100
|
let number = 3;
|
|
967
1101
|
const cargo = options.cargoCredentials !== undefined ? number++ : undefined;
|
|
968
1102
|
const sources = options.sourceCheckouts?.length ? number++ : undefined;
|
|
969
1103
|
const setup = number++;
|
|
970
|
-
const middle = number
|
|
1104
|
+
const middle = number;
|
|
1105
|
+
number += middleSteps;
|
|
971
1106
|
const cleanup = number++;
|
|
972
1107
|
return { cargo, sources, setup, middle, cleanup };
|
|
973
1108
|
}
|
|
@@ -994,6 +1129,146 @@ function followUpCleanupStep(numbers: FollowUpStepNumbers): CiWorkflowStep[] {
|
|
|
994
1129
|
return [{ kind: CiWorkflowStepKind.SaveNixDevenv, name: '🧹 Cleanup and cache Nix/devenv', number: numbers.cleanup }];
|
|
995
1130
|
}
|
|
996
1131
|
|
|
1132
|
+
/**
|
|
1133
|
+
* How long the darwin execution job may take, download included. Generous
|
|
1134
|
+
* because the archive is the whole workspace's test binaries, and bounded
|
|
1135
|
+
* because the runner behind `macosRunsOn` may be one person's laptop: an
|
|
1136
|
+
* unreachable runner queues, and this number is when the run says so.
|
|
1137
|
+
*/
|
|
1138
|
+
const CROSS_TEST_JOB_TIMEOUT_MINUTES = 30;
|
|
1139
|
+
|
|
1140
|
+
/** Rust names every Apple-desktop triple this way; iOS and simulator do not. */
|
|
1141
|
+
const DARWIN_TRIPLE_SUFFIX = '-apple-darwin';
|
|
1142
|
+
|
|
1143
|
+
/** One artifact carrying every triple's archive, scoped to the run that built it. */
|
|
1144
|
+
const CROSS_TEST_ARCHIVE_ARTIFACT = `cross-test-archives-${githubExpression('github.run_id')}`;
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* Executes the cross-built test binaries on a machine where they are native.
|
|
1148
|
+
*
|
|
1149
|
+
* This job COMPILES NOTHING, and cannot: its only Rust input is the archive the
|
|
1150
|
+
* Validate job uploaded, and `nextest run --archive-file` extracts prebuilt
|
|
1151
|
+
* binaries rather than invoking cargo (measured: zero cargo invocations). It
|
|
1152
|
+
* needs the checkout for the workspace `--workspace-remap .` points at and for
|
|
1153
|
+
* Nx to resolve the target, and setup-devenv for `nx` and `cargo-nextest`
|
|
1154
|
+
* themselves — the repository's ordinary shell, not a cross toolchain, no SDK,
|
|
1155
|
+
* no `rustup target add`.
|
|
1156
|
+
*
|
|
1157
|
+
* `needs: main` and a success gate rather than `!cancelled()`: an archive that
|
|
1158
|
+
* was never uploaded cannot be executed, and a job that starts anyway would
|
|
1159
|
+
* fail on a missing artifact and report it as a test failure.
|
|
1160
|
+
*
|
|
1161
|
+
* Only `*-apple-darwin` archives run here, because macOS runner labels are the
|
|
1162
|
+
* only native runner this declaration names. A repository declaring some other
|
|
1163
|
+
* foreign triple still gets its archive BUILT — which proves that triple
|
|
1164
|
+
* compiles — and no execution job, which is the honest rendering of having
|
|
1165
|
+
* nowhere to run it.
|
|
1166
|
+
*/
|
|
1167
|
+
function renderCrossTestExecutionJob(options: CiWorkflowDefinitionOptions): string {
|
|
1168
|
+
const archives = darwinCrossTestArchives(options);
|
|
1169
|
+
if (archives.length === 0) return '';
|
|
1170
|
+
const numbers = followUpStepNumbers(options, 2);
|
|
1171
|
+
const middleSteps: CiWorkflowStep[] = [
|
|
1172
|
+
{
|
|
1173
|
+
kind: CiWorkflowStepKind.DownloadCrossTestArchives,
|
|
1174
|
+
name: '📥 Download cross-target test archives',
|
|
1175
|
+
number: numbers.middle,
|
|
1176
|
+
},
|
|
1177
|
+
{ kind: CiWorkflowStepKind.CrossTests, name: '🧪 Cross-Target Unit Tests', number: numbers.middle + 1 },
|
|
1178
|
+
];
|
|
1179
|
+
return `
|
|
1180
|
+
macos-cross-tests:
|
|
1181
|
+
name: Unit Tests (${archives.map((archive) => archive.triple).join(', ')})
|
|
1182
|
+
needs: main
|
|
1183
|
+
${options.macosRunsOn === undefined ? ' runs-on: macos-latest' : renderRunsOnLine(options.macosRunsOn)}
|
|
1184
|
+
timeout-minutes: ${CROSS_TEST_JOB_TIMEOUT_MINUTES}
|
|
1185
|
+
if: \${{ needs.main.result == 'success' }}
|
|
1186
|
+
env:
|
|
1187
|
+
GH_TOKEN: \${{ github.token }}
|
|
1188
|
+
${remoteCacheJobEnvLines(options.remoteCache)}${cargoCredentialJobEnvLines(options.cargoCredentials)}${privateNpmReadTokenJobEnv(options)} steps:
|
|
1189
|
+
${renderCiWorkflowSteps(followUpSetupSteps(options, numbers), options)}
|
|
1190
|
+
${renderCiWorkflowSteps(middleSteps, options)}
|
|
1191
|
+
${renderCiWorkflowSteps(followUpCleanupStep(numbers), options)}`;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* The declared archives, checked against the naming the Nx graph would have
|
|
1196
|
+
* produced. A path that is not `cargoCrossTestArchiveFile(triple)` under some
|
|
1197
|
+
* project root cannot have come from that target, so it is refused here rather
|
|
1198
|
+
* than uploaded as an artifact nothing on the other side can find.
|
|
1199
|
+
*/
|
|
1200
|
+
function crossTestArchives(options: CiWorkflowDefinitionOptions): CiCrossTestArchive[] {
|
|
1201
|
+
return (options.crossTestArchives ?? []).map((archive) => {
|
|
1202
|
+
const suffix = cargoCrossTestArchiveFile(archive.triple);
|
|
1203
|
+
const path = archive.path.split('\\').join('/');
|
|
1204
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/.test(archive.triple)) {
|
|
1205
|
+
throw new Error(`smoo cross test archive triple must be a target triple, got ${JSON.stringify(archive.triple)}`);
|
|
1206
|
+
}
|
|
1207
|
+
if (path !== suffix && !path.endsWith(`/${suffix}`)) {
|
|
1208
|
+
throw new Error(
|
|
1209
|
+
`smoo cross test archive for ${archive.triple} must be a repository-relative ${suffix}, got ${archive.path}`,
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1212
|
+
if (path.startsWith('/') || path.split('/').includes('..')) {
|
|
1213
|
+
throw new Error(`smoo cross test archive path must stay inside the repository, got ${archive.path}`);
|
|
1214
|
+
}
|
|
1215
|
+
return { triple: archive.triple, path };
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
function crossArchiveTargetNames(options: CiWorkflowDefinitionOptions): string[] {
|
|
1220
|
+
return crossTestArchives(options).map((archive) => cargoCrossTestArchiveTargetName(archive.triple));
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* The declared preflight, as lines. A declaration with nothing in it is a
|
|
1225
|
+
* mechanism error, and it surfaces here at render time rather than as a step
|
|
1226
|
+
* whose `run:` block is empty.
|
|
1227
|
+
*/
|
|
1228
|
+
function crossToolchainPreflight(options: CiWorkflowDefinitionOptions): string[] {
|
|
1229
|
+
const preflight = options.platformProducer?.preflight ?? '';
|
|
1230
|
+
if (preflight.trim().length === 0) {
|
|
1231
|
+
throw new Error('smoo.github.platformProducer requires a nonempty toolchain preflight command.');
|
|
1232
|
+
}
|
|
1233
|
+
return preflight.split('\n');
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
/** The producer environment, step-scoped, quoted exactly as the publish workflow quotes it. */
|
|
1237
|
+
function platformProducerStepEnvLines(options: CiWorkflowDefinitionOptions): string[] {
|
|
1238
|
+
const entries = Object.entries(options.platformProducer?.env ?? {});
|
|
1239
|
+
if (entries.length === 0) return [];
|
|
1240
|
+
return [' env:', ...entries.map(([name, value]) => ` ${name}: ${JSON.stringify(value)}`)];
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
function darwinCrossTestArchives(options: CiWorkflowDefinitionOptions): CiCrossTestArchive[] {
|
|
1244
|
+
return crossTestArchives(options).filter((archive) => archive.triple.endsWith(DARWIN_TRIPLE_SUFFIX));
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
function darwinCrossTestTargetNames(options: CiWorkflowDefinitionOptions): string[] {
|
|
1248
|
+
return darwinCrossTestArchives(options).map((archive) => cargoCrossTestTargetName(archive.triple));
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* Where the download lands. upload-artifact roots an artifact at the least
|
|
1253
|
+
* common ancestor of the files it uploaded, so every archive in one artifact
|
|
1254
|
+
* has to share a parent directory for the restored layout to be the one the
|
|
1255
|
+
* runner targets read — true for one cargo workspace, false the moment a
|
|
1256
|
+
* second one also declares cross targets, which is refused here instead of
|
|
1257
|
+
* silently restoring the archives one directory too high.
|
|
1258
|
+
*/
|
|
1259
|
+
function crossTestArchiveDirectory(options: CiWorkflowDefinitionOptions): string {
|
|
1260
|
+
const directories = new Set(
|
|
1261
|
+
darwinCrossTestArchives(options).map((archive) => archive.path.slice(0, archive.path.lastIndexOf('/') + 1) || './'),
|
|
1262
|
+
);
|
|
1263
|
+
if (directories.size > 1) {
|
|
1264
|
+
throw new Error(
|
|
1265
|
+
`smoo cross test archives must share one directory to travel as one artifact, got ${[...directories].join(', ')}`,
|
|
1266
|
+
);
|
|
1267
|
+
}
|
|
1268
|
+
const [directory] = [...directories];
|
|
1269
|
+
return (directory ?? './').replace(/\/$/, '');
|
|
1270
|
+
}
|
|
1271
|
+
|
|
997
1272
|
function renderE2eDeploymentJob(options: CiWorkflowDefinitionOptions): string {
|
|
998
1273
|
if (!options.e2eDeployment) return '';
|
|
999
1274
|
const numbers = followUpStepNumbers(options);
|
|
@@ -8,6 +8,7 @@ import fc from 'fast-check';
|
|
|
8
8
|
import { type NxProjects, targetNamesFromProjects } from '../nx/index.js';
|
|
9
9
|
import {
|
|
10
10
|
anyProjectHasTagForTest,
|
|
11
|
+
crossTestArchivesForTest,
|
|
11
12
|
DEVENV_MODULE_IMPORT,
|
|
12
13
|
deployTargetInfoFromProjects,
|
|
13
14
|
extractInlineLocalBlocksForTest,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
LOCAL_SECTION_MARKER,
|
|
18
19
|
type ManagedFileContext,
|
|
19
20
|
macosPlatformArchitecturesForTest,
|
|
21
|
+
managedFileTargetsForContext,
|
|
20
22
|
managedFileTargetsForTest,
|
|
21
23
|
platformTargetGlobsForTest,
|
|
22
24
|
reinsertInlineLocalBlocksForTest,
|
|
@@ -205,6 +207,31 @@ describe('managed publish platform discovery', () => {
|
|
|
205
207
|
expect(macosPlatformArchitecturesForTest(['simulator-arm64-ios', 'cli-arm64-macos'])).toEqual(['arm64']);
|
|
206
208
|
expect(macosPlatformArchitecturesForTest(['build', 'cli-x64-linux', 'test'])).toEqual([]);
|
|
207
209
|
});
|
|
210
|
+
|
|
211
|
+
it('reads cross-built archives out of the graph, at each project root', () => {
|
|
212
|
+
expect(
|
|
213
|
+
crossTestArchivesForTest({
|
|
214
|
+
'@acme/codebase': {
|
|
215
|
+
root: '.',
|
|
216
|
+
targets: { 'cargo-cross-test-archive-aarch64-apple-darwin': {}, 'cargo-test-archive': {}, test: {} },
|
|
217
|
+
},
|
|
218
|
+
'acme-embedded': {
|
|
219
|
+
root: 'packages/embedded',
|
|
220
|
+
targets: { 'cargo-cross-test-archive-thumbv7em-none-eabihf': {} },
|
|
221
|
+
},
|
|
222
|
+
'acme-web': { root: 'packages/web', targets: { build: {}, 'cargo-cross-test-aarch64-apple-darwin': {} } },
|
|
223
|
+
}),
|
|
224
|
+
).toEqual([
|
|
225
|
+
{ triple: 'aarch64-apple-darwin', path: 'target/nextest/archive-aarch64-apple-darwin.tar.zst' },
|
|
226
|
+
{
|
|
227
|
+
triple: 'thumbv7em-none-eabihf',
|
|
228
|
+
path: 'packages/embedded/target/nextest/archive-thumbv7em-none-eabihf.tar.zst',
|
|
229
|
+
},
|
|
230
|
+
]);
|
|
231
|
+
// A repository with no cross declaration has no such target, so the CI
|
|
232
|
+
// renderer gets an empty list and renders the workflow it renders today.
|
|
233
|
+
expect(crossTestArchivesForTest({ '@acme/codebase': { root: '.', targets: { test: {} } } })).toEqual([]);
|
|
234
|
+
});
|
|
208
235
|
});
|
|
209
236
|
|
|
210
237
|
describe('managed devenv module import', () => {
|
|
@@ -237,14 +264,10 @@ describe('nx graph project helpers', () => {
|
|
|
237
264
|
},
|
|
238
265
|
},
|
|
239
266
|
app: {
|
|
267
|
+
// What the plugin infers for a private wrangler project, and what a published library
|
|
268
|
+
// holding a wrangler manifest used to get: a deploy target no tag enrols in CI.
|
|
240
269
|
targets: {
|
|
241
|
-
deploy: {
|
|
242
|
-
options: { command: 'echo no' },
|
|
243
|
-
configurations: {
|
|
244
|
-
staging: { command: 'wrangler deploy --env staging' },
|
|
245
|
-
production: { options: { command: 'wrangler deploy --env production' } },
|
|
246
|
-
},
|
|
247
|
-
},
|
|
270
|
+
deploy: { options: { command: 'smoo wrangler deploy-stage --stage {args.stage}' } },
|
|
248
271
|
'package-macos': {},
|
|
249
272
|
},
|
|
250
273
|
},
|
|
@@ -270,43 +293,40 @@ describe('nx graph project helpers', () => {
|
|
|
270
293
|
expect(hasExactTargetForTest(nearMisses, 'e2e-deployment')).toBe(false);
|
|
271
294
|
});
|
|
272
295
|
|
|
273
|
-
it('
|
|
274
|
-
expect(deployTargetInfoFromProjects(sampleProjects, 'staging')).toEqual({
|
|
275
|
-
|
|
276
|
-
provider: 'cloudflare',
|
|
277
|
-
});
|
|
278
|
-
expect(deployTargetInfoFromProjects(sampleProjects, 'production')).toEqual({
|
|
279
|
-
exists: true,
|
|
280
|
-
provider: 'cloudflare',
|
|
281
|
-
});
|
|
282
|
-
expect(deployTargetInfoFromProjects(sampleProjects, 'preview')).toEqual({ exists: false });
|
|
296
|
+
it('deploys nothing for a wrangler deploy target no tag names', () => {
|
|
297
|
+
expect(deployTargetInfoFromProjects(sampleProjects, 'staging')).toEqual({ exists: false });
|
|
298
|
+
expect(deployTargetInfoFromProjects(sampleProjects, 'production')).toEqual({ exists: false });
|
|
283
299
|
});
|
|
284
300
|
|
|
285
|
-
it('
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
},
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
};
|
|
301
|
+
it('reads the tags as precedence: permanent excludes, staging narrows, stage generalizes', () => {
|
|
302
|
+
const deploy = { options: { command: 'smoo wrangler deploy-stage --stage {args.stage}' } };
|
|
303
|
+
const stageFor = (tags: string[]) => ({
|
|
304
|
+
staging: deployTargetInfoFromProjects({ site: { tags, targets: { deploy } } }, 'staging').exists,
|
|
305
|
+
production: deployTargetInfoFromProjects({ site: { tags, targets: { deploy } } }, 'production').exists,
|
|
306
|
+
});
|
|
295
307
|
|
|
296
|
-
expect(
|
|
297
|
-
expect(
|
|
308
|
+
expect(stageFor(['stage-deploy-target'])).toEqual({ staging: true, production: true });
|
|
309
|
+
expect(stageFor(['staging-deploy-target'])).toEqual({ staging: true, production: false });
|
|
310
|
+
expect(stageFor(['permanent-deploy-target'])).toEqual({ staging: false, production: false });
|
|
311
|
+
// Both spellings on one project is a contradiction; the exclusion wins, which is what
|
|
312
|
+
// `nx show projects --exclude=tag:permanent-deploy-target` does to it in CI too.
|
|
313
|
+
expect(stageFor(['permanent-deploy-target', 'stage-deploy-target'])).toEqual({
|
|
314
|
+
staging: false,
|
|
315
|
+
production: false,
|
|
316
|
+
});
|
|
317
|
+
expect(stageFor(['npm:private'])).toEqual({ staging: false, production: false });
|
|
298
318
|
});
|
|
299
319
|
|
|
300
|
-
it('
|
|
301
|
-
const
|
|
302
|
-
site: {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
},
|
|
320
|
+
it('reads the command for the provider only: which credentials the generated job needs', () => {
|
|
321
|
+
const cloudflare: NxProjects = {
|
|
322
|
+
site: { tags: ['stage-deploy-target'], targets: { deploy: { command: 'wrangler deploy --config dist/w.json' } } },
|
|
323
|
+
};
|
|
324
|
+
const elsewhere: NxProjects = {
|
|
325
|
+
site: { tags: ['stage-deploy-target'], targets: { deploy: { command: 'bun tooling/deploy-site.ts' } } },
|
|
306
326
|
};
|
|
307
327
|
|
|
308
|
-
expect(deployTargetInfoFromProjects(
|
|
309
|
-
expect(deployTargetInfoFromProjects(
|
|
328
|
+
expect(deployTargetInfoFromProjects(cloudflare, 'staging')).toEqual({ exists: true, provider: 'cloudflare' });
|
|
329
|
+
expect(deployTargetInfoFromProjects(elsewhere, 'staging')).toEqual({ exists: true, provider: undefined });
|
|
310
330
|
});
|
|
311
331
|
|
|
312
332
|
it('finds a tag carried by any project in the graph', () => {
|
|
@@ -461,6 +481,7 @@ const context = (overrides: Partial<ManagedFileContext>): ManagedFileContext =>
|
|
|
461
481
|
platformTargetGlobs: [],
|
|
462
482
|
releasePlatformTargetGlobs: [],
|
|
463
483
|
macosPlatformArchitectures: [],
|
|
484
|
+
crossTestArchives: [],
|
|
464
485
|
...overrides,
|
|
465
486
|
});
|
|
466
487
|
|
|
@@ -555,6 +576,44 @@ describe('CI workflow rendering by repo shape', () => {
|
|
|
555
576
|
expect(rendered).toContain(' deploy-production:');
|
|
556
577
|
});
|
|
557
578
|
|
|
579
|
+
it('renders no deploy job at all for a repo whose wrangler projects carry no deploy tag', () => {
|
|
580
|
+
// The regression this exists for: published libraries ship a wrangler manifest to document a
|
|
581
|
+
// Durable Object binding for their consumers, the plugin inferred a deploy target from each,
|
|
582
|
+
// and a repository that deploys nothing from CI grew a Deploy Stage step holding Cloudflare
|
|
583
|
+
// credentials, a deployments permission, and a preview-cleanup workflow.
|
|
584
|
+
const deploy = { options: { command: 'smoo wrangler deploy-stage --stage {args.stage}' } };
|
|
585
|
+
const projects: NxProjects = {
|
|
586
|
+
'acme-cloudflare': { tags: ['npm:private'], targets: { deploy } },
|
|
587
|
+
'acme-documents': { tags: ['npm:public'], targets: { deploy } },
|
|
588
|
+
// A private worker, deployed by hand from a developer's shell and never by CI.
|
|
589
|
+
'acme-service': { targets: { deploy } },
|
|
590
|
+
};
|
|
591
|
+
const staging = deployTargetInfoFromProjects(projects, 'staging');
|
|
592
|
+
const production = deployTargetInfoFromProjects(projects, 'production');
|
|
593
|
+
const shape = context({
|
|
594
|
+
hasStagingDeployTargets: staging.exists,
|
|
595
|
+
stagingDeployProvider: staging.provider,
|
|
596
|
+
hasProductionDeployTargets: production.exists,
|
|
597
|
+
productionDeployProvider: production.provider,
|
|
598
|
+
hasE2eDeploymentTargets: true,
|
|
599
|
+
});
|
|
600
|
+
const ci = renderManagedWorkflowForTest('ci-workflow', shape);
|
|
601
|
+
|
|
602
|
+
expect(ci).not.toContain('Deploy Stage');
|
|
603
|
+
expect(ci).not.toContain('deployments: write');
|
|
604
|
+
expect(ci).not.toContain('CLOUDFLARE_API_TOKEN');
|
|
605
|
+
expect(ci).not.toContain('e2e-deployment');
|
|
606
|
+
expect(renderManagedWorkflowForTest('publish-workflow', shape)).not.toContain('Deploy production');
|
|
607
|
+
expect(managedFileTargetsForContext(shape)).not.toContain('.github/workflows/pr-preview-cleanup.yml');
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
it('adds the preview cleanup workflow only where a cloudflare stage deploy makes preview stages', () => {
|
|
611
|
+
expect(managedFileTargetsForContext(deploying)).toContain('.github/workflows/pr-preview-cleanup.yml');
|
|
612
|
+
expect(managedFileTargetsForContext({ ...deploying, stagingDeployProvider: undefined })).not.toContain(
|
|
613
|
+
'.github/workflows/pr-preview-cleanup.yml',
|
|
614
|
+
);
|
|
615
|
+
});
|
|
616
|
+
|
|
558
617
|
it('threads environments and secrets from the context into the workflow', () => {
|
|
559
618
|
const rendered = renderManagedWorkflowForTest('ci-workflow', {
|
|
560
619
|
...deploying,
|