@smoothbricks/nx-plugin 0.4.20 โ 0.4.22
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 +89 -18
- package/dist/bin/smoo-nx-cargo-hash.js +32 -4
- package/dist/cargo-source-hash.d.ts +10 -1
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +251 -41
- package/dist/cargo-workspace.d.ts +0 -1
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +9 -2
- package/dist/ensure-built.d.ts +6 -5
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +227 -30
- package/dist/index.js +18 -10
- package/dist/managed-files/ci-workflow.d.ts +20 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +42 -13
- package/dist/managed-files/files.d.ts +1 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +8 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +37 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.js +34 -6
- package/dist/workspace-manifest.d.ts +3 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/managed/raw/tooling/direnv/setup-environment.ts +23 -91
- package/managed/raw/tooling/git-hooks/commit-msg.sh +6 -0
- package/managed/raw/tooling/git-hooks/pre-commit.sh +6 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +6 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +19 -7
- package/package.json +1 -1
- package/src/bin/smoo-nx-cargo-hash.ts +29 -5
- package/src/cargo-source-hash.test.ts +291 -1
- package/src/cargo-source-hash.ts +190 -28
- package/src/cargo-workspace.test.ts +17 -10
- package/src/cargo-workspace.ts +9 -3
- package/src/ensure-built.test.ts +87 -29
- package/src/ensure-built.ts +274 -29
- package/src/index.test.ts +117 -20
- package/src/index.ts +18 -11
- package/src/managed-files/ci-workflow.ts +45 -14
- package/src/managed-files/files.ts +9 -2
- package/src/managed-files/generator.test.ts +5 -1
- package/src/managed-files/github-host-cache-isolation.test.ts +32 -6
- package/src/managed-files/pr-preview-cleanup-workflow.ts +87 -6
- package/src/workspace-manifest.ts +3 -1
package/dist/cargo-workspace.js
CHANGED
|
@@ -174,7 +174,7 @@ export function createCargoInputsCache() {
|
|
|
174
174
|
}
|
|
175
175
|
export function cargoPackageTestInputs(options) {
|
|
176
176
|
const cache = options.cache ?? createCargoInputsCache();
|
|
177
|
-
const key = `${options.absoluteProjectRoot}\0${options.memberDir}
|
|
177
|
+
const key = `${options.absoluteProjectRoot}\0${options.memberDir}`;
|
|
178
178
|
const cached = cache.results.get(key);
|
|
179
179
|
if (cached !== undefined)
|
|
180
180
|
return cached;
|
|
@@ -182,7 +182,14 @@ export function cargoPackageTestInputs(options) {
|
|
|
182
182
|
cache.results.set(key, derived);
|
|
183
183
|
return derived;
|
|
184
184
|
}
|
|
185
|
-
async function deriveCargoPackageTestInputs({ workspaceRoot, absoluteProjectRoot, memberDir
|
|
185
|
+
async function deriveCargoPackageTestInputs({ workspaceRoot, absoluteProjectRoot, memberDir }, cache) {
|
|
186
|
+
// Every fileset is anchored at `{workspaceRoot}`, never `{projectRoot}`: Nx
|
|
187
|
+
// hashes a `{projectRoot}` glob against only the files its project OWNS, and
|
|
188
|
+
// a nested Nx project owns the crates under it. A repository-root cargo
|
|
189
|
+
// workspace whose members live in `packages/*` would then hash none of its
|
|
190
|
+
// members' sources, and its archive would cache-hit against edited crates
|
|
191
|
+
// while every per-crate runner reran on the stale binaries.
|
|
192
|
+
const inputRoot = posix.join('{workspaceRoot}', relative(workspaceRoot, absoluteProjectRoot).split(sep).join('/'));
|
|
186
193
|
const loadManifest = (path) => {
|
|
187
194
|
const normalized = resolve(path);
|
|
188
195
|
const cached = cache.manifests.get(normalized);
|
package/dist/ensure-built.d.ts
CHANGED
|
@@ -99,13 +99,14 @@ export declare function describeMiss(reason: MissReason): string;
|
|
|
99
99
|
*/
|
|
100
100
|
export declare function firstCacheMiss(tasks: readonly Task[], cachedCodeByHash: ReadonlyMap<string, number>): MissReason | null;
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
102
|
+
* The entries the daemon does not vouch for.
|
|
103
103
|
*
|
|
104
|
-
* `
|
|
105
|
-
* ragged array
|
|
106
|
-
* positive one, and being wrong here means exec'ing a binary
|
|
104
|
+
* `verdicts[index]` is the daemon's verdict for `entries[index]`. A short or
|
|
105
|
+
* ragged array leaves the remainder unvouched rather than cleared: a missing
|
|
106
|
+
* verdict is not a positive one, and being wrong here means exec'ing a binary
|
|
107
|
+
* that was deleted.
|
|
107
108
|
*/
|
|
108
|
-
export declare function
|
|
109
|
+
export declare function unvouched<Entry>(entries: readonly Entry[], verdicts: readonly boolean[]): Entry[];
|
|
109
110
|
/**
|
|
110
111
|
* Make sure an Nx target's outputs are on disk, doing as little as possible
|
|
111
112
|
* when they already are.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensure-built.d.ts","sourceRoot":"","sources":["../src/ensure-built.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ensure-built.d.ts","sourceRoot":"","sources":["../src/ensure-built.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,IAAI,EAAa,MAAM,0BAA0B,CAAC;AAqDhE;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5C;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,QAAQ,CAAC,IAAI,EAAE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;;;;OAIG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;CAC5B;AAOD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAWvE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAmBvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,gBAAgB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5C,UAAU,GAAG,IAAI,CAmBnB;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,OAAO,EAAE,GAAG,KAAK,EAAE,CAEjG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAmCzF;AAmnBD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;CACxC;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,SAAS,EACf,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,KAAK,MAAM,GACtD,iBAAiB,CAQnB"}
|
package/dist/ensure-built.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
3
|
+
import { closeSync, existsSync, lstatSync, openSync, readdirSync, readlinkSync, readSync } from 'node:fs';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
|
-
import { join, resolve } from 'node:path';
|
|
5
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
6
6
|
function createWorkspaceNxRequire(workspaceRoot) {
|
|
7
7
|
const requireFromWorkspace = createRequire(join(workspaceRoot, 'package.json'));
|
|
8
8
|
return function requireNx(specifier) {
|
|
@@ -74,19 +74,15 @@ export function firstCacheMiss(tasks, cachedCodeByHash) {
|
|
|
74
74
|
return null;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* The entries the daemon does not vouch for.
|
|
78
78
|
*
|
|
79
|
-
* `
|
|
80
|
-
* ragged array
|
|
81
|
-
* positive one, and being wrong here means exec'ing a binary
|
|
79
|
+
* `verdicts[index]` is the daemon's verdict for `entries[index]`. A short or
|
|
80
|
+
* ragged array leaves the remainder unvouched rather than cleared: a missing
|
|
81
|
+
* verdict is not a positive one, and being wrong here means exec'ing a binary
|
|
82
|
+
* that was deleted.
|
|
82
83
|
*/
|
|
83
|
-
export function
|
|
84
|
-
|
|
85
|
-
if (matches[index] !== true) {
|
|
86
|
-
return { kind: 'stale-outputs', taskId: tasks[index].id };
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return null;
|
|
84
|
+
export function unvouched(entries, verdicts) {
|
|
85
|
+
return entries.filter((_, index) => verdicts[index] !== true);
|
|
90
86
|
}
|
|
91
87
|
/**
|
|
92
88
|
* Make sure an Nx target's outputs are on disk, doing as little as possible
|
|
@@ -213,7 +209,7 @@ async function ensureBuiltInWorkspace(workspaceRoot, selector, onMiss) {
|
|
|
213
209
|
reason = { kind: 'stale-inputs', taskId: selectorTaskId };
|
|
214
210
|
}
|
|
215
211
|
else {
|
|
216
|
-
reason = await probe(nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx);
|
|
212
|
+
reason = await probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx);
|
|
217
213
|
}
|
|
218
214
|
performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
|
|
219
215
|
const outcome = reason === null
|
|
@@ -309,13 +305,14 @@ async function refreshWorkspaceContext(workspaceRoot, tasks, requireNx) {
|
|
|
309
305
|
return inputsChanged;
|
|
310
306
|
}
|
|
311
307
|
/** `null` when the target is already built; otherwise the first reason it is not. */
|
|
312
|
-
async function probe(nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx) {
|
|
308
|
+
async function probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx) {
|
|
313
309
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
314
310
|
const { DaemonBasedTaskHasher } = requireNx('nx/src/hasher/task-hasher');
|
|
315
311
|
const { getTaskDetails, hashTasks } = requireNx('nx/src/hasher/hash-task');
|
|
316
312
|
const { getTaskSpecificEnv } = requireNx('nx/src/tasks-runner/task-env');
|
|
317
313
|
const { getCache } = requireNx('nx/src/tasks-runner/cache');
|
|
318
314
|
const { getRunnerOptions } = requireNx('nx/src/tasks-runner/run-command');
|
|
315
|
+
const { getExecutorNameForTask } = requireNx('nx/src/tasks-runner/utils');
|
|
319
316
|
// `isCloudDefault: false` because these options are only read here by the
|
|
320
317
|
// hasher, which looks at `selectivelyHashTsConfig`; the cloud credentials the
|
|
321
318
|
// flag would add belong to the cloud runner, and the run path calls Nx's own
|
|
@@ -341,20 +338,28 @@ async function probe(nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx)
|
|
|
341
338
|
}
|
|
342
339
|
await hashTasks(hasher, projectGraph, taskGraph, perTaskEnvs, getTaskDetails(), tasks);
|
|
343
340
|
performance.measure('ensureBuilt:hash', 'ensureBuilt:hash:start');
|
|
341
|
+
// An `nx:noop` task has no command: Nx completes it without spawning
|
|
342
|
+
// anything, and normalizes a command-less target that only names dependencies
|
|
343
|
+
// to one. A cache record would vouch for no work โ the tasks it aggregates are
|
|
344
|
+
// in this graph and answer for themselves โ so none is required. Demanding one
|
|
345
|
+
// made every call through an uncacheable aggregate hand the whole graph to Nx,
|
|
346
|
+
// which replays each dependency's cached log. Outputs a noop declares are
|
|
347
|
+
// still verified below, with every other task's.
|
|
348
|
+
const recordedTasks = tasks.filter((task) => getExecutorNameForTask(task, projectGraph) !== 'nx:noop');
|
|
344
349
|
// Nx's own factory, but deliberately never `init()`ed: that is what makes
|
|
345
350
|
// this a local-only, side-effect-free question. `init()` attaches the remote
|
|
346
351
|
// cache โ a network round-trip, and a download is precisely the work this
|
|
347
352
|
// probe exists to detect โ and asserts that the cache directory matches the
|
|
348
|
-
// database. Neither matters here:
|
|
349
|
-
//
|
|
353
|
+
// database. Neither matters here: the directory is read only to compare
|
|
354
|
+
// outputs against, and an artifact missing from it is a miss.
|
|
350
355
|
performance.mark('ensureBuilt:cache:start');
|
|
351
356
|
const cache = getCache(runnerOptions);
|
|
352
|
-
const cachedResults = await cache.getBatch(
|
|
357
|
+
const cachedResults = await cache.getBatch(recordedTasks.filter((task) => task.cache && task.hash));
|
|
353
358
|
const cachedCodeByHash = new Map();
|
|
354
359
|
for (const [hash, result] of cachedResults) {
|
|
355
360
|
cachedCodeByHash.set(hash, result.code);
|
|
356
361
|
}
|
|
357
|
-
const cacheMiss = firstCacheMiss(
|
|
362
|
+
const cacheMiss = firstCacheMiss(recordedTasks, cachedCodeByHash);
|
|
358
363
|
performance.measure('ensureBuilt:cache', 'ensureBuilt:cache:start');
|
|
359
364
|
if (cacheMiss) {
|
|
360
365
|
return cacheMiss;
|
|
@@ -362,22 +367,214 @@ async function probe(nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx)
|
|
|
362
367
|
// A cache record only proves the task once succeeded with these inputs. The
|
|
363
368
|
// artifact this facility is about โ the binary that is about to be exec'd โ
|
|
364
369
|
// lives in the working tree, where anything may have deleted or rewritten it
|
|
365
|
-
// since.
|
|
366
|
-
//
|
|
367
|
-
const
|
|
368
|
-
const outputEntries = [];
|
|
370
|
+
// since. The daemon answers that cheaply from the output hashes it recorded
|
|
371
|
+
// when Nx last wrote them.
|
|
372
|
+
const claims = [];
|
|
369
373
|
for (const task of tasks) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
continue;
|
|
374
|
+
if (task.outputs.length > 0 && task.hash !== undefined) {
|
|
375
|
+
claims.push({ taskId: task.id, outputs: task.outputs, hash: task.hash });
|
|
373
376
|
}
|
|
374
|
-
withOutputs.push(task);
|
|
375
|
-
outputEntries.push({ outputs: task.outputs, hash });
|
|
376
377
|
}
|
|
377
378
|
performance.mark('ensureBuilt:outputs:start');
|
|
378
|
-
const
|
|
379
|
+
const verdicts = await daemonClient.outputsHashesMatchBatch(claims.map(({ outputs, hash }) => ({ outputs, hash })));
|
|
379
380
|
performance.measure('ensureBuilt:outputs', 'ensureBuilt:outputs:start');
|
|
380
|
-
|
|
381
|
+
const doubted = unvouched(claims, verdicts);
|
|
382
|
+
if (doubted.length === 0) {
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
// Its records are lossy, though, and a lost record is not a changed output.
|
|
386
|
+
// They live in memory, so a restart drops every one. They are kept per
|
|
387
|
+
// collapsed directory (Nx tracks at most three paths per level), so a write
|
|
388
|
+
// anywhere under `packages/` voids a task whose outputs span four projects.
|
|
389
|
+
// And a write the daemon processes more than 2 s after a record erases it,
|
|
390
|
+
// which a daemon busy hashing does to a restore's own writes โ so each
|
|
391
|
+
// restore guarantees the next one. What settles the question is what a hit
|
|
392
|
+
// would restore: Nx's own local artifact for this exact hash. A working tree
|
|
393
|
+
// that already holds every entry of it is what the restore would leave.
|
|
394
|
+
// Anything else โ no artifact, a difference, an error while reading โ stays
|
|
395
|
+
// a miss.
|
|
396
|
+
performance.mark('ensureBuilt:artifacts:start');
|
|
397
|
+
const { expandOutputs } = requireNx('nx/src/native');
|
|
398
|
+
const comparison = {
|
|
399
|
+
expandOutputs,
|
|
400
|
+
left: Buffer.allocUnsafe(COMPARE_CHUNK_BYTES),
|
|
401
|
+
right: Buffer.allocUnsafe(COMPARE_CHUNK_BYTES),
|
|
402
|
+
observed: [],
|
|
403
|
+
realDirectories: new Set(),
|
|
404
|
+
};
|
|
405
|
+
for (const claim of doubted) {
|
|
406
|
+
// `recordedTasks` excludes `nx:noop`, so a noop's declared outputs have no
|
|
407
|
+
// artifact here and stay a miss.
|
|
408
|
+
const artifact = cachedResults.get(claim.hash);
|
|
409
|
+
if (artifact === undefined || !outputsMatchArtifact(comparison, workspaceRoot, artifact.outputsPath, claim)) {
|
|
410
|
+
return { kind: 'stale-outputs', taskId: claim.taskId };
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
// A write that landed while the bytes were being compared would otherwise be
|
|
414
|
+
// recorded as current.
|
|
415
|
+
const movedBeforeRecord = firstMovedClaim(comparison.observed);
|
|
416
|
+
if (movedBeforeRecord !== null) {
|
|
417
|
+
return { kind: 'stale-outputs', taskId: movedBeforeRecord };
|
|
418
|
+
}
|
|
419
|
+
// Re-arm the daemon the way Nx's runner does after restoring outputs, so the
|
|
420
|
+
// next call is back on the cheap path.
|
|
421
|
+
await daemonClient.recordOutputsHashBatch(doubted.map(({ outputs, hash }) => ({ outputs, hash })));
|
|
422
|
+
const movedDuringRecord = firstMovedClaim(comparison.observed);
|
|
423
|
+
performance.measure('ensureBuilt:artifacts', 'ensureBuilt:artifacts:start');
|
|
424
|
+
return movedDuringRecord === null ? null : { kind: 'stale-outputs', taskId: movedDuringRecord };
|
|
425
|
+
}
|
|
426
|
+
/** Read size for byte comparison: large enough to stream a binary quickly, small enough never to load one whole. */
|
|
427
|
+
const COMPARE_CHUNK_BYTES = 1 << 20;
|
|
428
|
+
/**
|
|
429
|
+
* Whether restoring `claim` from the artifact would leave the working tree as
|
|
430
|
+
* it is.
|
|
431
|
+
*
|
|
432
|
+
* The entries are the ones Nx's restore copies: `expandOutputs` over the
|
|
433
|
+
* artifact root with the task's outputs, globs and negations included. That
|
|
434
|
+
* walk is bounded by the artifact, which holds nothing but outputs, and it
|
|
435
|
+
* needs no reading of the pattern here. A restore replaces each entry whole
|
|
436
|
+
* and touches nothing else, so a working-tree file that matches a glob but is
|
|
437
|
+
* absent from the artifact survives it and is no difference. An output path
|
|
438
|
+
* Nx would refuse to restore (absolute, or climbing out with `..`), an
|
|
439
|
+
* artifact holding no entry at all, and system errors while reading are all
|
|
440
|
+
* misses.
|
|
441
|
+
*/
|
|
442
|
+
function outputsMatchArtifact(comparison, workspaceRoot, artifactRoot, claim) {
|
|
443
|
+
if (claim.outputs.some((output) => isAbsolute(output) || output.split('/').includes('..'))) {
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
try {
|
|
447
|
+
const entries = comparison.expandOutputs(artifactRoot, claim.outputs);
|
|
448
|
+
return (entries.length > 0 &&
|
|
449
|
+
entries.every((entry) => throughRealDirectories(comparison.realDirectories, workspaceRoot, entry) &&
|
|
450
|
+
sameTree(comparison, claim.taskId, join(workspaceRoot, entry), join(artifactRoot, entry))));
|
|
451
|
+
}
|
|
452
|
+
catch (error) {
|
|
453
|
+
if (isSystemError(error)) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Whether every directory between the workspace root and `entry` is a real
|
|
461
|
+
* directory. A restore realizes a symlinked parent as a directory, so reading
|
|
462
|
+
* an entry through one would compare bytes the restore does not leave there โ
|
|
463
|
+
* and would read the filesystem behind a link.
|
|
464
|
+
*/
|
|
465
|
+
function throughRealDirectories(realDirectories, workspaceRoot, entry) {
|
|
466
|
+
let directory = workspaceRoot;
|
|
467
|
+
const segments = entry.split('/');
|
|
468
|
+
for (const segment of segments.slice(0, -1)) {
|
|
469
|
+
directory = join(directory, segment);
|
|
470
|
+
if (realDirectories.has(directory)) {
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
if (lstatSync(directory, { throwIfNoEntry: false })?.isDirectory() !== true) {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
realDirectories.add(directory);
|
|
477
|
+
}
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Whether `actual` is `expected` as a restore would recreate it: same node
|
|
482
|
+
* type; a symlink by its text, never followed, because the link is what Nx
|
|
483
|
+
* stores and restores; a file by permission bits and bytes; a directory by its
|
|
484
|
+
* entry names and each entry in turn. Every working-tree node compared is
|
|
485
|
+
* observed, so a write during the comparison can be caught afterwards.
|
|
486
|
+
*/
|
|
487
|
+
function sameTree(comparison, taskId, actual, expected) {
|
|
488
|
+
const actualStats = lstatSync(actual, { bigint: true, throwIfNoEntry: false });
|
|
489
|
+
const expectedStats = lstatSync(expected, { bigint: true, throwIfNoEntry: false });
|
|
490
|
+
if (actualStats === undefined || expectedStats === undefined) {
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
comparison.observed.push({ taskId, path: actual, stats: actualStats });
|
|
494
|
+
if (expectedStats.isSymbolicLink()) {
|
|
495
|
+
return actualStats.isSymbolicLink() && readlinkSync(actual) === readlinkSync(expected);
|
|
496
|
+
}
|
|
497
|
+
if (expectedStats.isFile()) {
|
|
498
|
+
return (actualStats.isFile() &&
|
|
499
|
+
actualStats.size === expectedStats.size &&
|
|
500
|
+
(actualStats.mode & 4095n) === (expectedStats.mode & 4095n) &&
|
|
501
|
+
sameBytes(comparison, actual, expected, Number(expectedStats.size)));
|
|
502
|
+
}
|
|
503
|
+
if (expectedStats.isDirectory()) {
|
|
504
|
+
if (!actualStats.isDirectory()) {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
const names = readdirSync(actual).sort();
|
|
508
|
+
const expectedNames = readdirSync(expected).sort();
|
|
509
|
+
if (names.length !== expectedNames.length) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
for (let index = 0; index < names.length; index += 1) {
|
|
513
|
+
if (names[index] !== expectedNames[index]) {
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return names.every((name) => sameTree(comparison, taskId, join(actual, name), join(expected, name)));
|
|
518
|
+
}
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
/** Byte equality of two files already known to be `size` bytes, streamed through the comparison's buffers. */
|
|
522
|
+
function sameBytes(comparison, actual, expected, size) {
|
|
523
|
+
const actualFd = openSync(actual, 'r');
|
|
524
|
+
try {
|
|
525
|
+
const expectedFd = openSync(expected, 'r');
|
|
526
|
+
try {
|
|
527
|
+
for (let offset = 0; offset < size; offset += COMPARE_CHUNK_BYTES) {
|
|
528
|
+
const length = Math.min(COMPARE_CHUNK_BYTES, size - offset);
|
|
529
|
+
// A short read means the file changed length since it was sized.
|
|
530
|
+
if (readSync(actualFd, comparison.left, 0, length, offset) !== length ||
|
|
531
|
+
readSync(expectedFd, comparison.right, 0, length, offset) !== length ||
|
|
532
|
+
comparison.left.compare(comparison.right, 0, length, 0, length) !== 0) {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
finally {
|
|
539
|
+
closeSync(expectedFd);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
finally {
|
|
543
|
+
closeSync(actualFd);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* The task owning the first observed node that is no longer the node it was
|
|
548
|
+
* compared as: replaced (device, inode), rewritten (size, mtime) or otherwise
|
|
549
|
+
* touched (mode, ctime).
|
|
550
|
+
*/
|
|
551
|
+
function firstMovedClaim(observed) {
|
|
552
|
+
for (const { taskId, path, stats } of observed) {
|
|
553
|
+
let current;
|
|
554
|
+
try {
|
|
555
|
+
current = lstatSync(path, { bigint: true, throwIfNoEntry: false });
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
if (isSystemError(error)) {
|
|
559
|
+
return taskId;
|
|
560
|
+
}
|
|
561
|
+
throw error;
|
|
562
|
+
}
|
|
563
|
+
if (current === undefined ||
|
|
564
|
+
current.dev !== stats.dev ||
|
|
565
|
+
current.ino !== stats.ino ||
|
|
566
|
+
current.mode !== stats.mode ||
|
|
567
|
+
current.size !== stats.size ||
|
|
568
|
+
current.mtimeNs !== stats.mtimeNs ||
|
|
569
|
+
current.ctimeNs !== stats.ctimeNs) {
|
|
570
|
+
return taskId;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return null;
|
|
574
|
+
}
|
|
575
|
+
/** An operating-system or native-binding failure, as opposed to a programming error. */
|
|
576
|
+
function isSystemError(error) {
|
|
577
|
+
return error instanceof Error && 'code' in error && typeof error.code === 'string';
|
|
381
578
|
}
|
|
382
579
|
async function runTarget(nxJson, nxArgs, overrides, selector, reason, requireNx) {
|
|
383
580
|
const { runCommandForTasks } = requireNx('nx/src/tasks-runner/run-command');
|
package/dist/index.js
CHANGED
|
@@ -1361,20 +1361,26 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1361
1361
|
options: { command: WRANGLER_DEPLOY_COMMAND, cwd: projectRoot },
|
|
1362
1362
|
};
|
|
1363
1363
|
}
|
|
1364
|
-
//
|
|
1365
|
-
// under dist belongs to the concrete target that
|
|
1366
|
-
// `{projectRoot}/dist` here would cache the children's
|
|
1367
|
-
// under the aggregate's hash, and would make `smoo
|
|
1368
|
-
// --collect-outputs` attribute to `build` whatever sits
|
|
1369
|
-
// platform-target artifacts the collect excludes on
|
|
1370
|
-
// artifacts of targets that never ran. Two collected trees
|
|
1371
|
-
// binary and `apply-outputs` rejects the overlap.
|
|
1364
|
+
// Empty `outputs`, deliberately and explicitly: this aggregate runs no
|
|
1365
|
+
// command, so every file under dist belongs to the concrete target that
|
|
1366
|
+
// emitted it. Claiming `{projectRoot}/dist` here would cache the children's
|
|
1367
|
+
// bytes a second time under the aggregate's hash, and would make `smoo
|
|
1368
|
+
// github-ci nx-run-many --collect-outputs` attribute to `build` whatever sits
|
|
1369
|
+
// under dist โ including platform-target artifacts the collect excludes on
|
|
1370
|
+
// purpose and stale artifacts of targets that never ran. Two collected trees
|
|
1371
|
+
// then claim one binary and `apply-outputs` rejects the overlap. Omitting the
|
|
1372
|
+
// key is not the same thing: Nx gives a `build` or `prepare` target without
|
|
1373
|
+
// `outputs` its legacy defaults (`{projectRoot}/dist`, `/build`, `/public`,
|
|
1374
|
+
// `dist/{projectRoot}`), so a cache hit on the aggregate โ whose key does
|
|
1375
|
+
// not move when only a child's own inputs do โ restored the children's
|
|
1376
|
+
// previous dist over what they had just emitted. `lint` and `test` are
|
|
1372
1377
|
// aggregates on the same terms. Same reason nx.json must not put `outputs` in
|
|
1373
1378
|
// targetDefaults.build (see validateBuildTargetDefault).
|
|
1374
1379
|
if (hasOrdinaryBuildOutputTarget) {
|
|
1375
1380
|
targets.build = {
|
|
1376
1381
|
executor: 'nx:noop',
|
|
1377
1382
|
cache: true,
|
|
1383
|
+
outputs: [],
|
|
1378
1384
|
// `cargo-napi` is both an output family and a serialized cargo writer, so
|
|
1379
1385
|
// the two sources overlap; the Set keeps one edge per target while holding
|
|
1380
1386
|
// the order the families are listed in.
|
|
@@ -1967,7 +1973,10 @@ async function addCargoTestTargets(targets, currentProjectName, projectRoot, wor
|
|
|
1967
1973
|
if (plan.package.projectRoot !== projectRoot) {
|
|
1968
1974
|
continue;
|
|
1969
1975
|
}
|
|
1970
|
-
|
|
1976
|
+
// Workspace-anchored for the reason `cargoPackageTestInputs` gives: a
|
|
1977
|
+
// `{projectRoot}` glob hashes only files this project owns, and sibling
|
|
1978
|
+
// manifests belong to whichever nested project holds them.
|
|
1979
|
+
const inputRoot = posix.join('{workspaceRoot}', workspace.projectRoot);
|
|
1971
1980
|
// A workspace nextest build unifies features across every selected member.
|
|
1972
1981
|
// A sibling manifest can therefore change this crate's tests without being
|
|
1973
1982
|
// a path dependency. Track those manifests, not unrelated sibling sources.
|
|
@@ -1981,7 +1990,6 @@ async function addCargoTestTargets(targets, currentProjectName, projectRoot, wor
|
|
|
1981
1990
|
workspaceRoot,
|
|
1982
1991
|
absoluteProjectRoot: join(workspaceRoot, workspace.projectRoot),
|
|
1983
1992
|
memberDir: plan.package.dir,
|
|
1984
|
-
inputRoot,
|
|
1985
1993
|
cache: workspace.inputsCache,
|
|
1986
1994
|
})),
|
|
1987
1995
|
...workspace.packages.map((member) => posix.join(inputRoot, member.package.dir, 'Cargo.toml')),
|
|
@@ -133,6 +133,17 @@ export interface CiWorkflowDefinitionOptions extends DeployStepSecretConfig {
|
|
|
133
133
|
platformProducer?: PackageSmooGithub['platformProducer'];
|
|
134
134
|
}
|
|
135
135
|
export declare function defineCiWorkflow(options: CiWorkflowDefinitionOptions): CiWorkflowStep[];
|
|
136
|
+
/**
|
|
137
|
+
* CI's concurrency group: one per pull request, by its number, and one per ref
|
|
138
|
+
* for pushes. The PR preview cleanup joins the same group, so a pull request's
|
|
139
|
+
* close cancels its running CI and the cleanup starts only after that run's
|
|
140
|
+
* stage deploy has stopped. The number, not `github.ref`, names a pull
|
|
141
|
+
* request's group: a close that merged it carries the base branch's ref, which
|
|
142
|
+
* would put the cleanup in the base branch's own group, and a forge may spell a
|
|
143
|
+
* pull request's ref after its merge or after its head. Spelled literally
|
|
144
|
+
* rather than from `github.workflow`, which a forge may fill with the file name.
|
|
145
|
+
*/
|
|
146
|
+
export declare const CI_CONCURRENCY_GROUP = "CI-${{ github.event.pull_request.number || github.ref }}";
|
|
136
147
|
export declare function renderCiWorkflowYaml(options: CiWorkflowDefinitionOptions): string;
|
|
137
148
|
/** Job env for `.npmrc` token expansion. Registry URL is not a GitHub variable. */
|
|
138
149
|
export declare function privateNpmReadTokenJobEnv(options: Pick<CiWorkflowDefinitionOptions, 'privateNpm'>): string;
|
|
@@ -199,6 +210,8 @@ export declare function normalizeCargoCredentials(config: PackageCargoCredential
|
|
|
199
210
|
* checked-in managed output byte-identical across regeneration and hooks.
|
|
200
211
|
*/
|
|
201
212
|
export declare const SAME_REPO_GATE_FOLDED: string[];
|
|
213
|
+
/** A job's `environment:` line, or nothing when no GitHub Environment is declared. */
|
|
214
|
+
export declare function environmentLine(name: string | undefined): string;
|
|
202
215
|
/**
|
|
203
216
|
* The step-scoped `env:` block for a deploy step. Step scope is the property
|
|
204
217
|
* being rendered, not an accident of indentation: job env would hand the
|
|
@@ -211,5 +224,12 @@ export declare const SAME_REPO_GATE_FOLDED: string[];
|
|
|
211
224
|
* once in `deploySecrets` instead of being overridden here.
|
|
212
225
|
*/
|
|
213
226
|
export declare function deployStepSecretEnvLines(config: DeployStepSecretConfig): string[];
|
|
227
|
+
/**
|
|
228
|
+
* The step env for a step that acts on Cloudflare as the stage deploy did: the
|
|
229
|
+
* two Cloudflare credentials, read from the secrets `deployStepSecretEnvLines`
|
|
230
|
+
* names for them, and none of the other deploy secrets, which such a step
|
|
231
|
+
* never uses.
|
|
232
|
+
*/
|
|
233
|
+
export declare function cloudflareCredentialEnvLines(deploySecrets: Record<string, string> | undefined): string[];
|
|
214
234
|
export declare function artifactStepLines(provider: PackageSmooGithub['actionsProvider'], name: string, kind: 'upload' | 'download', inputs: readonly string[], condition?: string): string[];
|
|
215
235
|
//# sourceMappingURL=ci-workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ci-workflow.d.ts","sourceRoot":"","sources":["../../src/managed-files/ci-workflow.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,aAAa,EACb,6BAA6B,EAE7B,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,EACjB,6BAA6B,EAC7B,2BAA2B,EAC5B,MAAM,0BAA0B,CAAC;AAGlC,oBAAY,kBAAkB;IAC5B,QAAQ,aAAa;IACrB,eAAe,qBAAqB;IACpC,WAAW,iBAAiB;IAC5B,gBAAgB,sBAAsB;IACtC,SAAS,gBAAgB;IACzB,cAAc,qBAAqB;IACnC,KAAK,UAAU;IACf,YAAY,kBAAkB;IAC9B,IAAI,SAAS;IACb,SAAS,eAAe;IACxB,uBAAuB,8BAA8B;IACrD,iBAAiB,wBAAwB;IACz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FAAsF;AACtF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAEhE;AAQD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,EAAE,CAGjF;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,MAAM,EAAE,CAMxG;AAmRD,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,EAC9C,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,GAAG,UAAU,EAC3B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,SAAS,SAAc,GACtB,MAAM,EAAE,CAmBV"}
|
|
@@ -63,6 +63,17 @@ export function defineCiWorkflow(options) {
|
|
|
63
63
|
steps.push({ kind: CiWorkflowStepKind.ManagedFilesCheck, name: '๐ฉบ Check managed-file drift' }, { kind: CiWorkflowStepKind.ManagedFilesDispatch, name: '๐ Dispatch managed-file drift healing' }, { kind: CiWorkflowStepKind.SaveNxCache, name: '๐พ Save Nx cache' }, { kind: CiWorkflowStepKind.UploadTraceDbs, name: '๐ Upload trace DBs' }, { kind: CiWorkflowStepKind.SaveNixDevenv, name: '๐งน Cleanup and cache Nix/devenv' });
|
|
64
64
|
return steps.map((step, index) => ({ ...step, number: index + 2 }));
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* CI's concurrency group: one per pull request, by its number, and one per ref
|
|
68
|
+
* for pushes. The PR preview cleanup joins the same group, so a pull request's
|
|
69
|
+
* close cancels its running CI and the cleanup starts only after that run's
|
|
70
|
+
* stage deploy has stopped. The number, not `github.ref`, names a pull
|
|
71
|
+
* request's group: a close that merged it carries the base branch's ref, which
|
|
72
|
+
* would put the cleanup in the base branch's own group, and a forge may spell a
|
|
73
|
+
* pull request's ref after its merge or after its head. Spelled literally
|
|
74
|
+
* rather than from `github.workflow`, which a forge may fill with the file name.
|
|
75
|
+
*/
|
|
76
|
+
export const CI_CONCURRENCY_GROUP = 'CI-${{ github.event.pull_request.number || github.ref }}';
|
|
66
77
|
export function renderCiWorkflowYaml(options) {
|
|
67
78
|
const steps = defineCiWorkflow(options);
|
|
68
79
|
return [
|
|
@@ -90,17 +101,18 @@ ${options.deploy ? ' deployments: write\n' : ''} statuses: write
|
|
|
90
101
|
|
|
91
102
|
concurrency:
|
|
92
103
|
${options.deploy
|
|
93
|
-
? ` # One in-flight run per
|
|
94
|
-
# running workflow instead of canceling it,
|
|
95
|
-
# deploy job mid-flight. Pull requests and
|
|
96
|
-
# superseded runs.
|
|
97
|
-
group:
|
|
104
|
+
? ` # One in-flight run per pull request, and per ref for pushes. Pushes to the
|
|
105
|
+
# staging push branch queue behind a running workflow instead of canceling it,
|
|
106
|
+
# so a newer push never cancels the deploy job mid-flight. Pull requests and
|
|
107
|
+
# other branches keep canceling superseded runs.
|
|
108
|
+
group: ${CI_CONCURRENCY_GROUP}
|
|
98
109
|
cancel-in-progress: \${{ github.ref != ${stagingRefLiteral(options)} }}`
|
|
99
110
|
: ` # This workflow validates and never deploys, so there is no in-flight
|
|
100
|
-
# deployment for a newer push to protect: every
|
|
101
|
-
# runs. Queuing them instead serializes
|
|
102
|
-
#
|
|
103
|
-
|
|
111
|
+
# deployment for a newer push to protect: every pull request, and every ref
|
|
112
|
+
# for pushes, cancels its superseded runs. Queuing them instead serializes
|
|
113
|
+
# the staging branch, and a burst of pushes then reports the newest commit
|
|
114
|
+
# one full run per queued push late.
|
|
115
|
+
group: ${CI_CONCURRENCY_GROUP}
|
|
104
116
|
cancel-in-progress: true`}
|
|
105
117
|
|
|
106
118
|
defaults:
|
|
@@ -806,9 +818,15 @@ function yamlScalar(value) {
|
|
|
806
818
|
function stagingRefLiteral(options) {
|
|
807
819
|
return `'refs/heads/${stagingPushBranch(options).replaceAll("'", "''")}'`;
|
|
808
820
|
}
|
|
809
|
-
|
|
821
|
+
/** A job's `environment:` line, or nothing when no GitHub Environment is declared. */
|
|
822
|
+
export function environmentLine(name) {
|
|
810
823
|
return name ? ` environment: ${yamlScalar(name)}\n` : '';
|
|
811
824
|
}
|
|
825
|
+
/** The Cloudflare credentials a deploy step carries, env var name โ default repository secret name. */
|
|
826
|
+
const CLOUDFLARE_DEPLOY_SECRETS = {
|
|
827
|
+
CLOUDFLARE_API_TOKEN: 'CLOUDFLARE_API_TOKEN',
|
|
828
|
+
CLOUDFLARE_ACCOUNT_ID: 'CLOUDFLARE_ACCOUNT_ID',
|
|
829
|
+
};
|
|
812
830
|
/**
|
|
813
831
|
* The step-scoped `env:` block for a deploy step. Step scope is the property
|
|
814
832
|
* being rendered, not an accident of indentation: job env would hand the
|
|
@@ -821,11 +839,22 @@ function environmentLine(name) {
|
|
|
821
839
|
* once in `deploySecrets` instead of being overridden here.
|
|
822
840
|
*/
|
|
823
841
|
export function deployStepSecretEnvLines(config) {
|
|
824
|
-
const cloudflare = config.deployProvider === 'cloudflare'
|
|
825
|
-
? { CLOUDFLARE_API_TOKEN: 'CLOUDFLARE_API_TOKEN', CLOUDFLARE_ACCOUNT_ID: 'CLOUDFLARE_ACCOUNT_ID' }
|
|
826
|
-
: {};
|
|
842
|
+
const cloudflare = config.deployProvider === 'cloudflare' ? CLOUDFLARE_DEPLOY_SECRETS : {};
|
|
827
843
|
return secretEnvLines({ ...cloudflare, ...config.deploySecrets });
|
|
828
844
|
}
|
|
845
|
+
/**
|
|
846
|
+
* The step env for a step that acts on Cloudflare as the stage deploy did: the
|
|
847
|
+
* two Cloudflare credentials, read from the secrets `deployStepSecretEnvLines`
|
|
848
|
+
* names for them, and none of the other deploy secrets, which such a step
|
|
849
|
+
* never uses.
|
|
850
|
+
*/
|
|
851
|
+
export function cloudflareCredentialEnvLines(deploySecrets) {
|
|
852
|
+
const credentials = Object.entries(CLOUDFLARE_DEPLOY_SECRETS).map(([name, secret]) => [
|
|
853
|
+
name,
|
|
854
|
+
deploySecrets?.[name] ?? secret,
|
|
855
|
+
]);
|
|
856
|
+
return secretEnvLines(Object.fromEntries(credentials));
|
|
857
|
+
}
|
|
829
858
|
/** A step-level `env:` block mapping env var names to repository secrets; nothing when there are none. */
|
|
830
859
|
function secretEnvLines(secrets) {
|
|
831
860
|
const entries = Object.entries(secrets);
|
|
@@ -55,5 +55,5 @@ export declare function managedFileTargetsForContext(context: ManagedFileContext
|
|
|
55
55
|
/** Render all packaged templates before staging any workspace changes. */
|
|
56
56
|
export declare function renderManagedFiles(context: ManagedFileContext): ManagedFile[];
|
|
57
57
|
/** Renders a generated workflow through its real managed-file descriptor, so the context wiring is covered. */
|
|
58
|
-
export declare function renderManagedWorkflowForTest(source: 'ci-workflow' | 'publish-workflow', context: ManagedFileContext): string;
|
|
58
|
+
export declare function renderManagedWorkflowForTest(source: 'ci-workflow' | 'publish-workflow' | 'pr-preview-cleanup-workflow', context: ManagedFileContext): string;
|
|
59
59
|
//# sourceMappingURL=files.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/managed-files/files.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,EACjB,6BAA6B,EAC7B,2BAA2B,EAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,kBAAkB,EAAmD,MAAM,kBAAkB,CAAC;AAI5G,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAa7C,MAAM,WAAW,kBAAkB;IACjC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,uBAAuB,EAAE,OAAO,CAAC;IACjC,0BAA0B,EAAE,OAAO,CAAC;IACpC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,uBAAuB,EAAE,OAAO,CAAC;IACjC,8BAA8B,EAAE,OAAO,CAAC;IACxC,qBA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AAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,qFAAqF;IACrF,0BAA0B,EAAE,MAAM,EAAE,CAAC;IACrC,0BAA0B,EAAE,MAAM,EAAE,CAAC;IACrC,wFAAwF;IACxF,UAAU,CAAC,EAAE,uBAAuB,CAAC;IACrC,sFAAsF;IACtF,eAAe,CAAC,EAAE,2BAA2B,EAAE,CAAC;IAChD,kGAAkG;IAClG,gBAAgB,CAAC,EAAE,6BAA6B,CAAC;IACjD,uGAAuG;IACvG,WAAW,CAAC,EAAE,wBAAwB,CAAC;IACvC;;;;OAIG;IACH,iBAAiB,EAAE,kBAAkB,EAAE,CAAC;CACzC;AAED,sFAAsF;AACtF,eAAO,MAAM,gBAAgB;aAC3B,OAAO,EAAE,QAAQ;aACjB,GAAG,EAAE,aAAa;aAClB,IAAI,EAAE,2BAA2B;CACzB,CAAC;AAmJX,eAAO,MAAM,yBAAyB;;;GAAyE,CAAC;AAchH,qFAAqF;AACrF,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,EAAE,CAElF;AAED,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,EAAE,CAM7E;AAED,+GAA+G;AAC/G,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,6BAA6B,EAC1E,OAAO,EAAE,kBAAkB,GAC1B,MAAM,CAMR"}
|
|
@@ -235,7 +235,14 @@ function getManagedContent(file, context) {
|
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
237
|
if (file.source === 'pr-preview-cleanup-workflow') {
|
|
238
|
-
return renderPrPreviewCleanupWorkflowYaml({
|
|
238
|
+
return renderPrPreviewCleanupWorkflowYaml({
|
|
239
|
+
runsOn: context.ciRunsOn,
|
|
240
|
+
privateNpm: context.privateNpm,
|
|
241
|
+
sourceCheckouts: context.sourceCheckouts,
|
|
242
|
+
cargoCredentials: context.cargoCredentials,
|
|
243
|
+
environments: context.ciEnvironments,
|
|
244
|
+
deploySecrets: context.ciDeploySecrets,
|
|
245
|
+
});
|
|
239
246
|
}
|
|
240
247
|
throw new Error(`Unknown generated managed file source ${file.source}`);
|
|
241
248
|
}
|