@patronage/factory-ci 1.0.0-alpha.43 → 1.0.0-alpha.44
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 +66 -0
- package/dist/.build-fingerprint.json +1 -1
- package/dist/index.d.ts +297 -1
- package/dist/index.js +593 -51
- package/package.json +1 -1
- package/src/index.ts +44 -0
- package/src/preview-cleanup-workflow.ts +422 -0
- package/src/preview-cleanup.ts +688 -0
- package/src/proof-reuse-gate.ts +27 -7
package/README.md
CHANGED
|
@@ -308,6 +308,72 @@ const jobs = [
|
|
|
308
308
|
|
|
309
309
|
The audit job is `always()` so a failed destroy still runs the stage-wide check. It does not receive a stack name or path filter — per-stack audit filters are rejected because they trade away the whole-stage guarantee (paitronage#1143). `previewCleanupDestroyJobId(stack)` is the same id mapping callers can use when they assemble destroy jobs by hand.
|
|
310
310
|
|
|
311
|
+
### Closed-PR cleanup and the orphan sweep
|
|
312
|
+
|
|
313
|
+
`factoryPreviewCleanupWorkflow` (#1540) builds the whole cleanup on that topology, so each consumer stops carrying its own copy. It owns target discovery, the per-stack destroy matrices, outcome recording and the stage-wide audit. The consumer keeps its stack list, a one-line destroy command, a one-line residue reader, credentials and protected-stage policy.
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
import {
|
|
317
|
+
factoryPreviewCleanupWorkflow,
|
|
318
|
+
setupStepsForRoles,
|
|
319
|
+
} from "@patronage/factory-ci";
|
|
320
|
+
|
|
321
|
+
const cleanup = factoryPreviewCleanupWorkflow({
|
|
322
|
+
stacks: ["website", "loop", "flue-agents"],
|
|
323
|
+
stackAliases: { "preview-deploy-website": "website" },
|
|
324
|
+
hostedStagePrefix: "pr-", // omit when there is no hosted pr-N stage
|
|
325
|
+
environment: "preview-cleanup",
|
|
326
|
+
createGithubAppToken: generated.actions.createGithubAppToken,
|
|
327
|
+
residueCommand: "node tools/cleanup-residue.ts",
|
|
328
|
+
destroyCommand:
|
|
329
|
+
'pnpm alchemy:destroy "$FACTORY_PREVIEW_CLEANUP_STACK" "$FACTORY_PREVIEW_CLEANUP_STAGE"',
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
const setup = [
|
|
333
|
+
{
|
|
334
|
+
...generated.setupStepsByRole.checkout,
|
|
335
|
+
with: { ref: cleanup.checkoutRef },
|
|
336
|
+
},
|
|
337
|
+
...setupStepsForRoles(generated, ["setupPnpm", "setupNode", "install"]),
|
|
338
|
+
];
|
|
339
|
+
const discover = job(cleanup.discoverJob.jobId, {
|
|
340
|
+
...cleanup.discoverJob,
|
|
341
|
+
runsOn,
|
|
342
|
+
env: credentials,
|
|
343
|
+
steps: [...setup, ...cleanup.discoverJob.steps],
|
|
344
|
+
});
|
|
345
|
+
const destroys = cleanup.destroyJobs.map((destroy) =>
|
|
346
|
+
job(destroy.jobId, {
|
|
347
|
+
...destroy,
|
|
348
|
+
needs: [discover],
|
|
349
|
+
runsOn,
|
|
350
|
+
env: credentials,
|
|
351
|
+
steps: [...setup, ...destroy.steps],
|
|
352
|
+
})
|
|
353
|
+
);
|
|
354
|
+
const audit = job(cleanup.auditJob.jobId, {
|
|
355
|
+
...cleanup.auditJob,
|
|
356
|
+
needs: [discover, ...destroys],
|
|
357
|
+
runsOn,
|
|
358
|
+
env: { ...credentials, ...cleanup.auditJob.env },
|
|
359
|
+
steps: [...setup, ...cleanup.auditJob.steps],
|
|
360
|
+
});
|
|
361
|
+
workflow({
|
|
362
|
+
on: cleanup.on,
|
|
363
|
+
permissions: cleanup.permissions,
|
|
364
|
+
jobs: [discover, ...destroys, audit],
|
|
365
|
+
});
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
- **Gate.** Every credentialed job runs in the named GitHub `environment`. The discover job runs for a closed PR whose head is this repository (`FACTORY_PREVIEW_CLEANUP_PR_CLOSED_CONDITION`), on the schedule, or on a dispatch from the default branch (`FACTORY_PREVIEW_CLEANUP_SWEEP_CONDITION`). Nothing reads a production deploy flag. Check out `checkoutRef`, the default branch, never the closed head.
|
|
369
|
+
- **Discover.** For a closed PR, the PR's inventory registrations are united with the residue, keeping only `local-pr-<pr>-*` stages and the hosted `<prefix><pr>` stage in declared stacks (`discoverPreviewCleanupTargets`). The sweep keeps the residue of PRs GitHub reports closed (`discoverOrphanedPreviewCleanupTargets`, `readPullRequestStates`). It fails closed: a stage that does not parse as disposable, an undeclared stack, and an open or unknown PR are all retained. A sweep handles up to `sweep.maxTargets` targets (50) per run and leaves the rest for the next one. It takes each stage whole across its stacks, so a run goes over the cap only when its first stage alone has more stacks than the cap. Pass `sweep: false` for PR-close cleanup only.
|
|
370
|
+
- **Residue.** `residueCommand` prints `[{ "stack": …, "stage": … }]`. Map physical resources to a stack and stage before printing them; this package never guesses a resource's owner.
|
|
371
|
+
- **Destroy.** `destroyCommand` reads `$FACTORY_PREVIEW_CLEANUP_STACK` and `$FACTORY_PREVIEW_CLEANUP_STAGE` (and `$FACTORY_PREVIEW_CLEANUP_PR`), exits non-zero when it did not destroy, and may append evidence lines to `$FACTORY_PREVIEW_CLEANUP_EVIDENCE`. Matrix values reach the shell through the environment, never interpolated into the script.
|
|
372
|
+
- **Record.** After each destroy, `recordPreviewCleanupOutcome` lists the registration with the workflow token and writes the passed or failed outcome, with the evidence and run URL, through the Factory App token. A stage nothing registered records nothing. A registration whose last cleanup failed is recovered through the same transition.
|
|
373
|
+
- **Audit.** The audit re-reads the residue after every destroy and fails if any target stage remains under any stack (`assertPreviewCleanupTargetsAbsent`).
|
|
374
|
+
|
|
375
|
+
The invocable half is `psf preview:cleanup --action discover|sweep|record|audit`; the generated steps call it with `cli` (default `pnpm exec psf`).
|
|
376
|
+
|
|
311
377
|
### Merge-freeze writer job
|
|
312
378
|
|
|
313
379
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1222,6 +1222,302 @@ declare const previewCleanupDestroyJobId: (stack: string) => string;
|
|
|
1222
1222
|
*/
|
|
1223
1223
|
declare const factoryPreviewCleanupTopology: (options: FactoryPreviewCleanupTopologyOptions) => FactoryPreviewCleanupTopology;
|
|
1224
1224
|
//#endregion
|
|
1225
|
+
//#region src/preview-cleanup.d.ts
|
|
1226
|
+
/**
|
|
1227
|
+
* Closed-PR preview cleanup and the scheduled orphan sweep (#1540).
|
|
1228
|
+
*
|
|
1229
|
+
* This module owns the consumer-neutral decisions: which stages a closed PR
|
|
1230
|
+
* left behind, which stages belong to PRs that are already closed, how a
|
|
1231
|
+
* stack-scoped destroy outcome reaches the inventory, and whether a stage is
|
|
1232
|
+
* still present afterwards. The consumer keeps its stack list, the destroy
|
|
1233
|
+
* command, the residue reader, credentials and protected-stage policy.
|
|
1234
|
+
*
|
|
1235
|
+
* Every destructive target passes through the one disposable-stage grammar
|
|
1236
|
+
* (`local-pr-<pr>-<sha>`) or the consumer's declared hosted grammar
|
|
1237
|
+
* (`<prefix><pr>`). Anything else is retained, never destroyed.
|
|
1238
|
+
*/
|
|
1239
|
+
/** One `{ stack, stage }` row from the consumer's residue reader. */
|
|
1240
|
+
interface PreviewCleanupResidue {
|
|
1241
|
+
readonly stack: string;
|
|
1242
|
+
readonly stage: string;
|
|
1243
|
+
}
|
|
1244
|
+
/** One stack-scoped destroy the cleanup workflow runs. */
|
|
1245
|
+
interface PreviewCleanupTarget {
|
|
1246
|
+
/** Present when a registration supplied the head, so the record can bind it. */
|
|
1247
|
+
readonly headSha?: string;
|
|
1248
|
+
readonly pr: number;
|
|
1249
|
+
readonly stack: string;
|
|
1250
|
+
readonly stage: string;
|
|
1251
|
+
}
|
|
1252
|
+
interface PreviewCleanupStackPolicy {
|
|
1253
|
+
/**
|
|
1254
|
+
* The consumer's hosted per-PR stage prefix, such as `"pr-"` for `pr-123`.
|
|
1255
|
+
* Omit it when the consumer has no hosted per-PR stage.
|
|
1256
|
+
*/
|
|
1257
|
+
readonly hostedStagePrefix?: string;
|
|
1258
|
+
/**
|
|
1259
|
+
* Other names the inventory or the residue reader uses for a declared stack,
|
|
1260
|
+
* mapped to that stack. A registration recorded as `preview-deploy-website`
|
|
1261
|
+
* resolves to `website` with `{ "preview-deploy-website": "website" }`.
|
|
1262
|
+
*/
|
|
1263
|
+
readonly stackAliases?: Readonly<Record<string, string>>;
|
|
1264
|
+
/** The stacks a cleanup destroys, in the consumer's own names. */
|
|
1265
|
+
readonly stacks: readonly string[];
|
|
1266
|
+
}
|
|
1267
|
+
interface DiscoverPreviewCleanupTargetsInput extends PreviewCleanupStackPolicy {
|
|
1268
|
+
readonly pr: number;
|
|
1269
|
+
/** Inventory registrations for the PR, from `previewProofInventory.list`. */
|
|
1270
|
+
readonly registrations: readonly PreviewProofRegistration[];
|
|
1271
|
+
readonly residue: readonly PreviewCleanupResidue[];
|
|
1272
|
+
}
|
|
1273
|
+
type PreviewCleanupPullRequestState = "closed" | "open";
|
|
1274
|
+
interface DiscoverOrphanedPreviewCleanupTargetsInput extends PreviewCleanupStackPolicy {
|
|
1275
|
+
/**
|
|
1276
|
+
* Targets per run; the rest wait for the next sweep. Default 50. A stage's
|
|
1277
|
+
* targets across its stacks are taken whole, so a run exceeds the cap only
|
|
1278
|
+
* when its first stage alone has more stacks than the cap.
|
|
1279
|
+
*/
|
|
1280
|
+
readonly maxTargets?: number;
|
|
1281
|
+
/**
|
|
1282
|
+
* The state GitHub reported for each PR the residue names. A PR missing
|
|
1283
|
+
* from the map is unknown, and its stages are retained.
|
|
1284
|
+
*/
|
|
1285
|
+
readonly pullRequestStates: ReadonlyMap<number, PreviewCleanupPullRequestState>;
|
|
1286
|
+
readonly residue: readonly PreviewCleanupResidue[];
|
|
1287
|
+
}
|
|
1288
|
+
interface PreviewCleanupSweep {
|
|
1289
|
+
/**
|
|
1290
|
+
* Orphaned targets left for the next sweep. A stage is never split: all of
|
|
1291
|
+
* its stacks are taken or all are deferred.
|
|
1292
|
+
*/
|
|
1293
|
+
readonly deferred: number;
|
|
1294
|
+
readonly targets: readonly PreviewCleanupTarget[];
|
|
1295
|
+
}
|
|
1296
|
+
interface RecordPreviewCleanupOutcomeInput {
|
|
1297
|
+
readonly evidence: readonly string[];
|
|
1298
|
+
readonly headSha?: string;
|
|
1299
|
+
readonly outcome: Exclude<PreviewProofCleanupStatus, "pending">;
|
|
1300
|
+
readonly owner: string;
|
|
1301
|
+
readonly pr: number;
|
|
1302
|
+
readonly repo: string;
|
|
1303
|
+
readonly runUrl?: string;
|
|
1304
|
+
readonly stack: string;
|
|
1305
|
+
readonly stackAliases?: Readonly<Record<string, string>>;
|
|
1306
|
+
readonly stage: string;
|
|
1307
|
+
}
|
|
1308
|
+
interface RecordPreviewCleanupOutcomeAccess {
|
|
1309
|
+
/**
|
|
1310
|
+
* Lists registrations. A workflow `GITHUB_TOKEN` with
|
|
1311
|
+
* `PREVIEW_PROOF_INVENTORY_LIST_PERMISSIONS`: the Factory App token has no
|
|
1312
|
+
* contents permission and cannot serve the list (#825).
|
|
1313
|
+
*/
|
|
1314
|
+
readonly read: PreviewProofInventoryAccess;
|
|
1315
|
+
/** Writes the outcome. A Factory App installation token. */
|
|
1316
|
+
readonly write: PreviewProofInventoryAccess;
|
|
1317
|
+
}
|
|
1318
|
+
type RecordPreviewCleanupOutcomeResult = {
|
|
1319
|
+
/** Destroyed but never registered: inventory residue or a hosted stage. */readonly kind: "unregistered";
|
|
1320
|
+
} | {
|
|
1321
|
+
readonly kind: "recorded" | "recovered";
|
|
1322
|
+
readonly registration: PreviewProofRegistration;
|
|
1323
|
+
};
|
|
1324
|
+
interface ReadPullRequestStatesInput {
|
|
1325
|
+
readonly owner: string;
|
|
1326
|
+
readonly prs: readonly number[];
|
|
1327
|
+
readonly repo: string;
|
|
1328
|
+
}
|
|
1329
|
+
interface ReadPullRequestStatesAccess {
|
|
1330
|
+
readonly fetch?: typeof fetch;
|
|
1331
|
+
readonly timeoutMs?: number;
|
|
1332
|
+
/** Needs `pull-requests: read`. */
|
|
1333
|
+
readonly token: string;
|
|
1334
|
+
}
|
|
1335
|
+
/** The GitHub-output key a stack's matrix and presence flag use. */
|
|
1336
|
+
declare const previewCleanupStackOutputKey: (stack: string) => string;
|
|
1337
|
+
/**
|
|
1338
|
+
* Validate a stack policy. Throws on an empty or duplicate stack list, a
|
|
1339
|
+
* stack name a shell or GitHub output could misread, an alias to an
|
|
1340
|
+
* undeclared stack, or a hosted prefix that is not `<word>-`.
|
|
1341
|
+
*/
|
|
1342
|
+
declare const assertPreviewCleanupStackPolicy: (policy: PreviewCleanupStackPolicy) => void;
|
|
1343
|
+
/** The PR a hosted stage belongs to, or `null` when it is not one. */
|
|
1344
|
+
declare const parseHostedPreviewStage: (stage: string, prefix: string) => number | null;
|
|
1345
|
+
/**
|
|
1346
|
+
* Targets for one closed PR: its inventory registrations united with the
|
|
1347
|
+
* residue the consumer still sees for it. Only the PR's own `local-pr-<pr>-*`
|
|
1348
|
+
* stages and its hosted stage survive, in declared stacks. A registration
|
|
1349
|
+
* wins a collision so its head SHA reaches the cleanup record. A registration
|
|
1350
|
+
* whose cleanup already passed is skipped unless the residue still lists it.
|
|
1351
|
+
*/
|
|
1352
|
+
declare const discoverPreviewCleanupTargets: (input: DiscoverPreviewCleanupTargetsInput) => readonly PreviewCleanupTarget[];
|
|
1353
|
+
/**
|
|
1354
|
+
* The PRs whose disposable stages appear in the residue. The sweep reads
|
|
1355
|
+
* their state before it decides anything.
|
|
1356
|
+
*/
|
|
1357
|
+
declare const previewCleanupResiduePullRequests: (policy: PreviewCleanupStackPolicy, residue: readonly PreviewCleanupResidue[]) => readonly number[];
|
|
1358
|
+
/**
|
|
1359
|
+
* Targets for the scheduled sweep: disposable residue whose PR GitHub
|
|
1360
|
+
* reports closed. It fails closed. A stage that does not parse as disposable,
|
|
1361
|
+
* a stack the consumer did not declare, and a PR that is open or whose state
|
|
1362
|
+
* is unknown are all retained.
|
|
1363
|
+
*/
|
|
1364
|
+
declare const discoverOrphanedPreviewCleanupTargets: (input: DiscoverOrphanedPreviewCleanupTargetsInput) => PreviewCleanupSweep;
|
|
1365
|
+
/**
|
|
1366
|
+
* The `$GITHUB_OUTPUT` lines the cleanup workflow's discover job publishes:
|
|
1367
|
+
* `has_targets`, `targets`, and for each declared stack `has_<key>` and
|
|
1368
|
+
* `<key>_matrix`. A stack with no target still gets `has_<key>=false`, so
|
|
1369
|
+
* its destroy job skips instead of expanding an empty matrix.
|
|
1370
|
+
*/
|
|
1371
|
+
declare const previewCleanupGithubOutput: (policy: PreviewCleanupStackPolicy, targets: readonly PreviewCleanupTarget[]) => string;
|
|
1372
|
+
/** Parse untrusted residue JSON: an array of `{ stack, stage }` rows. */
|
|
1373
|
+
declare const parsePreviewCleanupResidue: (value: unknown) => readonly PreviewCleanupResidue[];
|
|
1374
|
+
/**
|
|
1375
|
+
* Parse untrusted target JSON (the discover job's `targets` output). Every
|
|
1376
|
+
* row must still be a disposable stage owned by its own PR, so a tampered
|
|
1377
|
+
* output cannot widen the audit or a record.
|
|
1378
|
+
*/
|
|
1379
|
+
declare const parsePreviewCleanupTargets: (policy: PreviewCleanupStackPolicy, value: unknown) => readonly PreviewCleanupTarget[];
|
|
1380
|
+
/**
|
|
1381
|
+
* The whole-stage audit after every destroy. Any residue row whose stage
|
|
1382
|
+
* is a target stage fails it, whatever stack the reader assigned the row,
|
|
1383
|
+
* because a sibling stack's leftovers are the same stage's residue.
|
|
1384
|
+
*/
|
|
1385
|
+
declare const assertPreviewCleanupTargetsAbsent: (targets: readonly PreviewCleanupTarget[], residue: readonly PreviewCleanupResidue[]) => void;
|
|
1386
|
+
/**
|
|
1387
|
+
* Record one stack destroy's outcome on the inventory registration it
|
|
1388
|
+
* cleaned up. A stage nothing registered (residue-only, or a hosted stage)
|
|
1389
|
+
* returns `unregistered` without writing. A registration whose last cleanup
|
|
1390
|
+
* failed is recovered through the same cleanup transition.
|
|
1391
|
+
*/
|
|
1392
|
+
declare const recordPreviewCleanupOutcome: (input: RecordPreviewCleanupOutcomeInput, access: RecordPreviewCleanupOutcomeAccess) => Promise<RecordPreviewCleanupOutcomeResult>;
|
|
1393
|
+
/**
|
|
1394
|
+
* Ask GitHub for each PR's state. A PR GitHub does not know is left out of
|
|
1395
|
+
* the map, so the sweep retains its stages.
|
|
1396
|
+
*/
|
|
1397
|
+
declare const readPullRequestStates: (input: ReadPullRequestStatesInput, access: ReadPullRequestStatesAccess) => Promise<ReadonlyMap<number, PreviewCleanupPullRequestState>>;
|
|
1398
|
+
//#endregion
|
|
1399
|
+
//#region src/preview-cleanup-workflow.d.ts
|
|
1400
|
+
declare const FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_ID = "discover";
|
|
1401
|
+
declare const FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_NAME = "Discover preview cleanup targets";
|
|
1402
|
+
declare const FACTORY_PREVIEW_CLEANUP_DISCOVER_STEP_ID = "targets";
|
|
1403
|
+
declare const FACTORY_PREVIEW_CLEANUP_DESTROY_STEP_ID = "destroy";
|
|
1404
|
+
declare const FACTORY_PREVIEW_CLEANUP_APP_TOKEN_STEP_ID = "factory-app-token";
|
|
1405
|
+
declare const FACTORY_PREVIEW_CLEANUP_DEFAULT_SWEEP_CRON = "23 6 * * *";
|
|
1406
|
+
/**
|
|
1407
|
+
* A closed pull request whose head lives in this repository. A fork's head
|
|
1408
|
+
* never reaches a job that holds cleanup credentials.
|
|
1409
|
+
*/
|
|
1410
|
+
declare const FACTORY_PREVIEW_CLEANUP_PR_CLOSED_CONDITION = "github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.head.repo.full_name == github.repository";
|
|
1411
|
+
/**
|
|
1412
|
+
* The sweep: the schedule, which GitHub always runs on the default branch,
|
|
1413
|
+
* or a manual dispatch from the default branch.
|
|
1414
|
+
*/
|
|
1415
|
+
declare const FACTORY_PREVIEW_CLEANUP_SWEEP_CONDITION = "github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch))";
|
|
1416
|
+
/**
|
|
1417
|
+
* The ref every cleanup job checks out: the default branch's trusted code,
|
|
1418
|
+
* never the closed PR's head. Empty on `schedule`, where the checkout
|
|
1419
|
+
* already defaults to the default branch.
|
|
1420
|
+
*/
|
|
1421
|
+
declare const FACTORY_PREVIEW_CLEANUP_CHECKOUT_REF = "${{ github.event.repository.default_branch }}";
|
|
1422
|
+
interface FactoryPreviewCleanupWorkflowOptions extends PreviewCleanupStackPolicy {
|
|
1423
|
+
readonly cli?: string;
|
|
1424
|
+
/**
|
|
1425
|
+
* The workflow's concurrency group for one destroy. It may read
|
|
1426
|
+
* `matrix.stack`, `matrix.stage` and `matrix.pr`. Share it with the
|
|
1427
|
+
* consumer's deploy job when a deploy and a destroy must not race.
|
|
1428
|
+
*/
|
|
1429
|
+
readonly concurrencyGroup?: string;
|
|
1430
|
+
/** The pinned `actions/create-github-app-token` the caller declared. */
|
|
1431
|
+
readonly createGithubAppToken: PinnedAction;
|
|
1432
|
+
/**
|
|
1433
|
+
* One shell line that destroys `$FACTORY_PREVIEW_CLEANUP_STAGE` of
|
|
1434
|
+
* `$FACTORY_PREVIEW_CLEANUP_STACK` and exits non-zero when it did not. It
|
|
1435
|
+
* may append evidence lines to `$FACTORY_PREVIEW_CLEANUP_EVIDENCE`.
|
|
1436
|
+
*/
|
|
1437
|
+
readonly destroyCommand: string;
|
|
1438
|
+
/**
|
|
1439
|
+
* The GitHub environment every job that holds cleanup credentials runs
|
|
1440
|
+
* in. Its protection rules, not a production deploy flag, gate cleanup.
|
|
1441
|
+
*/
|
|
1442
|
+
readonly environment: string;
|
|
1443
|
+
/**
|
|
1444
|
+
* One shell line that prints the consumer's residue as JSON
|
|
1445
|
+
* `[{ "stack": …, "stage": … }]` on stdout: Alchemy state and any physical
|
|
1446
|
+
* resources the consumer can attribute to a stack and stage.
|
|
1447
|
+
*/
|
|
1448
|
+
readonly residueCommand: string;
|
|
1449
|
+
/** The scheduled orphan sweep. Pass `false` to generate PR-close cleanup only. */
|
|
1450
|
+
readonly sweep?: false | {
|
|
1451
|
+
/** Defaults to `FACTORY_PREVIEW_CLEANUP_DEFAULT_SWEEP_CRON`. */readonly cron?: string;
|
|
1452
|
+
/**
|
|
1453
|
+
* Targets per sweep run. Defaults to 50. Stages are taken whole, so a
|
|
1454
|
+
* run exceeds it only when its first stage has more stacks than this.
|
|
1455
|
+
*/
|
|
1456
|
+
readonly maxTargets?: number;
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
interface FactoryPreviewCleanupWorkflowJob {
|
|
1460
|
+
readonly environment: string;
|
|
1461
|
+
readonly if: string;
|
|
1462
|
+
readonly jobId: string;
|
|
1463
|
+
readonly jobName: string;
|
|
1464
|
+
readonly permissions: Readonly<Record<string, "read" | "write">>;
|
|
1465
|
+
/** Append after the caller's setup steps. */
|
|
1466
|
+
readonly steps: readonly WorkflowStep[];
|
|
1467
|
+
}
|
|
1468
|
+
interface FactoryPreviewCleanupWorkflowDiscoverJob extends FactoryPreviewCleanupWorkflowJob {
|
|
1469
|
+
readonly outputs: Readonly<Record<string, string>>;
|
|
1470
|
+
}
|
|
1471
|
+
interface FactoryPreviewCleanupWorkflowDestroyJob extends FactoryPreviewCleanupWorkflowJob {
|
|
1472
|
+
readonly concurrency: {
|
|
1473
|
+
readonly cancelInProgress: false;
|
|
1474
|
+
readonly group: string;
|
|
1475
|
+
};
|
|
1476
|
+
/** Always the discover job's id. */
|
|
1477
|
+
readonly needs: readonly string[];
|
|
1478
|
+
readonly stack: string;
|
|
1479
|
+
readonly strategy: {
|
|
1480
|
+
readonly failFast: false;
|
|
1481
|
+
readonly matrix: {
|
|
1482
|
+
readonly include: string;
|
|
1483
|
+
};
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
interface FactoryPreviewCleanupWorkflowAuditJob extends FactoryPreviewCleanupWorkflowJob {
|
|
1487
|
+
/** Merge into the job's own `env` alongside the caller's credentials. */
|
|
1488
|
+
readonly env: Readonly<Record<string, string>>;
|
|
1489
|
+
/** The discover job, then every destroy job. */
|
|
1490
|
+
readonly needs: readonly string[];
|
|
1491
|
+
}
|
|
1492
|
+
interface FactoryPreviewCleanupWorkflow {
|
|
1493
|
+
readonly auditJob: FactoryPreviewCleanupWorkflowAuditJob;
|
|
1494
|
+
/** Pass to the checkout step of every job. */
|
|
1495
|
+
readonly checkoutRef: typeof FACTORY_PREVIEW_CLEANUP_CHECKOUT_REF;
|
|
1496
|
+
readonly destroyJobs: readonly FactoryPreviewCleanupWorkflowDestroyJob[];
|
|
1497
|
+
readonly discoverJob: FactoryPreviewCleanupWorkflowDiscoverJob;
|
|
1498
|
+
readonly on: Readonly<Record<string, unknown>>;
|
|
1499
|
+
readonly permissions: Readonly<{
|
|
1500
|
+
contents: "read";
|
|
1501
|
+
}>;
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Generate the factory-owned closed-PR preview cleanup and orphan sweep
|
|
1505
|
+
* (#1540) on top of `factoryPreviewCleanupTopology`:
|
|
1506
|
+
*
|
|
1507
|
+
* - `discover` reads the consumer's residue and, for a closed same-repo PR,
|
|
1508
|
+
* unites it with the PR's inventory registrations; for the sweep, keeps the
|
|
1509
|
+
* residue of PRs GitHub reports closed. It publishes one matrix per stack.
|
|
1510
|
+
* - one destroy job per stack runs the consumer's destroy for each matrix
|
|
1511
|
+
* target, then records the outcome on the inventory with the Factory App.
|
|
1512
|
+
* - one stage-wide audit re-reads the residue after every destroy and fails
|
|
1513
|
+
* if any target stage remains, in any stack.
|
|
1514
|
+
*
|
|
1515
|
+
* Every credentialed job runs in the consumer's GitHub environment, never
|
|
1516
|
+
* behind a production deploy flag. The caller prepends its own setup steps
|
|
1517
|
+
* (checked out at `checkoutRef`), and adds `runsOn` and credential `env`.
|
|
1518
|
+
*/
|
|
1519
|
+
declare const factoryPreviewCleanupWorkflow: (options: FactoryPreviewCleanupWorkflowOptions) => FactoryPreviewCleanupWorkflow;
|
|
1520
|
+
//#endregion
|
|
1225
1521
|
//#region src/preview-receipt-workflow.d.ts
|
|
1226
1522
|
interface FactoryPreviewReceiptWorkflowOptions {
|
|
1227
1523
|
readonly target: string;
|
|
@@ -1688,4 +1984,4 @@ declare const assertWorkflowShellParses: (yaml: string, options: {
|
|
|
1688
1984
|
readonly source: string;
|
|
1689
1985
|
}) => void;
|
|
1690
1986
|
//#endregion
|
|
1691
|
-
export { ALCHEMY_BASELINE, type AlchemyBaselinePackageJson, type AssertAlchemyBaselineInput, type BundleAlchemyEntryOptions, type CheckoutStepOptions, EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER, type ExecuteAlchemyEntryOptions, type ExecuteAlchemyEntryResult, FACTORY_APP_BROKER_ORIGIN, FACTORY_APP_BROKER_PATH, FACTORY_APP_BROKER_TOKEN_PERMISSIONS, FACTORY_CANDIDATE_IMPACT_BASIS_OUTPUT, FACTORY_CANDIDATE_IMPACT_DECISION_OUTPUT, FACTORY_CANDIDATE_IMPACT_INERT_OUTPUT, FACTORY_CANDIDATE_IMPACT_STEP_ID, FACTORY_CANDIDATE_IMPACT_UNSUBSCRIBED_OUTPUT, FACTORY_CANDIDATE_PULL_REQUEST_TYPES, FACTORY_CURSOR_OIDC_AUDIENCE, FACTORY_CURSOR_OIDC_ISSUER, FACTORY_CURSOR_OIDC_JWKS_URL, FACTORY_CURSOR_OIDC_MANAGED_RUNTIME, FACTORY_LIFECYCLE_CONTRACT_JOB_ID, FACTORY_LIFECYCLE_CONTRACT_JOB_NAME, FACTORY_MERGE_FREEZE_APP_TOKEN_STEP_ID, FACTORY_MERGE_FREEZE_CHECK_NAME, FACTORY_MERGE_FREEZE_IF, FACTORY_MERGE_FREEZE_JOB_ID, FACTORY_MERGE_FREEZE_JOB_NAME, FACTORY_MERGE_FREEZE_PERMISSIONS, FACTORY_MERGE_FREEZE_VERIFY_RESULT_EXPRESSION, FACTORY_MERGE_TARGET_REF_CONDITION, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_ID, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_NAME, FACTORY_PRODUCTION_IMPACT_BASIS_OUTPUT, FACTORY_PRODUCTION_IMPACT_DECISION_OUTPUT, FACTORY_PRODUCTION_IMPACT_STEP_ID, FACTORY_PRODUCTION_IMPACT_UNSUBSCRIBED_OUTPUT, FACTORY_PROOF_GATE_APP_ID, FACTORY_PROOF_GATE_CHECK_NAME, FACTORY_PROOF_GATE_GUARD, FACTORY_PROOF_GATE_IF, FACTORY_PROOF_GATE_MODE_OUTPUT, FACTORY_PROOF_GATE_OUTPUT, FACTORY_PROOF_GATE_REASONS, FACTORY_PROOF_GATE_REASON_OUTPUT, FACTORY_PROOF_GATE_SHELL, FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT, FACTORY_PROOF_GATE_STEP_ID, FACTORY_PROOF_GATE_STEP_NAME, FACTORY_PR_STATUS_HUD_APP_TOKEN_STEP_ID, FACTORY_PR_STATUS_HUD_CONCURRENCY, FACTORY_PR_STATUS_HUD_IF, FACTORY_PR_STATUS_HUD_JOB_ID, FACTORY_PR_STATUS_HUD_JOB_NAME, FACTORY_PR_STATUS_HUD_PERMISSIONS, FACTORY_PR_STATUS_HUD_PLAN_PATH, FACTORY_PUSH_IDENTITY_SCHEMA_VERSION, type FactoryCandidateImpactWorkflow, type FactoryCandidateImpactWorkflowOptions, type FactoryLifecycleContractLane, type FactoryLifecycleContractLaneOptions, type FactoryMergeFreezeJob, type FactoryMergeFreezeJobOptions, type FactoryPrStatusHudWorkflow, type FactoryPrStatusHudWorkflowOptions, type FactoryPreviewCleanupAuditJob, type FactoryPreviewCleanupDestroyJob, type FactoryPreviewCleanupTopology, type FactoryPreviewCleanupTopologyOptions, type FactoryPreviewReceiptWorkflow, type FactoryPreviewReceiptWorkflowOptions, type FactoryProductionImpactWorkflow, type FactoryProductionImpactWorkflowOptions, type FactoryProofGateOptions, type FactoryProofGateReason, type FactoryProofGateStep, type FactoryProofReusePresentationOptions, type FactoryProofReuseSummaryStep, type FactoryProofTimingStartStep, type FactoryPushIdentityConsumer, type FactoryPushIdentityConsumerOptions, type FactoryPushIdentityDisposition, type FactoryPushIdentityEnvelope, type FactoryPushIdentityProducer, type FactoryPushIdentityProducerOptions, type FactoryRunnerDecision, type FactoryRunnerHome, type FactoryRunnerKind, type FactoryRunnerOverride, type FactoryVerifyRunner, type FactoryVerifyRunnerMismatch, type FactoryVerifyRunnerPolicyInput, type FactoryVerifyRunnerPolicyReport, type FactoryVerifyRunnerTable, type FactoryWorkflowArtifact, type FactoryWorkflowOptions, type FactoryWorkflowSetupOptions, GitHubApiError, GitHubAppTokenTransportError, type GithubAppCredentials, type GithubAppInstallationPermissions, type GithubAppTokenOptions, type InstallStepOptions, type LocalPreviewStage, type LocalPreviewStageOptions, NODE_PNPM_ACTION_FAMILY_NODE24, type NodePnpmActionFamily, PREVIEW_PROOF_INVENTORY_CHECK_NAME, PREVIEW_PROOF_INVENTORY_LIST_PERMISSIONS, type ParseLocalPreviewStageExpected, type ParsedLocalPreviewStage, type PinnedAction, type PreviewProofCandidate, type PreviewProofCleanupOutcome, type PreviewProofCleanupStatus, type PreviewProofEnvelopeEvidence, type PreviewProofInventoryAccess, type PreviewProofInventoryCleanupInput, type PreviewProofInventoryListInput, type PreviewProofInventoryPersistInput, type PreviewProofInventoryStore, type PreviewProofInventoryTransport, type PreviewProofLifecycleEvent, type PreviewProofLifecycleState, type PreviewProofRegistration, type PreviewProofResolveQuery, PreviewProofTransportError, type ProofReuseCommand, type ProofReuseCoverageInput, type ProofReuseCoverageReport, SETUP_STEP_ROLES, type SetupNodeStepOptions, type SetupStepRole, UPLOAD_ARTIFACT, VITEST_PROFILE_SCHEMA_VERSION, VITEST_PROFILE_TOOL, type VitestJsonReport, type VitestProfile, type VitestProfileDependencies, type VitestProfileDurationSummary, type VitestProfileEnvironment, VitestProfileError, type VitestProfileOptions, type VitestProfileReadResult, type VitestProfileSample, type VitestProfileSampleExecution, type VitestTestStatus, type WorkflowShellParseFailure, type WorkflowStep, assertAlchemyBaseline, assertProofReuseCoverage, assertVerifyRunnerPolicy, assertWorkflowShellParses, bundleAlchemyEntry, captureVitestProfileEnvironment, executeAlchemyEntry, factoryCandidateImpactWorkflow, factoryCandidateOrPushCondition, factoryLifecycleContractLane, factoryMergeFreezeJob, factoryMergeFreezeScript, factoryPrStatusHudWorkflow, factoryPreviewCleanupTopology, factoryPreviewReceiptWorkflow, factoryProductionImpactWorkflow, factoryProofGateScript, factoryProofGateStep, factoryProofReuseSummaryStep, factoryProofTimingStartStep, factoryPushIdentityConsumer, factoryPushIdentityProducer, factoryVerifyRunner, factoryWorkflow, githubAppJwt, isLocalPreviewStage, localPreviewStage, mintInstallationToken, normalizeVitestProfileSample, parseLocalPreviewStage, previewCleanupDestroyJobId, previewProofInventory, previewProofLifecycle, productionImpactTargetOutput, proofReuseCoverage, proofReuseRequiredCommands, readVitestProfileDocument, resolveProofReuseCommands, runVitestProfile, setupStepsForRoles, verifyRunnerPolicy, workflowRunBlocks, workflowShellParseFailures, writeVitestProfile };
|
|
1987
|
+
export { ALCHEMY_BASELINE, type AlchemyBaselinePackageJson, type AssertAlchemyBaselineInput, type BundleAlchemyEntryOptions, type CheckoutStepOptions, type DiscoverOrphanedPreviewCleanupTargetsInput, type DiscoverPreviewCleanupTargetsInput, EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER, type ExecuteAlchemyEntryOptions, type ExecuteAlchemyEntryResult, FACTORY_APP_BROKER_ORIGIN, FACTORY_APP_BROKER_PATH, FACTORY_APP_BROKER_TOKEN_PERMISSIONS, FACTORY_CANDIDATE_IMPACT_BASIS_OUTPUT, FACTORY_CANDIDATE_IMPACT_DECISION_OUTPUT, FACTORY_CANDIDATE_IMPACT_INERT_OUTPUT, FACTORY_CANDIDATE_IMPACT_STEP_ID, FACTORY_CANDIDATE_IMPACT_UNSUBSCRIBED_OUTPUT, FACTORY_CANDIDATE_PULL_REQUEST_TYPES, FACTORY_CURSOR_OIDC_AUDIENCE, FACTORY_CURSOR_OIDC_ISSUER, FACTORY_CURSOR_OIDC_JWKS_URL, FACTORY_CURSOR_OIDC_MANAGED_RUNTIME, FACTORY_LIFECYCLE_CONTRACT_JOB_ID, FACTORY_LIFECYCLE_CONTRACT_JOB_NAME, FACTORY_MERGE_FREEZE_APP_TOKEN_STEP_ID, FACTORY_MERGE_FREEZE_CHECK_NAME, FACTORY_MERGE_FREEZE_IF, FACTORY_MERGE_FREEZE_JOB_ID, FACTORY_MERGE_FREEZE_JOB_NAME, FACTORY_MERGE_FREEZE_PERMISSIONS, FACTORY_MERGE_FREEZE_VERIFY_RESULT_EXPRESSION, FACTORY_MERGE_TARGET_REF_CONDITION, FACTORY_PREVIEW_CLEANUP_APP_TOKEN_STEP_ID, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_ID, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_NAME, FACTORY_PREVIEW_CLEANUP_CHECKOUT_REF, FACTORY_PREVIEW_CLEANUP_DEFAULT_SWEEP_CRON, FACTORY_PREVIEW_CLEANUP_DESTROY_STEP_ID, FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_ID, FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_NAME, FACTORY_PREVIEW_CLEANUP_DISCOVER_STEP_ID, FACTORY_PREVIEW_CLEANUP_PR_CLOSED_CONDITION, FACTORY_PREVIEW_CLEANUP_SWEEP_CONDITION, FACTORY_PRODUCTION_IMPACT_BASIS_OUTPUT, FACTORY_PRODUCTION_IMPACT_DECISION_OUTPUT, FACTORY_PRODUCTION_IMPACT_STEP_ID, FACTORY_PRODUCTION_IMPACT_UNSUBSCRIBED_OUTPUT, FACTORY_PROOF_GATE_APP_ID, FACTORY_PROOF_GATE_CHECK_NAME, FACTORY_PROOF_GATE_GUARD, FACTORY_PROOF_GATE_IF, FACTORY_PROOF_GATE_MODE_OUTPUT, FACTORY_PROOF_GATE_OUTPUT, FACTORY_PROOF_GATE_REASONS, FACTORY_PROOF_GATE_REASON_OUTPUT, FACTORY_PROOF_GATE_SHELL, FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT, FACTORY_PROOF_GATE_STEP_ID, FACTORY_PROOF_GATE_STEP_NAME, FACTORY_PR_STATUS_HUD_APP_TOKEN_STEP_ID, FACTORY_PR_STATUS_HUD_CONCURRENCY, FACTORY_PR_STATUS_HUD_IF, FACTORY_PR_STATUS_HUD_JOB_ID, FACTORY_PR_STATUS_HUD_JOB_NAME, FACTORY_PR_STATUS_HUD_PERMISSIONS, FACTORY_PR_STATUS_HUD_PLAN_PATH, FACTORY_PUSH_IDENTITY_SCHEMA_VERSION, type FactoryCandidateImpactWorkflow, type FactoryCandidateImpactWorkflowOptions, type FactoryLifecycleContractLane, type FactoryLifecycleContractLaneOptions, type FactoryMergeFreezeJob, type FactoryMergeFreezeJobOptions, type FactoryPrStatusHudWorkflow, type FactoryPrStatusHudWorkflowOptions, type FactoryPreviewCleanupAuditJob, type FactoryPreviewCleanupDestroyJob, type FactoryPreviewCleanupTopology, type FactoryPreviewCleanupTopologyOptions, type FactoryPreviewCleanupWorkflow, type FactoryPreviewCleanupWorkflowAuditJob, type FactoryPreviewCleanupWorkflowDestroyJob, type FactoryPreviewCleanupWorkflowDiscoverJob, type FactoryPreviewCleanupWorkflowJob, type FactoryPreviewCleanupWorkflowOptions, type FactoryPreviewReceiptWorkflow, type FactoryPreviewReceiptWorkflowOptions, type FactoryProductionImpactWorkflow, type FactoryProductionImpactWorkflowOptions, type FactoryProofGateOptions, type FactoryProofGateReason, type FactoryProofGateStep, type FactoryProofReusePresentationOptions, type FactoryProofReuseSummaryStep, type FactoryProofTimingStartStep, type FactoryPushIdentityConsumer, type FactoryPushIdentityConsumerOptions, type FactoryPushIdentityDisposition, type FactoryPushIdentityEnvelope, type FactoryPushIdentityProducer, type FactoryPushIdentityProducerOptions, type FactoryRunnerDecision, type FactoryRunnerHome, type FactoryRunnerKind, type FactoryRunnerOverride, type FactoryVerifyRunner, type FactoryVerifyRunnerMismatch, type FactoryVerifyRunnerPolicyInput, type FactoryVerifyRunnerPolicyReport, type FactoryVerifyRunnerTable, type FactoryWorkflowArtifact, type FactoryWorkflowOptions, type FactoryWorkflowSetupOptions, GitHubApiError, GitHubAppTokenTransportError, type GithubAppCredentials, type GithubAppInstallationPermissions, type GithubAppTokenOptions, type InstallStepOptions, type LocalPreviewStage, type LocalPreviewStageOptions, NODE_PNPM_ACTION_FAMILY_NODE24, type NodePnpmActionFamily, PREVIEW_PROOF_INVENTORY_CHECK_NAME, PREVIEW_PROOF_INVENTORY_LIST_PERMISSIONS, type ParseLocalPreviewStageExpected, type ParsedLocalPreviewStage, type PinnedAction, type PreviewCleanupPullRequestState, type PreviewCleanupResidue, type PreviewCleanupStackPolicy, type PreviewCleanupSweep, type PreviewCleanupTarget, type PreviewProofCandidate, type PreviewProofCleanupOutcome, type PreviewProofCleanupStatus, type PreviewProofEnvelopeEvidence, type PreviewProofInventoryAccess, type PreviewProofInventoryCleanupInput, type PreviewProofInventoryListInput, type PreviewProofInventoryPersistInput, type PreviewProofInventoryStore, type PreviewProofInventoryTransport, type PreviewProofLifecycleEvent, type PreviewProofLifecycleState, type PreviewProofRegistration, type PreviewProofResolveQuery, PreviewProofTransportError, type ProofReuseCommand, type ProofReuseCoverageInput, type ProofReuseCoverageReport, type ReadPullRequestStatesAccess, type ReadPullRequestStatesInput, type RecordPreviewCleanupOutcomeAccess, type RecordPreviewCleanupOutcomeInput, type RecordPreviewCleanupOutcomeResult, SETUP_STEP_ROLES, type SetupNodeStepOptions, type SetupStepRole, UPLOAD_ARTIFACT, VITEST_PROFILE_SCHEMA_VERSION, VITEST_PROFILE_TOOL, type VitestJsonReport, type VitestProfile, type VitestProfileDependencies, type VitestProfileDurationSummary, type VitestProfileEnvironment, VitestProfileError, type VitestProfileOptions, type VitestProfileReadResult, type VitestProfileSample, type VitestProfileSampleExecution, type VitestTestStatus, type WorkflowShellParseFailure, type WorkflowStep, assertAlchemyBaseline, assertPreviewCleanupStackPolicy, assertPreviewCleanupTargetsAbsent, assertProofReuseCoverage, assertVerifyRunnerPolicy, assertWorkflowShellParses, bundleAlchemyEntry, captureVitestProfileEnvironment, discoverOrphanedPreviewCleanupTargets, discoverPreviewCleanupTargets, executeAlchemyEntry, factoryCandidateImpactWorkflow, factoryCandidateOrPushCondition, factoryLifecycleContractLane, factoryMergeFreezeJob, factoryMergeFreezeScript, factoryPrStatusHudWorkflow, factoryPreviewCleanupTopology, factoryPreviewCleanupWorkflow, factoryPreviewReceiptWorkflow, factoryProductionImpactWorkflow, factoryProofGateScript, factoryProofGateStep, factoryProofReuseSummaryStep, factoryProofTimingStartStep, factoryPushIdentityConsumer, factoryPushIdentityProducer, factoryVerifyRunner, factoryWorkflow, githubAppJwt, isLocalPreviewStage, localPreviewStage, mintInstallationToken, normalizeVitestProfileSample, parseHostedPreviewStage, parseLocalPreviewStage, parsePreviewCleanupResidue, parsePreviewCleanupTargets, previewCleanupDestroyJobId, previewCleanupGithubOutput, previewCleanupResiduePullRequests, previewCleanupStackOutputKey, previewProofInventory, previewProofLifecycle, productionImpactTargetOutput, proofReuseCoverage, proofReuseRequiredCommands, readPullRequestStates, readVitestProfileDocument, recordPreviewCleanupOutcome, resolveProofReuseCommands, runVitestProfile, setupStepsForRoles, verifyRunnerPolicy, workflowRunBlocks, workflowShellParseFailures, writeVitestProfile };
|