@theholocron/cli 5.0.0-alpha.561 → 5.0.0-alpha.563
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 +1 -0
- package/dist/cli.mjs +2485 -1192
- package/dist/cli.mjs.map +1 -1
- package/package.json +5 -5
package/dist/cli.mjs
CHANGED
|
@@ -89,6 +89,7 @@ const COMMAND_CONTEXTS = {
|
|
|
89
89
|
"sync secrets": "workspace",
|
|
90
90
|
"new tunnel": "workspace",
|
|
91
91
|
"new domain": "workspace",
|
|
92
|
+
"new instance": "workspace",
|
|
92
93
|
"list projects": "workspace",
|
|
93
94
|
"new project": "workspace",
|
|
94
95
|
"close project": "workspace",
|
|
@@ -1244,6 +1245,24 @@ const newIncidentEntry = {
|
|
|
1244
1245
|
],
|
|
1245
1246
|
supportsDryRun: true
|
|
1246
1247
|
};
|
|
1248
|
+
// src/commands/new-instance/new-instance.entry.ts
|
|
1249
|
+
const newInstanceEntry = {
|
|
1250
|
+
name: "new instance",
|
|
1251
|
+
description: "Make a whole app instance (project, domain, secrets, GitHub App, deploy), and name only the tokens a person creates",
|
|
1252
|
+
positionals: [{
|
|
1253
|
+
key: "app",
|
|
1254
|
+
message: "App (a folder under apps/):",
|
|
1255
|
+
type: "input"
|
|
1256
|
+
}],
|
|
1257
|
+
options: [{
|
|
1258
|
+
key: "env",
|
|
1259
|
+
flag: "--env",
|
|
1260
|
+
type: "input",
|
|
1261
|
+
message: "Instance to make (preview):"
|
|
1262
|
+
}],
|
|
1263
|
+
skipOptions: ["yes"],
|
|
1264
|
+
supportsDryRun: true
|
|
1265
|
+
};
|
|
1247
1266
|
// src/commands/new-work/new-work.entry.ts
|
|
1248
1267
|
const newWorkEntry = {
|
|
1249
1268
|
name: "new work",
|
|
@@ -2432,6 +2451,7 @@ const registry = createCommandRegistry([
|
|
|
2432
2451
|
githubAppCreateEntry,
|
|
2433
2452
|
tunnelUpEntry,
|
|
2434
2453
|
newDomainEntry,
|
|
2454
|
+
newInstanceEntry,
|
|
2435
2455
|
projectListEntry,
|
|
2436
2456
|
projectCreateEntry,
|
|
2437
2457
|
projectCloseEntry,
|
|
@@ -16142,7 +16162,7 @@ async function relayChecks(input) {
|
|
|
16142
16162
|
const reason = missingTokenReason(err);
|
|
16143
16163
|
rows.push(...reason === void 0 ? [resultRow(WORKER_ID, WORKER_TITLE, [shown$2(describeError(err))], ""), skipRow$1(BINDINGS_ID, BINDINGS_TITLE, "not checked: could not read the Worker")] : skipWorker(reason));
|
|
16144
16164
|
}
|
|
16145
|
-
if (wantsRelay(layout)) rows.push(source ? webhookRow(input, source) : skipRow$1(WEBHOOK_ID, WEBHOOK_TITLE, input.errorsMissingReason));
|
|
16165
|
+
if (wantsRelay(layout)) rows.push(source ? webhookRow$1(input, source) : skipRow$1(WEBHOOK_ID, WEBHOOK_TITLE, input.errorsMissingReason));
|
|
16146
16166
|
for (const feed of generic) rows.push(genericWebhookRow(input, feed));
|
|
16147
16167
|
return rows;
|
|
16148
16168
|
}
|
|
@@ -16154,7 +16174,7 @@ function genericWebhookRow(input, feed) {
|
|
|
16154
16174
|
return webhookProblems(input, id, title, feed.channel.name, feed.webhook, feedAvatarOf(input.layout, feed.feed));
|
|
16155
16175
|
}
|
|
16156
16176
|
/** The error feed's webhook is on its channel, with a picture when the layout or the provider gives one. */
|
|
16157
|
-
function webhookRow(input, source) {
|
|
16177
|
+
function webhookRow$1(input, source) {
|
|
16158
16178
|
if (!input.found) return skipRow$1(WEBHOOK_ID, WEBHOOK_TITLE, "not checked: could not read the server");
|
|
16159
16179
|
const channel = input.layout.categories.flatMap((cat) => cat.channels ?? []).find((c) => c.feeds?.errors);
|
|
16160
16180
|
const feed = channel.feeds.errors;
|
|
@@ -26309,7 +26329,7 @@ const authSetCommand = {
|
|
|
26309
26329
|
* ever printed.
|
|
26310
26330
|
*/
|
|
26311
26331
|
const COMMAND$2 = "new github-app";
|
|
26312
|
-
const DEFAULT_WEBHOOK_SECRET_VAR = "SENTINEL_WEBHOOK_SECRET";
|
|
26332
|
+
const DEFAULT_WEBHOOK_SECRET_VAR$1 = "SENTINEL_WEBHOOK_SECRET";
|
|
26313
26333
|
async function runGithubAppCreate(input) {
|
|
26314
26334
|
const print = input.print ?? ((line) => console.error(line));
|
|
26315
26335
|
const logger = input.logger ?? getLogger();
|
|
@@ -26369,7 +26389,7 @@ async function runGithubAppCreate(input) {
|
|
|
26369
26389
|
server.close();
|
|
26370
26390
|
}
|
|
26371
26391
|
const settings = input.org ? `https://github.com/organizations/${input.org}/settings/apps/${app.slug}/advanced` : `https://github.com/settings/apps/${app.slug}/advanced`;
|
|
26372
|
-
const webhookSecretVar = input.webhookSecretVar || DEFAULT_WEBHOOK_SECRET_VAR;
|
|
26392
|
+
const webhookSecretVar = input.webhookSecretVar || DEFAULT_WEBHOOK_SECRET_VAR$1;
|
|
26373
26393
|
if (collect) {
|
|
26374
26394
|
try {
|
|
26375
26395
|
collect([
|
|
@@ -27328,161 +27348,2002 @@ const newIncidentCommand = {
|
|
|
27328
27348
|
})).status === "fail") process.exitCode = 1;
|
|
27329
27349
|
}
|
|
27330
27350
|
};
|
|
27331
|
-
// src/commands/
|
|
27332
|
-
const NOREPLY = /^(?:\d+\+)?([A-Za-z0-9-]+)@users\.noreply\.github\.com$/;
|
|
27351
|
+
// src/commands/app-layer/app-layer.ts
|
|
27333
27352
|
/**
|
|
27334
|
-
* The
|
|
27335
|
-
*
|
|
27336
|
-
*
|
|
27337
|
-
* `user.name` is a display name, not a login, so it is never guessed from; with neither, there is no default.
|
|
27353
|
+
* The vault layer an app's secrets for a deployment target are read from: `production` reads `prod` and `preview` reads
|
|
27354
|
+
* its own `preview` layer, never `prod` (spec `tech-sentinel-preview-instance`), so a preview deployment is given only
|
|
27355
|
+
* what its own Environment holds.
|
|
27338
27356
|
*/
|
|
27339
|
-
function
|
|
27340
|
-
|
|
27341
|
-
if (login) return login;
|
|
27342
|
-
return NOREPLY.exec(read("user.email")?.trim() ?? "")?.[1];
|
|
27357
|
+
function appLayer(target) {
|
|
27358
|
+
return target === "production" ? "prod" : "preview";
|
|
27343
27359
|
}
|
|
27344
|
-
// src/commands/
|
|
27345
|
-
/**
|
|
27346
|
-
|
|
27347
|
-
|
|
27348
|
-
|
|
27349
|
-
|
|
27350
|
-
|
|
27351
|
-
|
|
27352
|
-
|
|
27353
|
-
|
|
27354
|
-
|
|
27355
|
-
|
|
27356
|
-
|
|
27357
|
-
|
|
27358
|
-
|
|
27359
|
-
|
|
27360
|
-
|
|
27361
|
-
|
|
27362
|
-
|
|
27363
|
-
|
|
27364
|
-
|
|
27365
|
-
|
|
27366
|
-
|
|
27360
|
+
// src/commands/generated-secrets/generated-secrets.ts
|
|
27361
|
+
/**
|
|
27362
|
+
* The secrets the CLI may make up (spec `tech-rotate-generated-secrets`). A name is here only when its value is random
|
|
27363
|
+
* and nobody else issues or holds a copy: a vendor's API token, or a signing secret the vendor also stores, must not be
|
|
27364
|
+
* invented, so anything not listed is refused by `generateSecretValue()`.
|
|
27365
|
+
*/
|
|
27366
|
+
const GENERATED_SECRETS = { CRON_SECRET: {
|
|
27367
|
+
bytes: 32,
|
|
27368
|
+
encoding: "hex",
|
|
27369
|
+
note: "the bearer Vercel's cron sends to Sentinel's /api/scheduled"
|
|
27370
|
+
} };
|
|
27371
|
+
/** The recipe for `name`, or `undefined` when the CLI does not make that secret. */
|
|
27372
|
+
function generatedSecret(name) {
|
|
27373
|
+
return Object.hasOwn(GENERATED_SECRETS, name) ? GENERATED_SECRETS[name] : void 0;
|
|
27374
|
+
}
|
|
27375
|
+
/**
|
|
27376
|
+
* A fresh value for a secret in {@link GENERATED_SECRETS}. The value is never printed or logged by the caller.
|
|
27377
|
+
*
|
|
27378
|
+
* @throws {Error} When `name` is not one the CLI generates (the message lists the ones it does).
|
|
27379
|
+
*/
|
|
27380
|
+
function generateSecretValue(name, random = randomBytes) {
|
|
27381
|
+
const recipe = generatedSecret(name);
|
|
27382
|
+
if (!recipe) throw new Error(`${name} is not a secret the CLI generates (${Object.keys(GENERATED_SECRETS).join(", ")}): a token a vendor issues cannot be made up`);
|
|
27383
|
+
return Buffer.from(random(recipe.bytes)).toString(recipe.encoding);
|
|
27384
|
+
}
|
|
27385
|
+
// src/commands/instance-declaration/instance-declaration.ts
|
|
27386
|
+
/** A list of names: every one a non-empty string, none twice. */
|
|
27387
|
+
function namesOf(app, path, value) {
|
|
27388
|
+
if (value === void 0) return [];
|
|
27389
|
+
if (!Array.isArray(value) || value.some((name) => typeof name !== "string" || name === "")) throw new ConfigError$1(`${app}: \`${path}\` must be a list of names`);
|
|
27390
|
+
const names = value;
|
|
27391
|
+
const repeated = names.find((name, index) => names.indexOf(name) !== index);
|
|
27392
|
+
if (repeated !== void 0) throw new ConfigError$1(`${app}: \`${path}\` lists ${repeated} twice`);
|
|
27393
|
+
return names;
|
|
27394
|
+
}
|
|
27395
|
+
/** An object of name to string. */
|
|
27396
|
+
function constantsOf(app, path, value) {
|
|
27397
|
+
if (value === void 0) return {};
|
|
27398
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new ConfigError$1(`${app}: \`${path}\` must be an object of names to values`);
|
|
27399
|
+
const entries = Object.entries(value);
|
|
27400
|
+
const bad = entries.find(([name, constant]) => name === "" || typeof constant !== "string");
|
|
27401
|
+
if (bad) throw new ConfigError$1(`${app}: \`${path}\` must give ${bad[0] || "every name"} a string value`);
|
|
27402
|
+
return Object.fromEntries(entries);
|
|
27403
|
+
}
|
|
27404
|
+
/**
|
|
27405
|
+
* What the app's preview instance says about where its secrets come from: `generate` (names the CLI makes up), `values`
|
|
27406
|
+
* (non-secret constants) and `copy` (names read from the `prod` Environment), each in the `deployment` options'
|
|
27407
|
+
* `instances.preview` next to its `project` and `domain` (spec `tech-new-instance-command`). `undefined` when the app
|
|
27408
|
+
* declares no preview instance; `previewInstance()` is the one that judges the instance itself, so a malformed one is
|
|
27409
|
+
* not this function's to report.
|
|
27410
|
+
*
|
|
27411
|
+
* @param app - The app's name, for the message.
|
|
27412
|
+
* @param options - The `deployment` provider's options from the app's config.
|
|
27413
|
+
* @throws {ConfigError} For a list or object of the wrong shape, a name listed twice, or a `generate` name the CLI does
|
|
27414
|
+
* not make (a token a vendor issues cannot be made up).
|
|
27415
|
+
*/
|
|
27416
|
+
function instanceDeclaration(app, options) {
|
|
27417
|
+
const instances = options.instances;
|
|
27418
|
+
const declared = instances && typeof instances === "object" ? instances.preview : void 0;
|
|
27419
|
+
if (!declared || typeof declared !== "object") return void 0;
|
|
27420
|
+
const entry = declared;
|
|
27421
|
+
const generate = namesOf(app, "instances.preview.generate", entry.generate);
|
|
27422
|
+
const unknown = generate.find((name) => !generatedSecret(name));
|
|
27423
|
+
if (unknown !== void 0) throw new ConfigError$1(`${app}: \`instances.preview.generate\` names ${unknown}, which the CLI does not make up: a token a vendor issues is made by a person`);
|
|
27424
|
+
return {
|
|
27425
|
+
generate,
|
|
27426
|
+
values: constantsOf(app, "instances.preview.values", entry.values),
|
|
27427
|
+
copy: namesOf(app, "instances.preview.copy", entry.copy)
|
|
27428
|
+
};
|
|
27429
|
+
}
|
|
27430
|
+
// src/commands/secrets-sync/secret-routes.ts
|
|
27431
|
+
/**
|
|
27432
|
+
* The routes into `secrets` that `repo.secrets.sync` declares for one vault environment: every entry naming it gives
|
|
27433
|
+
* its keys (all of them when omitted) and the scope they land at (`repo` when omitted). An environment no entry names
|
|
27434
|
+
* has no routes, which leaves `sync secrets` to its own flags. An organization scope also carries
|
|
27435
|
+
* `visibility: "selected"` and its `repos`, as names in the organization (spec `tech-org-secret-visibility`, #2062).
|
|
27436
|
+
*
|
|
27437
|
+
* @param entries - `repo.secrets.sync`, if the config has it.
|
|
27438
|
+
* @param environmentId - The vault environment being synced.
|
|
27439
|
+
* @throws When an entry's `scope` is not `repo`, `env=<name>` or `org=<name>`.
|
|
27440
|
+
*/
|
|
27441
|
+
function secretRoutes(entries, environmentId) {
|
|
27442
|
+
return (entries ?? []).filter((entry) => entry.environment === environmentId).map((entry) => {
|
|
27443
|
+
const scope = parseScope(entry.scope ?? "repo");
|
|
27444
|
+
return {
|
|
27445
|
+
scope: scope.kind === "organization" && entry.repos ? {
|
|
27446
|
+
...scope,
|
|
27447
|
+
visibility: "selected",
|
|
27448
|
+
repos: entry.repos.map(repoName)
|
|
27449
|
+
} : scope,
|
|
27450
|
+
...entry.keys ? { keys: entry.keys } : {}
|
|
27451
|
+
};
|
|
27367
27452
|
});
|
|
27368
|
-
return answer === "none" ? void 0 : answer;
|
|
27369
27453
|
}
|
|
27370
|
-
// src/commands/
|
|
27371
|
-
/**
|
|
27372
|
-
|
|
27373
|
-
|
|
27374
|
-
|
|
27375
|
-
|
|
27376
|
-
|
|
27377
|
-
|
|
27378
|
-
|
|
27379
|
-
|
|
27380
|
-
|
|
27381
|
-
|
|
27454
|
+
// src/commands/secrets-sync/github-name/github-name.ts
|
|
27455
|
+
/**
|
|
27456
|
+
* Why GitHub would refuse `name` as an Actions secret or variable name, or `undefined` when it would accept it.
|
|
27457
|
+
*
|
|
27458
|
+
* GitHub's rules (the same for repository, environment and organization secrets and variables): letters, digits and
|
|
27459
|
+
* underscores only, no spaces, not starting with a digit, and not starting with `GITHUB_` (reserved, in any case).
|
|
27460
|
+
* A name that breaks one gets a bare 422 from the API, which no retry can fix, so the sync checks first.
|
|
27461
|
+
*
|
|
27462
|
+
* @param name - The secret or variable name.
|
|
27463
|
+
*/
|
|
27464
|
+
function githubNameProblem(name) {
|
|
27465
|
+
if (name === "") return "GitHub names cannot be empty";
|
|
27466
|
+
if (!/^[A-Za-z0-9_]+$/.test(name)) return "GitHub names may only contain letters, digits and underscores";
|
|
27467
|
+
if (/^[0-9]/.test(name)) return "GitHub names cannot start with a number";
|
|
27468
|
+
if (/^GITHUB_/i.test(name)) return "GitHub reserves names starting with GITHUB_";
|
|
27382
27469
|
}
|
|
27383
|
-
// src/commands/
|
|
27470
|
+
// src/commands/secrets-sync/restore-pem/restore-pem.ts
|
|
27471
|
+
/** A PEM block written on one line: the begin marker, the body, the end marker, with spaces between them. */
|
|
27472
|
+
const COLLAPSED = /^(-----BEGIN [A-Z0-9 ]+-----) ([\s\S]+?) (-----END [A-Z0-9 ]+-----)$/;
|
|
27473
|
+
/** Base64 lines in a PEM are 64 characters wide. */
|
|
27474
|
+
const LINE_WIDTH = 64;
|
|
27384
27475
|
/**
|
|
27385
|
-
*
|
|
27386
|
-
*
|
|
27387
|
-
*
|
|
27388
|
-
*
|
|
27389
|
-
*
|
|
27390
|
-
*
|
|
27391
|
-
*
|
|
27476
|
+
* Put a PEM back on its lines when its line breaks were turned into spaces. A key pasted into a single-line field
|
|
27477
|
+
* (a 1Password Environment variable, a form) arrives as `-----BEGIN ... KEY----- MIIE... -----END ... KEY-----`, which
|
|
27478
|
+
* Node's crypto, OpenSSL and `actions/create-github-app-token` refuse (`DECODER routines::unsupported`). The header and
|
|
27479
|
+
* footer go on their own lines and the body is cut into 64-character lines.
|
|
27480
|
+
*
|
|
27481
|
+
* Anything else is returned as it came: a PEM already on its lines, a value that is not a PEM, a block whose end marker
|
|
27482
|
+
* does not match its begin marker, and a legacy encrypted key (its body holds `Proc-Type:` header fields, whose own
|
|
27483
|
+
* line breaks cannot be rebuilt). Running it twice gives the same result as running it once.
|
|
27392
27484
|
*/
|
|
27393
|
-
|
|
27394
|
-
|
|
27395
|
-
|
|
27396
|
-
|
|
27397
|
-
|
|
27398
|
-
|
|
27399
|
-
});
|
|
27400
|
-
|
|
27401
|
-
|
|
27485
|
+
function restorePem(value) {
|
|
27486
|
+
const match = COLLAPSED.exec(value.trim());
|
|
27487
|
+
if (!match) return value;
|
|
27488
|
+
const [, begin, body, end] = match;
|
|
27489
|
+
if (begin.replace("BEGIN", "END") !== end || body.includes(":")) return value;
|
|
27490
|
+
const lines = body.replace(/\s+/g, "").match(new RegExp(`.{1,${LINE_WIDTH}}`, "g"));
|
|
27491
|
+
return lines ? `${begin}\n${lines.join("\n")}\n${end}\n` : value;
|
|
27492
|
+
}
|
|
27493
|
+
// src/commands/secrets-sync/secrets-sync.ts
|
|
27494
|
+
/**
|
|
27495
|
+
* `holocron sync secrets` — vault → destinations.
|
|
27496
|
+
*
|
|
27497
|
+
* Reads a named environment from the configured `vault` (1P
|
|
27498
|
+
* Environment / similar) as KEY=VALUE pairs, then fans those values
|
|
27499
|
+
* out to the configured destinations:
|
|
27500
|
+
*
|
|
27501
|
+
* - `secrets` capability (e.g., GH Actions secrets) — repo-scope
|
|
27502
|
+
* - `deployment` capability (e.g., Vercel env vars) — per-target
|
|
27503
|
+
* - local `.env` file (optional, planned for v5.1 — currently skipped
|
|
27504
|
+
* with a soft "not yet" note)
|
|
27505
|
+
*
|
|
27506
|
+
* Per-secret routing rules:
|
|
27507
|
+
*
|
|
27508
|
+
* - `deployment` (for each target the caller asks for, defaults: production + preview) and a Worker's secrets fail
|
|
27509
|
+
* closed (#2061): they receive only the keys `repo.secrets.deploy` names for this environment (an exact `keys`
|
|
27510
|
+
* list and/or a `prefix`), passed in as `deployFilter`. With none, the run throws a `ConfigError` before it reads
|
|
27511
|
+
* the vault. A name outside the filter is reported by name only and never reaches the provider.
|
|
27512
|
+
* - `secrets` (GH Actions) fails closed too (#2104): with no `repo.secrets.sync` entry for the environment, no
|
|
27513
|
+
* `--github-secret` (`--github-secret-scope` alone names no keys and is refused) and no deployment or Worker destination, the run throws a
|
|
27514
|
+
* `ConfigError` before the vault is read, `--dry-run` included. A deployment or Worker sync alone writes nothing
|
|
27515
|
+
* to `secrets`. Where a destination is named, `secrets` defaults to every key, repo-scoped — and a
|
|
27516
|
+
* caller can pass `githubSecretKeys` (an allowlist, from repeatable
|
|
27517
|
+
* `--github-secret KEY` CLI values) to restrict `secrets` to only
|
|
27518
|
+
* those keys, and `githubSecretScope` (same `{ kind }` shape `secret
|
|
27519
|
+
* set`'s own `--scope repo|env=NAME|org=NAME` parses to) to apply one
|
|
27520
|
+
* scope to all of them. A key not in the allowlist is skipped for
|
|
27521
|
+
* `secrets` entirely — still synced to `deployment` if configured.
|
|
27522
|
+
* Needed for a vault holding a mix of deploy-only secrets and one
|
|
27523
|
+
* CI-consumed, org-wide secret (holocron#781's Sentinel case: 4
|
|
27524
|
+
* Vercel-only keys + one org-scoped Axiom ingest token that
|
|
27525
|
+
* a workflow in `theholocron/.github` also read).
|
|
27526
|
+
* - With no `--github-secret`, the routes come from `repo.secrets.sync`: every
|
|
27527
|
+
* entry for this environment gives `secrets` its own keys and scope, one
|
|
27528
|
+
* step per scope, so one environment can fill organization and repository
|
|
27529
|
+
* secrets in one run.
|
|
27530
|
+
* - `repo.variables.sync` entries for this environment give Actions variables: each key goes through the `source`
|
|
27531
|
+
* provider's `syncVariables` (repo scope) or `syncOrgVariables`, one call per key, without pruning. An
|
|
27532
|
+
* environment with only variable entries pushes nothing to `secrets` or `deployment`.
|
|
27533
|
+
* - A key that is blank in the vault is skipped in every destination, and a
|
|
27534
|
+
* listed key the vault does not hold is a skipped row.
|
|
27535
|
+
*
|
|
27536
|
+
* The vault MUST implement `readEnvironment(envId)` (optional method).
|
|
27537
|
+
* If it doesn't, the command errors with a hint to populate the keys
|
|
27538
|
+
* individually via `holocron new secret` (also planned for v5.1).
|
|
27539
|
+
*/
|
|
27540
|
+
/**
|
|
27541
|
+
* The `ConfigError` text for a sync that names no destination for `secrets`: the environment, and the environments
|
|
27542
|
+
* `repo.secrets.sync` does have an entry for.
|
|
27543
|
+
*/
|
|
27544
|
+
function noSecretsEntryMessage(environmentId, entries) {
|
|
27545
|
+
const known = [...new Set(entries.map((entry) => resolvedEnvironment(entry)))];
|
|
27546
|
+
const list = known.length > 0 ? known.map((name) => JSON.stringify(name)).join(", ") : "none";
|
|
27547
|
+
return `no \`repo.secrets.sync\` entry for environment ${JSON.stringify(environmentId)}: a sync with no entry would write every key to the repository's secrets. Environments with an entry: ${list}. Add { environment: ${JSON.stringify(environmentId)}, keys: [...], scope: "repo" } (or layer: "<layer>") to repo.secrets.sync, or name the destination with --github-secret <KEY> (with --github-secret-scope for another scope)`;
|
|
27548
|
+
}
|
|
27549
|
+
/** Why there is no `workers` provider: the plugin's own load error when it failed to load (e.g. a missing account id). */
|
|
27550
|
+
function workersMissing(loader) {
|
|
27551
|
+
const base = "--worker needs a `workers` provider in holocron.config.ts";
|
|
27552
|
+
const failure = loader.loadFailures().find((f) => f.key === "workers");
|
|
27553
|
+
return failure ? `${base} (\`${failure.provider}\` failed to load: ${describeError(failure.error)})` : base;
|
|
27554
|
+
}
|
|
27555
|
+
async function runSecretsSync(input) {
|
|
27556
|
+
await assertSyncableLayer(input.environmentId, {
|
|
27557
|
+
repoRoot: input.context.repoRoot,
|
|
27558
|
+
...input.gitExec ? { gitExec: input.gitExec } : {}
|
|
27559
|
+
});
|
|
27402
27560
|
const print = input.print ?? ((line) => console.log(line));
|
|
27403
|
-
const
|
|
27404
|
-
const
|
|
27405
|
-
|
|
27406
|
-
|
|
27407
|
-
|
|
27408
|
-
|
|
27409
|
-
|
|
27410
|
-
|
|
27411
|
-
|
|
27412
|
-
|
|
27413
|
-
|
|
27414
|
-
|
|
27415
|
-
|
|
27416
|
-
|
|
27561
|
+
const logger = input.logger ?? getLogger();
|
|
27562
|
+
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
27563
|
+
await withSpinner("Loading plugins…", () => loader.load());
|
|
27564
|
+
assertPluginsResolvable(loader, "sync secrets");
|
|
27565
|
+
logger.info({
|
|
27566
|
+
environment: input.environmentId,
|
|
27567
|
+
dryRun: (input.context.dryRun ?? false) || void 0
|
|
27568
|
+
}, "sync secrets: start");
|
|
27569
|
+
const dryRun = input.context.dryRun ?? false;
|
|
27570
|
+
const variablesOnly = (input.variableRoutes?.length ?? 0) > 0 && input.secretRoutes?.length === 0 && !input.projectId;
|
|
27571
|
+
if ((loader.has("deployment") && !variablesOnly && Boolean(input.projectId) || input.workerScript) && !input.deployFilter) throw new ConfigError$1(`no \`repo.secrets.deploy\` entry for environment ${JSON.stringify(input.environmentId)}: a deployment or a Worker receives only the keys named by \`keys\` or \`prefix\`, never every key. Add { environment: ${JSON.stringify(input.environmentId)}, prefix: "<PREFIX>_" } (or keys: [...]) to repo.secrets.deploy`);
|
|
27572
|
+
const namesSecretsDestination = input.secretRoutes !== void 0 || Boolean(input.githubSecretKeys?.length);
|
|
27573
|
+
if (!namesSecretsDestination && input.githubSecretScope !== void 0) throw new ConfigError$1(`--github-secret-scope names a scope but no keys: pass the keys to write with --github-secret <KEY>, or declare environment ${JSON.stringify(input.environmentId)} in \`repo.secrets.sync\``);
|
|
27574
|
+
if (!namesSecretsDestination && !input.projectId && !input.workerScript) throw new ConfigError$1(noSecretsEntryMessage(input.environmentId, input.loaded.resolved.repo?.secrets?.sync ?? []));
|
|
27575
|
+
for (const route of input.secretRoutes ?? [{ scope: input.githubSecretScope ?? { kind: "repo" } }]) if (route.scope.kind === "organization" && !route.scope.repos?.length) throw new ConfigError$1(`organization secrets (org=${route.scope.name}) need an explicit reader list: declare them in \`repo.secrets.sync\` with \`repos: [...]\` (visibility "selected"), never "all"`);
|
|
27576
|
+
const targets = input.targets ?? ["production", "preview"];
|
|
27577
|
+
print(style.header(`Holocron sync secrets — environment ${input.environmentId}${dryRun ? " (dry-run)" : ""}`));
|
|
27578
|
+
print(style.dim(` vault: ${vaultProviderName(loader)}`));
|
|
27579
|
+
print("");
|
|
27580
|
+
const vault = loader.get("vault");
|
|
27581
|
+
if (!vault.readEnvironment) throw new Error(`vault provider (${vault.providerName}) does not implement readEnvironment — sync needs bulk env reads`);
|
|
27582
|
+
let envVars;
|
|
27583
|
+
try {
|
|
27584
|
+
envVars = await withSpinner(`Reading vault environment ${input.environmentId}…`, () => vault.readEnvironment(input.environmentId));
|
|
27585
|
+
} catch (err) {
|
|
27586
|
+
const message = describeError(err);
|
|
27587
|
+
print(` ${style.fail(`could not read vault environment ${input.environmentId}: ${message}`)}`);
|
|
27588
|
+
logger.warn({
|
|
27589
|
+
environment: input.environmentId,
|
|
27590
|
+
reason: logReason(err)
|
|
27591
|
+
}, "sync secrets: vault read failed");
|
|
27592
|
+
return summarise$2([{
|
|
27593
|
+
destination: `vault:${vault.providerName}`,
|
|
27594
|
+
scope: `environment=${input.environmentId}`,
|
|
27595
|
+
key: "(all)",
|
|
27596
|
+
status: "fail",
|
|
27597
|
+
message
|
|
27598
|
+
}], logger, print, dryRun);
|
|
27599
|
+
}
|
|
27600
|
+
const keys = Object.keys(envVars).sort();
|
|
27601
|
+
print(style.step(`read ${keys.length} keys from vault`));
|
|
27602
|
+
print("");
|
|
27603
|
+
const deploySplit = input.deployFilter ? splitDeployKeys(keys, input.deployFilter) : void 0;
|
|
27604
|
+
const rows = [];
|
|
27605
|
+
if (loader.has("secrets")) {
|
|
27606
|
+
const secrets = loader.get("secrets");
|
|
27607
|
+
const routes = input.secretRoutes ?? (input.githubSecretKeys?.length ? [{
|
|
27608
|
+
scope: input.githubSecretScope ?? { kind: "repo" },
|
|
27609
|
+
keys: input.githubSecretKeys
|
|
27610
|
+
}] : []);
|
|
27611
|
+
for (const route of routes) {
|
|
27612
|
+
print(style.step(routes.length > 1 ? `secrets (${scopeLabel(route.scope)})` : "secrets"));
|
|
27613
|
+
const access = await readAccess(secrets, route.scope, print);
|
|
27614
|
+
for (const key of route.keys ?? keys) {
|
|
27615
|
+
const row = await pushRow(`secrets:${secrets.providerName}`, scopeLabel(route.scope), key, envVars, dryRun, async (value) => {
|
|
27616
|
+
await secrets.setSecret(route.scope, key, value);
|
|
27617
|
+
}, nameCheck(secrets.providerName));
|
|
27618
|
+
if (access && (row.status === "ok" || row.status === "dry-run")) row.message = accessNote({
|
|
27619
|
+
visibility: "selected",
|
|
27620
|
+
repos: access.wanted
|
|
27621
|
+
}, access.current?.get(key.toUpperCase()), access.current !== void 0);
|
|
27622
|
+
rows.push(row);
|
|
27623
|
+
print(formatRow(row));
|
|
27624
|
+
}
|
|
27625
|
+
}
|
|
27626
|
+
}
|
|
27627
|
+
const variableRoutes = input.variableRoutes ?? [];
|
|
27628
|
+
if (variableRoutes.length > 0) {
|
|
27629
|
+
const source = loader.has("source") ? loader.get("source") : void 0;
|
|
27630
|
+
for (const route of variableRoutes) {
|
|
27631
|
+
const scope = scopeLabel(route.scope);
|
|
27632
|
+
print(style.step(`variables (${scope})`));
|
|
27633
|
+
const destination = `variables:${source?.providerName ?? "source"}`;
|
|
27634
|
+
const org = route.scope.kind === "organization" ? route.scope.name : void 0;
|
|
27635
|
+
const unsupported = !source ? "needs a `source` provider in holocron.config.ts" : org === void 0 && !source.syncVariables ? `source provider (${source.providerName}) does not implement syncVariables` : org !== void 0 && !source.syncOrgVariables ? `source provider (${source.providerName}) does not implement syncOrgVariables` : void 0;
|
|
27636
|
+
if (unsupported) {
|
|
27637
|
+
const row = {
|
|
27638
|
+
destination,
|
|
27639
|
+
scope,
|
|
27640
|
+
key: "(all)",
|
|
27641
|
+
status: "fail",
|
|
27642
|
+
message: unsupported
|
|
27643
|
+
};
|
|
27644
|
+
rows.push(row);
|
|
27645
|
+
print(formatRow(row));
|
|
27646
|
+
continue;
|
|
27647
|
+
}
|
|
27648
|
+
for (const key of route.keys) {
|
|
27649
|
+
rows.push(await pushRow(destination, scope, key, envVars, dryRun, async (value) => {
|
|
27650
|
+
if (org === void 0) await source.syncVariables({ [key]: value }, { prune: false });
|
|
27651
|
+
else await source.syncOrgVariables(org, { [key]: {
|
|
27652
|
+
value,
|
|
27653
|
+
visibility: route.visibility ?? "all"
|
|
27654
|
+
} }, { prune: false });
|
|
27655
|
+
}, nameCheck(source.providerName)));
|
|
27656
|
+
print(formatRow(rows[rows.length - 1]));
|
|
27657
|
+
}
|
|
27658
|
+
}
|
|
27659
|
+
}
|
|
27660
|
+
if (loader.has("deployment") && !variablesOnly) {
|
|
27661
|
+
const deploy = loader.get("deployment");
|
|
27662
|
+
if (!input.projectId) {
|
|
27663
|
+
print(style.step("deployment"));
|
|
27664
|
+
const row = {
|
|
27665
|
+
destination: `deployment:${deploy.providerName}`,
|
|
27666
|
+
scope: "no projectId",
|
|
27667
|
+
key: "(all)",
|
|
27668
|
+
status: "skip",
|
|
27669
|
+
message: "projectId required for deployment env-var sync (pass --project-id)"
|
|
27417
27670
|
};
|
|
27671
|
+
rows.push(row);
|
|
27672
|
+
print(formatRow(row));
|
|
27673
|
+
} else for (const target of targets) {
|
|
27674
|
+
print(style.step(`deployment (target=${target})`));
|
|
27675
|
+
const destination = `deployment:${deploy.providerName}`;
|
|
27676
|
+
reportFiltered(destination, `target=${target}`, deploySplit.filtered, input.deployFilter, rows, print);
|
|
27677
|
+
for (const key of deploySplit.send) {
|
|
27678
|
+
rows.push(await pushRow(destination, `target=${target}`, key, envVars, dryRun, async (value) => {
|
|
27679
|
+
await deploy.setEnvVar(input.projectId, target, key, value);
|
|
27680
|
+
}));
|
|
27681
|
+
print(formatRow(rows[rows.length - 1]));
|
|
27682
|
+
}
|
|
27418
27683
|
}
|
|
27419
|
-
|
|
27420
|
-
|
|
27421
|
-
|
|
27422
|
-
|
|
27423
|
-
|
|
27684
|
+
}
|
|
27685
|
+
if (input.workerScript) {
|
|
27686
|
+
const script = input.workerScript;
|
|
27687
|
+
print(style.step(`workers (script=${script})`));
|
|
27688
|
+
const workers = loader.has("workers") ? loader.get("workers") : void 0;
|
|
27689
|
+
if (!workers?.setSecret) {
|
|
27690
|
+
const row = {
|
|
27691
|
+
destination: "workers",
|
|
27692
|
+
scope: `script=${script}`,
|
|
27693
|
+
key: "(all)",
|
|
27424
27694
|
status: "fail",
|
|
27425
|
-
|
|
27426
|
-
specPath
|
|
27695
|
+
message: workers ? `workers provider (${workers.providerName}) cannot set secrets` : workersMissing(loader)
|
|
27427
27696
|
};
|
|
27697
|
+
rows.push(row);
|
|
27698
|
+
print(formatRow(row));
|
|
27699
|
+
} else {
|
|
27700
|
+
reportFiltered(`workers:${workers.providerName}`, `script=${script}`, deploySplit.filtered, input.deployFilter, rows, print);
|
|
27701
|
+
for (const key of deploySplit.send) {
|
|
27702
|
+
rows.push(await pushRow(`workers:${workers.providerName}`, `script=${script}`, key, envVars, dryRun, async (value) => {
|
|
27703
|
+
await workers.setSecret(script, key, value);
|
|
27704
|
+
}));
|
|
27705
|
+
print(formatRow(rows[rows.length - 1]));
|
|
27706
|
+
}
|
|
27428
27707
|
}
|
|
27429
27708
|
}
|
|
27430
|
-
|
|
27431
|
-
|
|
27432
|
-
|
|
27433
|
-
|
|
27434
|
-
|
|
27435
|
-
|
|
27436
|
-
|
|
27437
|
-
|
|
27438
|
-
|
|
27709
|
+
return summarise$2(rows, logger, print, dryRun);
|
|
27710
|
+
}
|
|
27711
|
+
/**
|
|
27712
|
+
* Record the vault keys a deployment or Worker filter left out: one skipped row each (names only; the value is never
|
|
27713
|
+
* read for them) and one line naming them all, so the dry run and the real run show what stayed behind.
|
|
27714
|
+
*/
|
|
27715
|
+
function reportFiltered(destination, scope, filtered, filter, rows, print) {
|
|
27716
|
+
const allowed = [...filter.prefixes.map((p) => `${p}*`), ...filter.keys].join(", ");
|
|
27717
|
+
for (const key of filtered) rows.push({
|
|
27718
|
+
destination,
|
|
27719
|
+
scope,
|
|
27720
|
+
key,
|
|
27721
|
+
status: "skip",
|
|
27722
|
+
message: `filtered: not in repo.secrets.deploy (${allowed})`
|
|
27439
27723
|
});
|
|
27440
|
-
if (
|
|
27441
|
-
|
|
27442
|
-
|
|
27443
|
-
|
|
27444
|
-
|
|
27445
|
-
|
|
27446
|
-
|
|
27447
|
-
|
|
27448
|
-
|
|
27449
|
-
|
|
27450
|
-
};
|
|
27451
|
-
|
|
27452
|
-
|
|
27453
|
-
return {
|
|
27454
|
-
status: "ok",
|
|
27455
|
-
rows,
|
|
27456
|
-
...created.key ? { key: created.key } : {}
|
|
27457
|
-
};
|
|
27458
|
-
}
|
|
27459
|
-
if (dryRun || !created.key) {
|
|
27460
|
-
print(` ${style.skip(`would write ${specPath} from the new issue; nothing is written on a dry run`)}`);
|
|
27724
|
+
if (filtered.length > 0) print(style.dim(` · not sent (${filtered.length}, outside ${allowed}): ${filtered.join(", ")}`));
|
|
27725
|
+
}
|
|
27726
|
+
/**
|
|
27727
|
+
* For an organization scope: the readers the entry declares and, when the provider can report them, who can read each
|
|
27728
|
+
* secret now (by upper-cased name, since GitHub treats names as case-insensitive). A listing that fails is said once
|
|
27729
|
+
* and the write goes on without the difference. `undefined` for any other scope.
|
|
27730
|
+
*/
|
|
27731
|
+
async function readAccess(secrets, scope, print) {
|
|
27732
|
+
if (scope.kind !== "organization") return void 0;
|
|
27733
|
+
const wanted = scope.repos;
|
|
27734
|
+
if (!secrets.listSecretAccess) return { wanted };
|
|
27735
|
+
try {
|
|
27736
|
+
const found = await secrets.listSecretAccess(scope);
|
|
27461
27737
|
return {
|
|
27462
|
-
|
|
27463
|
-
|
|
27464
|
-
specPath
|
|
27738
|
+
wanted,
|
|
27739
|
+
current: new Map(Object.entries(found).map(([name, a]) => [name.toUpperCase(), a]))
|
|
27465
27740
|
};
|
|
27741
|
+
} catch (err) {
|
|
27742
|
+
print(style.dim(` · could not read who can read the organization's secrets (${describeError(err)})`));
|
|
27743
|
+
return { wanted };
|
|
27466
27744
|
}
|
|
27467
|
-
|
|
27468
|
-
|
|
27469
|
-
|
|
27470
|
-
|
|
27471
|
-
|
|
27472
|
-
|
|
27473
|
-
|
|
27474
|
-
|
|
27475
|
-
|
|
27745
|
+
}
|
|
27746
|
+
/** Log every row, then print and log the summary. Shared by a finished run and one that stopped at the vault. */
|
|
27747
|
+
function summarise$2(rows, logger, print, dryRun) {
|
|
27748
|
+
for (const r of rows) logger[r.status === "fail" ? "warn" : "info"]({
|
|
27749
|
+
destination: r.destination,
|
|
27750
|
+
scope: r.scope,
|
|
27751
|
+
key: r.key,
|
|
27752
|
+
status: r.status,
|
|
27753
|
+
...r.message ? { detail: r.message } : {}
|
|
27754
|
+
}, `sync secrets: ${r.key} → ${r.destination}`);
|
|
27755
|
+
const summary = rows.reduce((acc, r) => {
|
|
27756
|
+
if (r.status === "ok") acc.ok += 1;
|
|
27757
|
+
else if (r.status === "fail") acc.fail += 1;
|
|
27758
|
+
else if (r.status === "skip") acc.skip += 1;
|
|
27759
|
+
else if (r.status === "dry-run") acc.dryRun += 1;
|
|
27760
|
+
return acc;
|
|
27761
|
+
}, {
|
|
27762
|
+
ok: 0,
|
|
27763
|
+
fail: 0,
|
|
27764
|
+
skip: 0,
|
|
27765
|
+
dryRun: 0
|
|
27476
27766
|
});
|
|
27477
|
-
|
|
27478
|
-
|
|
27479
|
-
|
|
27480
|
-
|
|
27767
|
+
logger[summary.fail > 0 ? "warn" : "info"]({
|
|
27768
|
+
...summary,
|
|
27769
|
+
keys: rows.length
|
|
27770
|
+
}, "sync secrets: done");
|
|
27771
|
+
print("");
|
|
27772
|
+
const summaryLine = `${summary.ok} ok, ${summary.fail} fail, ${summary.skip} skipped${dryRun ? `, ${summary.dryRun} would-do` : ""}`;
|
|
27773
|
+
print(summary.fail > 0 ? style.fail(summaryLine) : style.success(summaryLine));
|
|
27481
27774
|
return {
|
|
27482
|
-
|
|
27483
|
-
|
|
27484
|
-
|
|
27485
|
-
|
|
27775
|
+
rows,
|
|
27776
|
+
summary
|
|
27777
|
+
};
|
|
27778
|
+
}
|
|
27779
|
+
/**
|
|
27780
|
+
* One key to one destination. A key the vault does not hold, or holds blank, is a skipped row: a blank is a placeholder
|
|
27781
|
+
* for a value still to be found, and pushing it would overwrite a working secret with nothing (which no provider can
|
|
27782
|
+
* read back to undo). Everything else goes through {@link runRow}.
|
|
27783
|
+
*/
|
|
27784
|
+
async function pushRow(destination, scope, key, envVars, dryRun, body, nameProblem) {
|
|
27785
|
+
const problem = nameProblem?.(key);
|
|
27786
|
+
if (problem) return {
|
|
27787
|
+
destination,
|
|
27788
|
+
scope,
|
|
27789
|
+
key,
|
|
27790
|
+
status: "skip",
|
|
27791
|
+
message: `invalid name: ${problem}`
|
|
27792
|
+
};
|
|
27793
|
+
const value = Object.hasOwn(envVars, key) ? envVars[key] : void 0;
|
|
27794
|
+
if (value === void 0) return {
|
|
27795
|
+
destination,
|
|
27796
|
+
scope,
|
|
27797
|
+
key,
|
|
27798
|
+
status: "skip",
|
|
27799
|
+
message: "not in the vault environment"
|
|
27800
|
+
};
|
|
27801
|
+
if (value.trim() === "") return {
|
|
27802
|
+
destination,
|
|
27803
|
+
scope,
|
|
27804
|
+
key,
|
|
27805
|
+
status: "skip",
|
|
27806
|
+
message: "blank in the vault environment"
|
|
27807
|
+
};
|
|
27808
|
+
return runRow(destination, scope, key, dryRun, () => body(restorePem(value)));
|
|
27809
|
+
}
|
|
27810
|
+
/** The name check for a destination: GitHub's rules when the provider is `github`, none for any other. */
|
|
27811
|
+
function nameCheck(providerName) {
|
|
27812
|
+
return providerName === "github" ? githubNameProblem : void 0;
|
|
27813
|
+
}
|
|
27814
|
+
async function runRow(destination, scope, key, dryRun, body) {
|
|
27815
|
+
if (dryRun) return {
|
|
27816
|
+
destination,
|
|
27817
|
+
scope,
|
|
27818
|
+
key,
|
|
27819
|
+
status: "dry-run"
|
|
27820
|
+
};
|
|
27821
|
+
try {
|
|
27822
|
+
await body();
|
|
27823
|
+
return {
|
|
27824
|
+
destination,
|
|
27825
|
+
scope,
|
|
27826
|
+
key,
|
|
27827
|
+
status: "ok"
|
|
27828
|
+
};
|
|
27829
|
+
} catch (err) {
|
|
27830
|
+
return {
|
|
27831
|
+
destination,
|
|
27832
|
+
scope,
|
|
27833
|
+
key,
|
|
27834
|
+
status: "fail",
|
|
27835
|
+
message: errorMessage(err)
|
|
27836
|
+
};
|
|
27837
|
+
}
|
|
27838
|
+
}
|
|
27839
|
+
function formatRow(row) {
|
|
27840
|
+
const detail = row.message ? style.dim(` (${row.message})`) : "";
|
|
27841
|
+
const label = `${row.key}${detail}`;
|
|
27842
|
+
if (row.status === "ok") return ` ${style.success(label)}`;
|
|
27843
|
+
if (row.status === "fail") return ` ${style.fail(label)}`;
|
|
27844
|
+
if (row.status === "dry-run") return ` ${style.dim(`… ${label}`)}`;
|
|
27845
|
+
return ` ${style.dim(`· ${label}`)}`;
|
|
27846
|
+
}
|
|
27847
|
+
function scopeLabel(scope) {
|
|
27848
|
+
if (scope.kind === "repo") return "scope=repo";
|
|
27849
|
+
if (scope.kind === "organization") return `scope=organization,org=${scope.name}`;
|
|
27850
|
+
return `scope=environment,env=${scope.name}`;
|
|
27851
|
+
}
|
|
27852
|
+
function vaultProviderName(loader) {
|
|
27853
|
+
if (!loader.has("vault")) return "<missing>";
|
|
27854
|
+
return loader.get("vault").providerName;
|
|
27855
|
+
}
|
|
27856
|
+
// src/commands/secrets-sync/variable-routes.ts
|
|
27857
|
+
/**
|
|
27858
|
+
* The routes into Actions variables that `repo.variables.sync` declares for one vault environment: every entry naming
|
|
27859
|
+
* it gives its keys and the scope they land at (`repo` when omitted). An environment no entry names has none.
|
|
27860
|
+
*
|
|
27861
|
+
* @param entries - `repo.variables.sync`, if the config has it.
|
|
27862
|
+
* @param environmentId - The vault environment being synced.
|
|
27863
|
+
* @throws When an entry's `scope` is not `repo` or `org=<name>`.
|
|
27864
|
+
*/
|
|
27865
|
+
function variableRoutes(entries, environmentId) {
|
|
27866
|
+
return (entries ?? []).filter((entry) => entry.environment === environmentId).map((entry) => {
|
|
27867
|
+
const scope = parseScope(entry.scope ?? "repo");
|
|
27868
|
+
if (scope.kind === "environment") throw new Error(`invalid variable scope "${entry.scope}" — expected "repo" or "org=<name>"`);
|
|
27869
|
+
return {
|
|
27870
|
+
scope,
|
|
27871
|
+
keys: entry.keys,
|
|
27872
|
+
...entry.visibility ? { visibility: entry.visibility } : {}
|
|
27873
|
+
};
|
|
27874
|
+
});
|
|
27875
|
+
}
|
|
27876
|
+
// src/commands/new-instance/read-seams/load-instance/load-instance.ts
|
|
27877
|
+
/** The names `new github-app` writes the App's credentials as; the webhook secret's is its default (`--webhook-secret-var`). */
|
|
27878
|
+
const APP_CREDENTIAL_NAMES = [
|
|
27879
|
+
"SENTINEL_GITHUB_APP_ID",
|
|
27880
|
+
"SENTINEL_GITHUB_APP_PRIVATE_KEY",
|
|
27881
|
+
"SENTINEL_WEBHOOK_SECRET"
|
|
27882
|
+
];
|
|
27883
|
+
/** Every token the root's and the app's providers declare, once each; a plugin that cannot be read declares none. */
|
|
27884
|
+
async function declaredTokens(session, ports) {
|
|
27885
|
+
const tuples = [...providerTuples(session.rootLoaded.resolved.providers), ...providerTuples(session.appLoaded.resolved.providers)];
|
|
27886
|
+
const read = ports.providerTokens(session.rootLoaded);
|
|
27887
|
+
const tokens = [];
|
|
27888
|
+
for (const provider of new Set(tuples.map((tuple) => tuple.provider))) try {
|
|
27889
|
+
tokens.push(...await read(provider));
|
|
27890
|
+
} catch {}
|
|
27891
|
+
return tokens;
|
|
27892
|
+
}
|
|
27893
|
+
/**
|
|
27894
|
+
* Reads everything `holocron new instance` needs to know about an app's preview instance: its project and domain, where
|
|
27895
|
+
* each of its secrets comes from, the filter that says which names it may hold, the Environments it reads and writes, the
|
|
27896
|
+
* GitHub App it uses and the tokens the plugins declare. Reads only; names and declarations, never a value.
|
|
27897
|
+
*
|
|
27898
|
+
* @param input.app - The app's folder name.
|
|
27899
|
+
* @param input.target - The `--env` of the run; only `preview` is an instance.
|
|
27900
|
+
* @param input.session - The app's and the root's configs, opened.
|
|
27901
|
+
* @throws {ConfigError} For a target that is not `preview`, an app with no deployment provider or no preview instance, or
|
|
27902
|
+
* no `repo.secrets.deploy` entry for the instance's Environment (its secrets cannot be classified without one).
|
|
27903
|
+
*/
|
|
27904
|
+
async function loadInstance(input) {
|
|
27905
|
+
const { app, target, session, ports } = input;
|
|
27906
|
+
const { targets } = parseAppEnv(target);
|
|
27907
|
+
if (targets[0] !== "preview") throw new ConfigError$1(`\`new instance\` makes the preview instance (--env preview); production is the app itself, made by \`setup\``);
|
|
27908
|
+
const layer = appLayer("preview");
|
|
27909
|
+
const resolved = session.appLoaded.resolved;
|
|
27910
|
+
const deployment = appPlan(resolved).deployment;
|
|
27911
|
+
if (!deployment) throw new ConfigError$1(`${app} declares no \`deployment\` provider, so it has no instance to make`);
|
|
27912
|
+
const options = deployment.options;
|
|
27913
|
+
const instance = previewInstance(app, options);
|
|
27914
|
+
const declaration = instanceDeclaration(app, options);
|
|
27915
|
+
if (!instance || !declaration) throw new ConfigError$1(`${app} declares no preview instance (\`instances.preview\` in its \`deployment\` options)`);
|
|
27916
|
+
const repoRoot = session.appContext.repoRoot;
|
|
27917
|
+
const environment = await ports.resolveEnvironment(layer, repoRoot);
|
|
27918
|
+
const copyEnvironment = await ports.resolveEnvironment("prod", repoRoot);
|
|
27919
|
+
const filter = deployFilter(resolved.repo?.secrets?.deploy, environment);
|
|
27920
|
+
if (!filter) throw new ConfigError$1(`${app}: \`repo.secrets.deploy\` has no entry for ${environment}, so the instance's secrets cannot be classified`);
|
|
27921
|
+
const entry = session.rootLoaded.resolved.githubApps?.find((candidate) => candidate.environment === environment);
|
|
27922
|
+
return {
|
|
27923
|
+
app,
|
|
27924
|
+
target,
|
|
27925
|
+
layer,
|
|
27926
|
+
project: instance.project,
|
|
27927
|
+
...instance.domain ? { domain: instance.domain } : {},
|
|
27928
|
+
environment,
|
|
27929
|
+
copyEnvironment,
|
|
27930
|
+
declaration,
|
|
27931
|
+
filter,
|
|
27932
|
+
appNames: entry ? [...APP_CREDENTIAL_NAMES] : [],
|
|
27933
|
+
...entry ? { appInstance: entry.name } : {},
|
|
27934
|
+
tokens: await declaredTokens(session, ports)
|
|
27935
|
+
};
|
|
27936
|
+
}
|
|
27937
|
+
// src/commands/new-instance/read-seams/open-instance-session/open-instance-session.ts
|
|
27938
|
+
/** The runtime context of one config: where it lives, the dry run, the tokens and the org it resolves to. */
|
|
27939
|
+
function contextFor(repoRoot, base, resolved) {
|
|
27940
|
+
const org = resolveOrg({ org: base.org }, resolved);
|
|
27941
|
+
return {
|
|
27942
|
+
repoRoot,
|
|
27943
|
+
dryRun: base.dryRun,
|
|
27944
|
+
...base.tokens,
|
|
27945
|
+
...org === void 0 ? {} : { org }
|
|
27946
|
+
};
|
|
27947
|
+
}
|
|
27948
|
+
/**
|
|
27949
|
+
* Opens the two configs a `new instance` run reads: the app's own (its `deployment` options, the deploy filter, the
|
|
27950
|
+
* vault) and the repository root's (`githubApps`, and the plugins whose tokens a person makes), each with its runtime
|
|
27951
|
+
* context and a loaded plugin loader. Nothing is written.
|
|
27952
|
+
*
|
|
27953
|
+
* @param app - The app's folder name.
|
|
27954
|
+
* @param context - The run's context.
|
|
27955
|
+
* @param ports - What touches the file system and the plugins.
|
|
27956
|
+
* @throws {ConfigError} When no app has that name, or the app has no `holocron.config` of its own.
|
|
27957
|
+
*/
|
|
27958
|
+
async function openInstanceSession(app, context, ports) {
|
|
27959
|
+
const lookup = await ports.resolveApp(app, context.cwd);
|
|
27960
|
+
if (!lookup.app) {
|
|
27961
|
+
const names = lookup.names.length ? lookup.names.join(", ") : "none found";
|
|
27962
|
+
throw new ConfigError$1(`no app named "${app}" in this workspace (apps: ${names})`);
|
|
27963
|
+
}
|
|
27964
|
+
if (!lookup.app.config) {
|
|
27965
|
+
const why = lookup.app.configError ? `: ${lookup.app.configError}` : "";
|
|
27966
|
+
throw new ConfigError$1(`${app} has no holocron.config of its own${why}`);
|
|
27967
|
+
}
|
|
27968
|
+
const appLoaded = await ports.loadConfig(lookup.app.dir);
|
|
27969
|
+
const rootLoaded = await ports.loadConfig(lookup.repoRoot);
|
|
27970
|
+
ports.applyResolvedConfig({ org: context.org }, appLoaded.resolved);
|
|
27971
|
+
const appContext = contextFor(lookup.app.dir, context, appLoaded.resolved);
|
|
27972
|
+
const rootContext = contextFor(lookup.repoRoot, context, rootLoaded.resolved);
|
|
27973
|
+
const appLoader = ports.makeLoader(appLoaded.resolved, appContext);
|
|
27974
|
+
const rootLoader = ports.makeLoader(rootLoaded.resolved, rootContext);
|
|
27975
|
+
await appLoader.load();
|
|
27976
|
+
await rootLoader.load();
|
|
27977
|
+
return {
|
|
27978
|
+
app,
|
|
27979
|
+
appLoaded,
|
|
27980
|
+
appContext,
|
|
27981
|
+
appLoader,
|
|
27982
|
+
rootLoaded,
|
|
27983
|
+
rootContext,
|
|
27984
|
+
rootLoader
|
|
27985
|
+
};
|
|
27986
|
+
}
|
|
27987
|
+
// src/commands/new-instance/read-seams/read-instance-back/read-instance-back.ts
|
|
27988
|
+
/** Runs one read-back and keeps its rows; a throw (the helpers catch their own, a port may not) is a failing row. */
|
|
27989
|
+
async function settled(id, title, run) {
|
|
27990
|
+
try {
|
|
27991
|
+
return [await run()].flat();
|
|
27992
|
+
} catch (err) {
|
|
27993
|
+
return [{
|
|
27994
|
+
id,
|
|
27995
|
+
title,
|
|
27996
|
+
status: "fail",
|
|
27997
|
+
detail: `could not run: ${errorMessage(err)}`,
|
|
27998
|
+
problems: []
|
|
27999
|
+
}];
|
|
28000
|
+
}
|
|
28001
|
+
}
|
|
28002
|
+
/**
|
|
28003
|
+
* The three read-backs of `holocron new instance` after the deploy, as rows: the webhook answers a GET with 405, `doctor
|
|
28004
|
+
* github-app` for the instance's own App, and what `doctor secrets` says the deployment receives. The App is judged over
|
|
28005
|
+
* the repository root's config (which declares `githubApps`) and the secrets over the app's (which declares
|
|
28006
|
+
* `repo.secrets.deploy`). With no domain or no App declared the row says so and is skipped. Reads only; names and
|
|
28007
|
+
* statuses, never a value.
|
|
28008
|
+
*/
|
|
28009
|
+
async function readInstanceBack(input) {
|
|
28010
|
+
const { setup, session, ports } = input;
|
|
28011
|
+
const { domain, appInstance } = setup;
|
|
28012
|
+
const webhook = domain ? settled("instance:webhook", "the webhook answers a GET with 405", () => ports.webhookRow({ domain })) : Promise.resolve([{
|
|
28013
|
+
id: "instance:webhook",
|
|
28014
|
+
title: "the webhook answers a GET with 405",
|
|
28015
|
+
status: "skip",
|
|
28016
|
+
detail: "the instance declares no domain, so there is no address to ask",
|
|
28017
|
+
problems: []
|
|
28018
|
+
}]);
|
|
28019
|
+
const app = appInstance ? settled("instance:github-app", "the GitHub App matches its manifest", () => ports.instanceAppRows({
|
|
28020
|
+
loaded: session.rootLoaded,
|
|
28021
|
+
context: session.rootContext,
|
|
28022
|
+
loader: session.rootLoader,
|
|
28023
|
+
instanceName: appInstance
|
|
28024
|
+
})) : Promise.resolve([{
|
|
28025
|
+
id: "instance:github-app",
|
|
28026
|
+
title: "the GitHub App matches its manifest",
|
|
28027
|
+
status: "skip",
|
|
28028
|
+
detail: `\`githubApps\` has no entry for ${setup.environment}`,
|
|
28029
|
+
problems: []
|
|
28030
|
+
}]);
|
|
28031
|
+
const secrets = settled("instance:secrets", "the deployment receives its keys", () => ports.instanceSecretsRow({
|
|
28032
|
+
loaded: session.appLoaded,
|
|
28033
|
+
context: session.appContext,
|
|
28034
|
+
loader: session.appLoader,
|
|
28035
|
+
environment: setup.environment
|
|
28036
|
+
}));
|
|
28037
|
+
return (await Promise.all([
|
|
28038
|
+
webhook,
|
|
28039
|
+
app,
|
|
28040
|
+
secrets
|
|
28041
|
+
])).flat();
|
|
28042
|
+
}
|
|
28043
|
+
// src/commands/new-instance/read-seams/read-instance-environment/read-instance-environment.ts
|
|
28044
|
+
/**
|
|
28045
|
+
* How 1Password words an Environment that does not exist ("environment couldn't be found", the phrase its plugin's own
|
|
28046
|
+
* `credentials` reader keys on). The vault capability has no typed "not found" (a failed `op` call is a `ProviderApiError`
|
|
28047
|
+
* with status 0 and the stderr in its message), so this is the only way to tell a missing Environment from one that cannot
|
|
28048
|
+
* be read, and any other wording is `unreadable` with the reason. Not verified against a real vault.
|
|
28049
|
+
*/
|
|
28050
|
+
const MISSING = /couldn.?t be found|could not be found/i;
|
|
28051
|
+
/**
|
|
28052
|
+
* An Environment's entries, read in memory through the vault: for each name whether it is blank and whether the vault
|
|
28053
|
+
* conceals it, and the value only for a name in `valuesFor` and only when it is not concealed (a `copy` reads the visible
|
|
28054
|
+
* values of `prod`, never a secret). Never throws, and no value is printed, logged or put in a reason.
|
|
28055
|
+
*
|
|
28056
|
+
* @param input.vault - The loaded vault provider, or `undefined` when none is configured.
|
|
28057
|
+
* @param input.environment - The Environment's name.
|
|
28058
|
+
* @param input.valuesFor - The names whose value is wanted.
|
|
28059
|
+
*/
|
|
28060
|
+
async function readInstanceEnvironment(input) {
|
|
28061
|
+
const { vault, environment } = input;
|
|
28062
|
+
if (!vault) return {
|
|
28063
|
+
status: "unreadable",
|
|
28064
|
+
reason: "no vault provider is configured"
|
|
28065
|
+
};
|
|
28066
|
+
if (!vault.readEnvironmentEntries) return {
|
|
28067
|
+
status: "unreadable",
|
|
28068
|
+
reason: `${vault.providerName} cannot tell a concealed value from a visible one`
|
|
28069
|
+
};
|
|
28070
|
+
const wanted = new Set(input.valuesFor);
|
|
28071
|
+
try {
|
|
28072
|
+
const entries = {};
|
|
28073
|
+
for (const entry of await vault.readEnvironmentEntries(environment)) entries[entry.name] = {
|
|
28074
|
+
blank: entry.value === "",
|
|
28075
|
+
concealed: entry.concealed,
|
|
28076
|
+
...wanted.has(entry.name) && !entry.concealed ? { value: entry.value } : {}
|
|
28077
|
+
};
|
|
28078
|
+
return {
|
|
28079
|
+
status: "ok",
|
|
28080
|
+
entries
|
|
28081
|
+
};
|
|
28082
|
+
} catch (err) {
|
|
28083
|
+
const reason = errorMessage(err);
|
|
28084
|
+
return MISSING.test(reason) ? { status: "missing" } : {
|
|
28085
|
+
status: "unreadable",
|
|
28086
|
+
reason
|
|
28087
|
+
};
|
|
28088
|
+
}
|
|
28089
|
+
}
|
|
28090
|
+
// src/commands/new-instance/instance-app-rows/instance-app-rows.ts
|
|
28091
|
+
/**
|
|
28092
|
+
* The second read-back of `holocron new instance`: `doctor github-app` for the instance's own App, as rows. It runs the
|
|
28093
|
+
* doctor's own function over the config narrowed to that one `githubApps` entry, with nothing printed, so the App is
|
|
28094
|
+
* judged by the comparison every other run uses (reachable, events, permissions, installations, deliveries). The
|
|
28095
|
+
* credentials are read in memory by the doctor and never leave it.
|
|
28096
|
+
*/
|
|
28097
|
+
async function instanceAppRows(input) {
|
|
28098
|
+
const { loaded, instanceName } = input;
|
|
28099
|
+
const instance = loaded.resolved.githubApps?.find((app) => app.name === instanceName);
|
|
28100
|
+
if (!instance) return [{
|
|
28101
|
+
id: "instance:github-app",
|
|
28102
|
+
title: "the GitHub App matches its manifest",
|
|
28103
|
+
status: "skip",
|
|
28104
|
+
detail: `\`githubApps\` has no entry named ${instanceName}`,
|
|
28105
|
+
problems: []
|
|
28106
|
+
}];
|
|
28107
|
+
try {
|
|
28108
|
+
return (await runDoctorGitHubApp({
|
|
28109
|
+
loaded: {
|
|
28110
|
+
...loaded,
|
|
28111
|
+
resolved: {
|
|
28112
|
+
...loaded.resolved,
|
|
28113
|
+
githubApps: [instance]
|
|
28114
|
+
}
|
|
28115
|
+
},
|
|
28116
|
+
context: input.context,
|
|
28117
|
+
print: () => void 0,
|
|
28118
|
+
...input.loader ? { loader: input.loader } : {},
|
|
28119
|
+
...input.readManifest ? { readManifest: input.readManifest } : {},
|
|
28120
|
+
...input.api ? { api: input.api } : {},
|
|
28121
|
+
...input.now ? { now: input.now } : {}
|
|
28122
|
+
})).rows;
|
|
28123
|
+
} catch (err) {
|
|
28124
|
+
return [{
|
|
28125
|
+
id: "instance:github-app",
|
|
28126
|
+
title: "the GitHub App matches its manifest",
|
|
28127
|
+
status: "fail",
|
|
28128
|
+
detail: `doctor github-app could not run: ${errorMessage(err)}`,
|
|
28129
|
+
problems: []
|
|
28130
|
+
}];
|
|
28131
|
+
}
|
|
28132
|
+
}
|
|
28133
|
+
// src/commands/new-instance/instance-secrets-row/instance-secrets-row.ts
|
|
28134
|
+
/**
|
|
28135
|
+
* The third read-back of `holocron new instance`: what `doctor secrets` says the instance's deployment would receive from
|
|
28136
|
+
* the Environment (its `deploy-<environment>` row, names only). `doctor secrets` has no `preview` environment of its own,
|
|
28137
|
+
* but its `prod` run lists a row for every `repo.secrets.deploy` entry, the preview layer's included, so the run asks for
|
|
28138
|
+
* that and keeps the one row. Nothing is printed and no value is read into a row.
|
|
28139
|
+
*/
|
|
28140
|
+
async function instanceSecretsRow(input) {
|
|
28141
|
+
const id = `deploy-${input.environment}`;
|
|
28142
|
+
try {
|
|
28143
|
+
return (await runDoctorSecrets({
|
|
28144
|
+
loaded: input.loaded,
|
|
28145
|
+
context: input.context,
|
|
28146
|
+
environments: ["prod"],
|
|
28147
|
+
only: "secrets",
|
|
28148
|
+
print: () => void 0,
|
|
28149
|
+
...input.loader ? { loader: input.loader } : {}
|
|
28150
|
+
})).rows.find((row) => row.id === id) ?? {
|
|
28151
|
+
id: "instance:secrets",
|
|
28152
|
+
title: "the deployment receives its keys",
|
|
28153
|
+
status: "skip",
|
|
28154
|
+
detail: `\`repo.secrets.deploy\` has no entry for ${input.environment}`,
|
|
28155
|
+
problems: []
|
|
28156
|
+
};
|
|
28157
|
+
} catch (err) {
|
|
28158
|
+
return {
|
|
28159
|
+
id: "instance:secrets",
|
|
28160
|
+
title: "the deployment receives its keys",
|
|
28161
|
+
status: "fail",
|
|
28162
|
+
detail: `doctor secrets could not run: ${errorMessage(err)}`,
|
|
28163
|
+
problems: []
|
|
28164
|
+
};
|
|
28165
|
+
}
|
|
28166
|
+
}
|
|
28167
|
+
// src/commands/new-instance/webhook-row/webhook-row.ts
|
|
28168
|
+
/**
|
|
28169
|
+
* The first read-back of `holocron new instance`: the instance's webhook answers `405` to a plain GET, which proves the
|
|
28170
|
+
* function is deployed and routing (the same assertion the Checkly uptime check makes). Names and a status only.
|
|
28171
|
+
*
|
|
28172
|
+
* @param input.domain - The domain the instance serves.
|
|
28173
|
+
* @param input.fetch - The HTTP call; defaults to the global `fetch`.
|
|
28174
|
+
*/
|
|
28175
|
+
async function webhookRow(input) {
|
|
28176
|
+
const id = "instance:webhook";
|
|
28177
|
+
const title = "the webhook answers a GET with 405";
|
|
28178
|
+
const url = `https://${input.domain}/api/webhook`;
|
|
28179
|
+
try {
|
|
28180
|
+
const { status } = await (input.fetch ?? fetch)(url, { method: "GET" });
|
|
28181
|
+
return status === 405 ? {
|
|
28182
|
+
id,
|
|
28183
|
+
title,
|
|
28184
|
+
status: "ok",
|
|
28185
|
+
detail: `${url} answers 405`,
|
|
28186
|
+
problems: []
|
|
28187
|
+
} : {
|
|
28188
|
+
id,
|
|
28189
|
+
title,
|
|
28190
|
+
status: "fail",
|
|
28191
|
+
detail: `${url} answers ${status}, not 405`,
|
|
28192
|
+
problems: []
|
|
28193
|
+
};
|
|
28194
|
+
} catch (err) {
|
|
28195
|
+
return {
|
|
28196
|
+
id,
|
|
28197
|
+
title,
|
|
28198
|
+
status: "fail",
|
|
28199
|
+
detail: `${url} could not be reached: ${errorMessage(err)}`,
|
|
28200
|
+
problems: []
|
|
28201
|
+
};
|
|
28202
|
+
}
|
|
28203
|
+
}
|
|
28204
|
+
// src/commands/new-instance/read-seams/read-ports/read-ports.ts
|
|
28205
|
+
/** The real ports of the read seams: the workspace, the config, the plugins and the network. */
|
|
28206
|
+
function createReadPorts() {
|
|
28207
|
+
return {
|
|
28208
|
+
resolveApp,
|
|
28209
|
+
loadConfig,
|
|
28210
|
+
applyResolvedConfig,
|
|
28211
|
+
resolveEnvironment: (layer, repoRoot, gitExec) => resolveEnvironmentId(layer, {
|
|
28212
|
+
repoRoot,
|
|
28213
|
+
gitExec
|
|
28214
|
+
}),
|
|
28215
|
+
makeLoader: (resolved, context) => new PluginLoader(resolved, context),
|
|
28216
|
+
providerTokens: (loaded) => defaultProviderTokens(loaded),
|
|
28217
|
+
webhookRow,
|
|
28218
|
+
instanceAppRows,
|
|
28219
|
+
instanceSecretsRow
|
|
28220
|
+
};
|
|
28221
|
+
}
|
|
28222
|
+
// src/commands/new-instance/read-seams/create-read-seams/create-read-seams.ts
|
|
28223
|
+
/**
|
|
28224
|
+
* The real read seams of `holocron new instance`: `load` (the app's and the root's configs, opened once and kept for the
|
|
28225
|
+
* run), `readEnvironment` (an Environment's entries through the app's vault, in memory) and `readBack` (the webhook, the
|
|
28226
|
+
* GitHub App and the secrets, as rows). Nothing here writes. `readEnvironment` and `readBack` need `load` to have run, as
|
|
28227
|
+
* the orchestrator does first; without it they say so instead of reading a config nobody opened.
|
|
28228
|
+
*
|
|
28229
|
+
* @param context - The run's context.
|
|
28230
|
+
* @param ports - What touches the file system, the plugins and the network; the real ones by default.
|
|
28231
|
+
*/
|
|
28232
|
+
function createReadSeams(context, ports = createReadPorts()) {
|
|
28233
|
+
let session;
|
|
28234
|
+
return {
|
|
28235
|
+
async load(app, target) {
|
|
28236
|
+
session = await openInstanceSession(app, context, ports);
|
|
28237
|
+
return loadInstance({
|
|
28238
|
+
app,
|
|
28239
|
+
target,
|
|
28240
|
+
session,
|
|
28241
|
+
ports
|
|
28242
|
+
});
|
|
28243
|
+
},
|
|
28244
|
+
async readEnvironment(environment, valuesFor) {
|
|
28245
|
+
if (!session) return {
|
|
28246
|
+
status: "unreadable",
|
|
28247
|
+
reason: "the instance's config has not been loaded yet"
|
|
28248
|
+
};
|
|
28249
|
+
return readInstanceEnvironment({
|
|
28250
|
+
vault: session.appLoader.has("vault") ? session.appLoader.get("vault") : void 0,
|
|
28251
|
+
environment,
|
|
28252
|
+
valuesFor
|
|
28253
|
+
});
|
|
28254
|
+
},
|
|
28255
|
+
async readBack(setup) {
|
|
28256
|
+
if (!session) return [{
|
|
28257
|
+
id: "instance:read-back",
|
|
28258
|
+
title: "the read-backs",
|
|
28259
|
+
status: "fail",
|
|
28260
|
+
detail: "the instance's config has not been loaded yet",
|
|
28261
|
+
problems: []
|
|
28262
|
+
}];
|
|
28263
|
+
return readInstanceBack({
|
|
28264
|
+
setup,
|
|
28265
|
+
session,
|
|
28266
|
+
ports
|
|
28267
|
+
});
|
|
28268
|
+
}
|
|
28269
|
+
};
|
|
28270
|
+
}
|
|
28271
|
+
// src/commands/new-instance/confirm-seam/confirm-seam.ts
|
|
28272
|
+
const REAL$6 = {
|
|
28273
|
+
isTTY: () => process.stdin.isTTY === true,
|
|
28274
|
+
ask: async (message) => {
|
|
28275
|
+
const { confirm } = await import("@inquirer/prompts");
|
|
28276
|
+
return confirm({
|
|
28277
|
+
message,
|
|
28278
|
+
default: false
|
|
28279
|
+
});
|
|
28280
|
+
}
|
|
28281
|
+
};
|
|
28282
|
+
/**
|
|
28283
|
+
* The one question before the first write (spec `tech-new-instance-command`): prints what will be written, by name, and
|
|
28284
|
+
* asks. The orchestrator asks only when `--yes` was not given, so a run with no terminal and no `--yes` stops here.
|
|
28285
|
+
*
|
|
28286
|
+
* @throws {NonInteractiveError} When there is no terminal to ask on.
|
|
28287
|
+
*/
|
|
28288
|
+
async function confirmSeam(context, lines, deps = {}) {
|
|
28289
|
+
const real = {
|
|
28290
|
+
...REAL$6,
|
|
28291
|
+
...deps
|
|
28292
|
+
};
|
|
28293
|
+
for (const line of lines) context.print(line);
|
|
28294
|
+
if (!real.isTTY()) throw new NonInteractiveError("new instance asks before it writes: run it on a terminal, or pass --yes");
|
|
28295
|
+
return real.ask("Make these changes?");
|
|
28296
|
+
}
|
|
28297
|
+
// src/commands/new-instance/github-app-name/github-app-name.ts
|
|
28298
|
+
/** GitHub's limit on an App's name. */
|
|
28299
|
+
const MAX_LENGTH = 34;
|
|
28300
|
+
/**
|
|
28301
|
+
* The name `holocron new instance` gives the instance's GitHub App: the organization and the `githubApps` entry's name,
|
|
28302
|
+
* lower case, in one slug (`theholocron` and `Sentinel - preview` make `theholocron-sentinel-preview`). The config has
|
|
28303
|
+
* no field for an App's name (the manifest flow takes it as a flag), and an App's name must be unique across all of GitHub
|
|
28304
|
+
* and at most 34 characters, so the name is derived and deterministic: the same entry always gives the same name, and
|
|
28305
|
+
* the org prefix keeps it from colliding with another account's. It matters only the first time: once the Environment
|
|
28306
|
+
* holds the App's id the command never makes the App again.
|
|
28307
|
+
*
|
|
28308
|
+
* @param org - The organization, when there is one.
|
|
28309
|
+
* @param entryName - The `githubApps` entry's `name`.
|
|
28310
|
+
*/
|
|
28311
|
+
function githubAppName(org, entryName) {
|
|
28312
|
+
return `${org ?? ""} ${entryName}`.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+/, "").slice(0, MAX_LENGTH).replace(/-+$/, "") || "holocron-app";
|
|
28313
|
+
}
|
|
28314
|
+
// src/commands/new-instance/create-app-seam/create-app-seam.ts
|
|
28315
|
+
const REAL$5 = {
|
|
28316
|
+
resolveApp,
|
|
28317
|
+
loadConfig,
|
|
28318
|
+
runGithubAppCreate,
|
|
28319
|
+
interactive: () => process.stdin.isTTY === true
|
|
28320
|
+
};
|
|
28321
|
+
/** The variable the webhook secret is written as: the instance's own name for it, else the default `new github-app` uses. */
|
|
28322
|
+
const DEFAULT_WEBHOOK_SECRET_VAR = "SENTINEL_WEBHOOK_SECRET";
|
|
28323
|
+
/**
|
|
28324
|
+
* Makes the instance's GitHub App from its `githubApps` entry's manifest and hands its credentials to `collect` instead
|
|
28325
|
+
* of a file of their own, so they join the one import file (spec `tech-new-instance-command` step 4). The entry is read
|
|
28326
|
+
* from the repository's root config, where `githubApps` lives, and the webhook goes to the instance's own domain. Never
|
|
28327
|
+
* throws; the App's credentials are never printed or returned.
|
|
28328
|
+
*/
|
|
28329
|
+
async function createAppSeam(context, setup, collect, deps = {}) {
|
|
28330
|
+
const real = {
|
|
28331
|
+
...REAL$5,
|
|
28332
|
+
...deps
|
|
28333
|
+
};
|
|
28334
|
+
const fail = (message) => ({
|
|
28335
|
+
status: "fail",
|
|
28336
|
+
message
|
|
28337
|
+
});
|
|
28338
|
+
try {
|
|
28339
|
+
if (!setup.appInstance) return fail("the layer has no `githubApps` entry, so there is no App to make");
|
|
28340
|
+
if (!setup.domain) return fail("the instance names no domain, so its App has no webhook address");
|
|
28341
|
+
const { repoRoot } = await real.resolveApp(setup.app, context.cwd);
|
|
28342
|
+
const loaded = await real.loadConfig(repoRoot);
|
|
28343
|
+
const entry = loaded.resolved.githubApps?.find((candidate) => candidate.name === setup.appInstance);
|
|
28344
|
+
if (!entry) return fail(`the root config has no \`githubApps\` entry named "${setup.appInstance}"`);
|
|
28345
|
+
const org = resolveOrg(context.org ? { org: context.org } : {}, loaded.resolved);
|
|
28346
|
+
const report = await real.runGithubAppCreate({
|
|
28347
|
+
dir: repoRoot,
|
|
28348
|
+
manifest: entry.manifest,
|
|
28349
|
+
name: githubAppName(org, entry.name),
|
|
28350
|
+
webhookUrl: `https://${setup.domain}/api/webhook`,
|
|
28351
|
+
...org ? { org } : {},
|
|
28352
|
+
webhookSecretVar: setup.appNames.find((name) => name.endsWith("WEBHOOK_SECRET")) ?? DEFAULT_WEBHOOK_SECRET_VAR,
|
|
28353
|
+
collect,
|
|
28354
|
+
print: context.print,
|
|
28355
|
+
interactive: real.interactive()
|
|
28356
|
+
});
|
|
28357
|
+
if (report.status !== "ok") return fail("the App was not made: see the lines above for why");
|
|
28358
|
+
return {
|
|
28359
|
+
status: "ok",
|
|
28360
|
+
...report.slug ? { installUrl: `https://github.com/apps/${report.slug}/installations/new` } : {}
|
|
28361
|
+
};
|
|
28362
|
+
} catch (err) {
|
|
28363
|
+
return fail(errorMessage(err));
|
|
28364
|
+
}
|
|
28365
|
+
}
|
|
28366
|
+
// src/commands/new-instance/app-run-outcome/app-run-outcome.ts
|
|
28367
|
+
/**
|
|
28368
|
+
* What `runAppSync()` and `runAppDeploy()` reported, as a seam's outcome: only `fail` fails. An app with nothing to
|
|
28369
|
+
* sync or deploy (`nothing`) and a run that wrote nothing (`dry-run`) are ok, and the message says which, so the row is
|
|
28370
|
+
* honest about a step that did no work.
|
|
28371
|
+
*/
|
|
28372
|
+
function appRunOutcome(report) {
|
|
28373
|
+
if (report.status === "fail") return {
|
|
28374
|
+
status: "fail",
|
|
28375
|
+
message: report.message
|
|
28376
|
+
};
|
|
28377
|
+
if (report.status === "nothing") return {
|
|
28378
|
+
status: "ok",
|
|
28379
|
+
message: `skipped, nothing to do: ${report.message}`
|
|
28380
|
+
};
|
|
28381
|
+
if (report.status === "dry-run") return {
|
|
28382
|
+
status: "ok",
|
|
28383
|
+
message: `dry run, nothing written: ${report.message}`
|
|
28384
|
+
};
|
|
28385
|
+
return {
|
|
28386
|
+
status: "ok",
|
|
28387
|
+
message: report.message
|
|
28388
|
+
};
|
|
28389
|
+
}
|
|
28390
|
+
// src/commands/new-instance/load-app-seam/load-app-seam.ts
|
|
28391
|
+
const REAL$4 = {
|
|
28392
|
+
resolveApp,
|
|
28393
|
+
loadConfig,
|
|
28394
|
+
applyResolvedConfig,
|
|
28395
|
+
makeLoader: (resolved, context) => new PluginLoader(resolved, context)
|
|
28396
|
+
};
|
|
28397
|
+
/**
|
|
28398
|
+
* Loads an app the way `sync <app>` and `deploy <app>` do: found by its folder name, its own config, the runtime
|
|
28399
|
+
* context with the `--token` values and the plugin loader over them (spec `tech-new-instance-command`).
|
|
28400
|
+
*
|
|
28401
|
+
* @throws {Error} When no app has that name (the message lists the apps); a config that cannot be loaded throws its own.
|
|
28402
|
+
*/
|
|
28403
|
+
async function loadAppSeam(context, appName, deps = {}) {
|
|
28404
|
+
const real = {
|
|
28405
|
+
...REAL$4,
|
|
28406
|
+
...deps
|
|
28407
|
+
};
|
|
28408
|
+
const lookup = await real.resolveApp(appName, context.cwd);
|
|
28409
|
+
const { app } = lookup;
|
|
28410
|
+
if (!app) {
|
|
28411
|
+
const names = lookup.names.length ? lookup.names.join(", ") : "none found";
|
|
28412
|
+
throw new Error(`no app named "${appName}" in this workspace (apps: ${names})`);
|
|
28413
|
+
}
|
|
28414
|
+
const loaded = await real.loadConfig(app.dir);
|
|
28415
|
+
const argv = context.org ? { org: context.org } : {};
|
|
28416
|
+
real.applyResolvedConfig(argv, loaded.resolved);
|
|
28417
|
+
const runtime = {
|
|
28418
|
+
repoRoot: app.dir,
|
|
28419
|
+
dryRun: context.dryRun,
|
|
28420
|
+
...context.tokens,
|
|
28421
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
28422
|
+
};
|
|
28423
|
+
return {
|
|
28424
|
+
app,
|
|
28425
|
+
loaded,
|
|
28426
|
+
context: runtime,
|
|
28427
|
+
loader: real.makeLoader(loaded.resolved, runtime)
|
|
28428
|
+
};
|
|
28429
|
+
}
|
|
28430
|
+
// src/commands/new-instance/deploy-seam/deploy-seam.ts
|
|
28431
|
+
const REAL$3 = {
|
|
28432
|
+
loadApp: loadAppSeam,
|
|
28433
|
+
parseAppEnv,
|
|
28434
|
+
runAppDeploy,
|
|
28435
|
+
buildApp,
|
|
28436
|
+
stageDeploy,
|
|
28437
|
+
runDeployFromFiles
|
|
28438
|
+
};
|
|
28439
|
+
/**
|
|
28440
|
+
* `deploy <app> --env <target>` as a step (spec `tech-new-instance-command` step 6): the same `runAppDeploy()` the command
|
|
28441
|
+
* runs (domain check, build, stage, deploy), over the app's own config, with its report taken as an outcome instead of
|
|
28442
|
+
* an exit code. Never throws.
|
|
28443
|
+
*/
|
|
28444
|
+
async function deploySeam(context, setup, deps = {}) {
|
|
28445
|
+
const real = {
|
|
28446
|
+
...REAL$3,
|
|
28447
|
+
...deps
|
|
28448
|
+
};
|
|
28449
|
+
try {
|
|
28450
|
+
const loadedApp = await real.loadApp(context, setup.app);
|
|
28451
|
+
return appRunOutcome(await real.runAppDeploy({
|
|
28452
|
+
app: loadedApp.app,
|
|
28453
|
+
env: real.parseAppEnv([setup.target]),
|
|
28454
|
+
load: async () => ({
|
|
28455
|
+
loaded: loadedApp.loaded,
|
|
28456
|
+
context: loadedApp.context,
|
|
28457
|
+
loader: loadedApp.loader
|
|
28458
|
+
}),
|
|
28459
|
+
print: context.print,
|
|
28460
|
+
build: real.buildApp,
|
|
28461
|
+
stage: real.stageDeploy,
|
|
28462
|
+
deployFiles: real.runDeployFromFiles
|
|
28463
|
+
}));
|
|
28464
|
+
} catch (err) {
|
|
28465
|
+
return {
|
|
28466
|
+
status: "fail",
|
|
28467
|
+
message: errorMessage(err)
|
|
28468
|
+
};
|
|
28469
|
+
}
|
|
28470
|
+
}
|
|
28471
|
+
// src/commands/new-instance/ensure-project-seam/ensure-project-seam.ts
|
|
28472
|
+
const REAL$2 = {
|
|
28473
|
+
loadApp: loadAppSeam,
|
|
28474
|
+
ensureInstanceProject
|
|
28475
|
+
};
|
|
28476
|
+
/**
|
|
28477
|
+
* Makes the instance's project and the domain it serves, the way `setup` does and without the rest of `setup`
|
|
28478
|
+
* (`ensureInstanceProject()`, spec `tech-new-instance-command` step 2). The app's own config supplies the `deployment`
|
|
28479
|
+
* provider and, when one is configured, the `dns` provider that makes the domain's record. Never throws: a project that
|
|
28480
|
+
* cannot be made is a failing step, after the steps that did run.
|
|
28481
|
+
*/
|
|
28482
|
+
async function ensureProjectSeam(context, setup, dryRun, deps = {}) {
|
|
28483
|
+
const real = {
|
|
28484
|
+
...REAL$2,
|
|
28485
|
+
...deps
|
|
28486
|
+
};
|
|
28487
|
+
const steps = [];
|
|
28488
|
+
const failure = (message) => ({
|
|
28489
|
+
capability: "deployment",
|
|
28490
|
+
step: `ensureProject ${setup.project}`,
|
|
28491
|
+
status: "fail",
|
|
28492
|
+
message
|
|
28493
|
+
});
|
|
28494
|
+
try {
|
|
28495
|
+
const { loader } = await real.loadApp(context, setup.app);
|
|
28496
|
+
if (!loader.has("deployment")) return [failure("the app configures no `deployment` provider")];
|
|
28497
|
+
const deploy = loader.get("deployment");
|
|
28498
|
+
await real.ensureInstanceProject({
|
|
28499
|
+
deploy,
|
|
28500
|
+
dns: () => loader.has("dns") ? loader.get("dns") : void 0,
|
|
28501
|
+
instance: {
|
|
28502
|
+
project: setup.project,
|
|
28503
|
+
...setup.domain ? { domain: setup.domain } : {}
|
|
28504
|
+
},
|
|
28505
|
+
dryRun,
|
|
28506
|
+
report: (step) => {
|
|
28507
|
+
steps.push(step);
|
|
28508
|
+
}
|
|
28509
|
+
});
|
|
28510
|
+
return steps;
|
|
28511
|
+
} catch (err) {
|
|
28512
|
+
return [...steps, failure(describeProviderError(err))];
|
|
28513
|
+
}
|
|
28514
|
+
}
|
|
28515
|
+
// src/commands/secrets-handoff/secrets-handoff.ts
|
|
28516
|
+
/**
|
|
28517
|
+
* Hand several secrets to a person for import into a vault in one file: the multi-line sibling of `handOffSecret()`,
|
|
28518
|
+
* for `holocron new instance` (spec `tech-new-instance-command`). The CLI cannot write to a 1Password Environment, so the
|
|
28519
|
+
* hand-off is the private import file, the way `export tokens` and the heartbeat hand-off do it
|
|
28520
|
+
* (`.holocron/.private/.credentials`, mode 0600, never overwritten, refused unless git says it ignores it, refused on
|
|
28521
|
+
* Windows, deleted once the import is done). The values go only to that file: nothing here prints, logs or returns one.
|
|
28522
|
+
*/
|
|
28523
|
+
/** A name a dotenv file can carry and a shell can export. */
|
|
28524
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
28525
|
+
async function handOffSecrets(input) {
|
|
28526
|
+
const { print, entries } = input;
|
|
28527
|
+
const fail = (reason, ...message) => {
|
|
28528
|
+
for (const line of message) print(line);
|
|
28529
|
+
return {
|
|
28530
|
+
status: "fail",
|
|
28531
|
+
written: [],
|
|
28532
|
+
reason
|
|
28533
|
+
};
|
|
28534
|
+
};
|
|
28535
|
+
if (entries.length === 0) return fail("empty", "nothing to hand over");
|
|
28536
|
+
const lines = [];
|
|
28537
|
+
const names = [];
|
|
28538
|
+
const blank = [];
|
|
28539
|
+
for (const { name, value } of entries) {
|
|
28540
|
+
if (!NAME.test(name)) return fail("name", `"${name}" is not a name a variable can carry`);
|
|
28541
|
+
if (names.includes(name)) return fail("duplicate", `${name} is listed twice: a name is handed over once`);
|
|
28542
|
+
const line = dotenvLine(name, value);
|
|
28543
|
+
if (line === null) return fail("unsupported", `${name}: its value is not one a dotenv file can carry`);
|
|
28544
|
+
lines.push(line);
|
|
28545
|
+
names.push(name);
|
|
28546
|
+
if (value === "") blank.push(name);
|
|
28547
|
+
}
|
|
28548
|
+
if ((input.platform ?? process.platform) === "win32") return fail("windows", "cannot make the file private on Windows: its mode bits are not enforced");
|
|
28549
|
+
const target = resolveCredentialsFile(input.base, void 0, input.makeDir);
|
|
28550
|
+
const file = target.path;
|
|
28551
|
+
const git = (input.isIgnored ?? isGitIgnored)(file);
|
|
28552
|
+
if (git === "tracked" || git === "unknown") return fail("not-ignored", git === "tracked" ? `refusing to write secrets to ${file}: git does not ignore it, so it could be committed` : `refusing to write secrets to ${file}: git could not say whether it ignores it`, ignoreAdvice(target.isDefault, "choose a path outside the repository"));
|
|
28553
|
+
let identity;
|
|
28554
|
+
try {
|
|
28555
|
+
identity = (input.writeFile ?? writeCredentialsFile)(file, `${lines.join("\n")}\n`, false);
|
|
28556
|
+
} catch (err) {
|
|
28557
|
+
return fail("write", `could not write ${file}: ${errorMessage(err)}`, "an existing file is never overwritten: finish importing it, delete it, then run the command again");
|
|
28558
|
+
}
|
|
28559
|
+
print(`wrote ${names.length} name(s) for import: ${names.join(", ")}`);
|
|
28560
|
+
if (blank.length > 0) print(`${blank.join(", ")} ${blank.length === 1 ? "is" : "are"} blank: fill in after the import`);
|
|
28561
|
+
const where = input.environment ? `the \`${input.environment}\` Environment` : "the Environment that holds them";
|
|
28562
|
+
return await finishCredentialsFile({
|
|
28563
|
+
path: file,
|
|
28564
|
+
identity,
|
|
28565
|
+
print,
|
|
28566
|
+
holds: "the new values",
|
|
28567
|
+
importHint: `import it in the 1Password app: Developer, View Environments, ${where}, Import .env file`,
|
|
28568
|
+
keep: input.keep,
|
|
28569
|
+
interactive: input.interactive,
|
|
28570
|
+
shred: input.shred,
|
|
28571
|
+
waitForImport: input.waitForImport
|
|
28572
|
+
}) ? {
|
|
28573
|
+
status: "ok",
|
|
28574
|
+
written: names
|
|
28575
|
+
} : {
|
|
28576
|
+
status: "fail",
|
|
28577
|
+
written: names,
|
|
28578
|
+
reason: "file-left"
|
|
28579
|
+
};
|
|
28580
|
+
}
|
|
28581
|
+
// src/commands/new-instance/hand-off-seam/hand-off-seam.ts
|
|
28582
|
+
const REAL$1 = {
|
|
28583
|
+
handOffSecrets,
|
|
28584
|
+
findRoot: (cwd) => findRootSync(cwd, "pnpm-workspace.yaml", { fallback: "start" }),
|
|
28585
|
+
interactive: () => process.stdin.isTTY === true
|
|
28586
|
+
};
|
|
28587
|
+
/**
|
|
28588
|
+
* Writes the one import file of the run (`handOffSecrets()`: private, mode 0600, never overwritten), waits for the person
|
|
28589
|
+
* to import it into the Environment and removes it (spec `tech-new-instance-command` step 5). The values go only into
|
|
28590
|
+
* that file: the outcome carries a reason, never a value. Never throws.
|
|
28591
|
+
*/
|
|
28592
|
+
async function handOffSeam(context, entries, environment, deps = {}) {
|
|
28593
|
+
const real = {
|
|
28594
|
+
...REAL$1,
|
|
28595
|
+
...deps
|
|
28596
|
+
};
|
|
28597
|
+
try {
|
|
28598
|
+
const result = await real.handOffSecrets({
|
|
28599
|
+
entries,
|
|
28600
|
+
base: real.findRoot(context.cwd),
|
|
28601
|
+
print: context.print,
|
|
28602
|
+
environment,
|
|
28603
|
+
interactive: real.interactive()
|
|
28604
|
+
});
|
|
28605
|
+
if (result.status === "ok") return { status: "ok" };
|
|
28606
|
+
return {
|
|
28607
|
+
status: "fail",
|
|
28608
|
+
message: `the import file was not handed over${result.reason ? ` (${result.reason})` : ""}`
|
|
28609
|
+
};
|
|
28610
|
+
} catch (err) {
|
|
28611
|
+
return {
|
|
28612
|
+
status: "fail",
|
|
28613
|
+
message: errorMessage(err)
|
|
28614
|
+
};
|
|
28615
|
+
}
|
|
28616
|
+
}
|
|
28617
|
+
// src/commands/app-sync/app-sync.ts
|
|
28618
|
+
/**
|
|
28619
|
+
* `holocron sync <app> --env <env>`: reads the app's vault Environment of each target's layer (`prod` for production,
|
|
28620
|
+
* `preview` for preview, never one for the other) and sends the secrets `repo.secrets.deploy` names for that layer to the
|
|
28621
|
+
* app's destinations, the way `sync secrets --project-id <app> --target <target>` or `--worker <app>` would: the Vercel
|
|
28622
|
+
* project when the app has a `deployment` provider, the Worker script when it has a `workers` provider, both named after
|
|
28623
|
+
* the app folder. Before anything is written the project must serve the app's
|
|
28624
|
+
* configured `domain`. An app with neither destination has nothing to sync and is reported, not failed.
|
|
28625
|
+
*
|
|
28626
|
+
* @param input - The app, the environment, its loaded config and the seams tests replace.
|
|
28627
|
+
*/
|
|
28628
|
+
async function runAppSync(input) {
|
|
28629
|
+
const { app, env } = input;
|
|
28630
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
28631
|
+
const fail = (message) => {
|
|
28632
|
+
print(` ${style.fail(message)}`);
|
|
28633
|
+
return {
|
|
28634
|
+
status: "fail",
|
|
28635
|
+
message
|
|
28636
|
+
};
|
|
28637
|
+
};
|
|
28638
|
+
if (app.configError) return fail(`${app.name}: its holocron.config cannot be read: ${app.configError}`);
|
|
28639
|
+
const plan = appPlan(app.config);
|
|
28640
|
+
if (!plan.deployment && !plan.workers) {
|
|
28641
|
+
const message = `${app.name}: no deployment or Worker is configured, so there are no secrets to sync; nothing to do`;
|
|
28642
|
+
print(` ${style.dim(message)}`);
|
|
28643
|
+
return {
|
|
28644
|
+
status: "nothing",
|
|
28645
|
+
message
|
|
28646
|
+
};
|
|
28647
|
+
}
|
|
28648
|
+
if (!plan.deployKeys) return fail(`${app.name}: its config has no \`repo.secrets.deploy\` entry, and a deployment or Worker receives only the secrets that names`);
|
|
28649
|
+
const { loaded, context, loader } = await input.load();
|
|
28650
|
+
const destinations = [plan.deployment ? `${app.name} (project)` : "", plan.workers ? `${app.name} (Worker)` : ""];
|
|
28651
|
+
print(style.header(`Holocron sync ${app.name} → ${destinations.filter(Boolean).join(" + ")}${context.dryRun ? " (dry-run)" : ""}`));
|
|
28652
|
+
const instances = /* @__PURE__ */ new Map();
|
|
28653
|
+
if (plan.deployment) {
|
|
28654
|
+
await loader.load();
|
|
28655
|
+
if (!loader.has("deployment")) return fail(`${app.name}: the deployment provider did not load`);
|
|
28656
|
+
try {
|
|
28657
|
+
for (const target of env.targets) instances.set(target, appInstance(app.name, plan.deployment.options, target));
|
|
28658
|
+
} catch (err) {
|
|
28659
|
+
return fail(errorMessage(err));
|
|
28660
|
+
}
|
|
28661
|
+
for (const instance of instances.values()) {
|
|
28662
|
+
const checked = await checkProjectDomain(loader.get("deployment"), instance.project, instance.domain);
|
|
28663
|
+
if (checked.status === "fail") return fail(checked.message);
|
|
28664
|
+
print(` ${style.dim(checked.message)}`);
|
|
28665
|
+
}
|
|
28666
|
+
}
|
|
28667
|
+
const resolved = loaded.resolved;
|
|
28668
|
+
const failed = [];
|
|
28669
|
+
let written = 0;
|
|
28670
|
+
let skipped = 0;
|
|
28671
|
+
for (const target of env.targets) {
|
|
28672
|
+
const environment = await input.resolveEnvironment(appLayer(target));
|
|
28673
|
+
const instance = instances.get(target);
|
|
28674
|
+
const routes = secretRoutes(resolved.repo?.secrets?.sync, environment);
|
|
28675
|
+
const variables = variableRoutes(resolved.repo?.variables?.sync, environment);
|
|
28676
|
+
const variablesOnly = variables.length > 0 && routes.length === 0;
|
|
28677
|
+
const filter = deployFilter(resolved.repo?.secrets?.deploy, environment);
|
|
28678
|
+
const report = await input.syncSecrets({
|
|
28679
|
+
loaded,
|
|
28680
|
+
context,
|
|
28681
|
+
loader,
|
|
28682
|
+
environmentId: environment,
|
|
28683
|
+
...instance ? {
|
|
28684
|
+
projectId: instance.project,
|
|
28685
|
+
targets: [instance.production ? "production" : target]
|
|
28686
|
+
} : {},
|
|
28687
|
+
...plan.workers ? { workerScript: app.name } : {},
|
|
28688
|
+
...filter ? { deployFilter: filter } : {},
|
|
28689
|
+
...routes.length ? { secretRoutes: routes } : variablesOnly ? { secretRoutes: [] } : {},
|
|
28690
|
+
...variables.length ? { variableRoutes: variables } : {}
|
|
28691
|
+
});
|
|
28692
|
+
written += report.summary.ok;
|
|
28693
|
+
skipped += report.summary.skip;
|
|
28694
|
+
if (report.summary.fail > 0) failed.push(`${target}: ${report.summary.fail} secret(s) did not sync`);
|
|
28695
|
+
}
|
|
28696
|
+
if (failed.length > 0) return {
|
|
28697
|
+
status: "fail",
|
|
28698
|
+
message: `${app.name}: ${failed.join("; ")}`
|
|
28699
|
+
};
|
|
28700
|
+
return {
|
|
28701
|
+
status: "ok",
|
|
28702
|
+
message: `${app.name} synced (${written} written, ${skipped} skipped)`
|
|
28703
|
+
};
|
|
28704
|
+
}
|
|
28705
|
+
// src/commands/new-instance/sync-seam/sync-seam.ts
|
|
28706
|
+
const REAL = {
|
|
28707
|
+
loadApp: loadAppSeam,
|
|
28708
|
+
parseAppEnv,
|
|
28709
|
+
runAppSync,
|
|
28710
|
+
resolveEnvironmentId,
|
|
28711
|
+
runSecretsSync
|
|
28712
|
+
};
|
|
28713
|
+
/**
|
|
28714
|
+
* `sync <app> --env <target>` as a step (spec `tech-new-instance-command` step 6): the same `runAppSync()` the command
|
|
28715
|
+
* runs, over the app's own config, with its report taken as an outcome instead of an exit code. The allow-list of
|
|
28716
|
+
* `repo.secrets.deploy` applies as it always does. Never throws.
|
|
28717
|
+
*/
|
|
28718
|
+
async function syncSeam(context, setup, deps = {}) {
|
|
28719
|
+
const real = {
|
|
28720
|
+
...REAL,
|
|
28721
|
+
...deps
|
|
28722
|
+
};
|
|
28723
|
+
try {
|
|
28724
|
+
const loadedApp = await real.loadApp(context, setup.app);
|
|
28725
|
+
const { app } = loadedApp;
|
|
28726
|
+
return appRunOutcome(await real.runAppSync({
|
|
28727
|
+
app,
|
|
28728
|
+
env: real.parseAppEnv([setup.target]),
|
|
28729
|
+
load: async () => ({
|
|
28730
|
+
loaded: loadedApp.loaded,
|
|
28731
|
+
context: loadedApp.context,
|
|
28732
|
+
loader: loadedApp.loader
|
|
28733
|
+
}),
|
|
28734
|
+
print: context.print,
|
|
28735
|
+
resolveEnvironment: (layer) => real.resolveEnvironmentId(layer, { repoRoot: app.dir }),
|
|
28736
|
+
syncSecrets: real.runSecretsSync
|
|
28737
|
+
}));
|
|
28738
|
+
} catch (err) {
|
|
28739
|
+
return {
|
|
28740
|
+
status: "fail",
|
|
28741
|
+
message: errorMessage(err)
|
|
28742
|
+
};
|
|
28743
|
+
}
|
|
28744
|
+
}
|
|
28745
|
+
// src/commands/new-instance/write-seams/write-seams.ts
|
|
28746
|
+
/**
|
|
28747
|
+
* The seams of `holocron new instance` that write something or ask (spec `tech-new-instance-command`): the project and
|
|
28748
|
+
* domain, a generated value, the GitHub App, the one import file, `sync`, `deploy` and the question. Each takes its
|
|
28749
|
+
* context from here and returns an outcome that names no value; none throws except the question, which throws
|
|
28750
|
+
* `NonInteractiveError` when there is no terminal. The read seams are made separately.
|
|
28751
|
+
*
|
|
28752
|
+
* @param context - Where the command runs and how it was asked to.
|
|
28753
|
+
*/
|
|
28754
|
+
function createWriteSeams(context) {
|
|
28755
|
+
return {
|
|
28756
|
+
ensureProject: (setup, dryRun) => ensureProjectSeam(context, setup, dryRun),
|
|
28757
|
+
generate: (name) => generateSecretValue(name),
|
|
28758
|
+
createApp: (setup, collect) => createAppSeam(context, setup, collect),
|
|
28759
|
+
handOff: (entries, environment) => handOffSeam(context, entries, environment),
|
|
28760
|
+
sync: (setup) => syncSeam(context, setup),
|
|
28761
|
+
deploy: (setup) => deploySeam(context, setup),
|
|
28762
|
+
confirm: (lines) => confirmSeam(context, lines)
|
|
28763
|
+
};
|
|
28764
|
+
}
|
|
28765
|
+
// src/commands/new-instance/create-new-instance-deps/create-new-instance-deps.ts
|
|
28766
|
+
/**
|
|
28767
|
+
* The real seams of `holocron new instance` (spec `tech-new-instance-command`): the read ones (`load`,
|
|
28768
|
+
* `readEnvironment`, `readBack`) and the write ones (the project, a generated value, the GitHub App, the import file,
|
|
28769
|
+
* `sync`, `deploy` and the question), one object for `runNewInstance()`. Every seam returns an outcome that names no
|
|
28770
|
+
* value; the write seams never throw but for the question without a terminal.
|
|
28771
|
+
*
|
|
28772
|
+
* @param context - Where the command runs and how it was asked to.
|
|
28773
|
+
*/
|
|
28774
|
+
function createNewInstanceDeps(context) {
|
|
28775
|
+
return {
|
|
28776
|
+
...createReadSeams(context),
|
|
28777
|
+
...createWriteSeams(context)
|
|
28778
|
+
};
|
|
28779
|
+
}
|
|
28780
|
+
// src/commands/new-instance/new-instance.args.ts
|
|
28781
|
+
const newInstanceArgs = (y) => y.positional("app", {
|
|
28782
|
+
type: "string",
|
|
28783
|
+
describe: "The app (a folder under apps/) whose `deployment` options declare the instance"
|
|
28784
|
+
}).option("env", {
|
|
28785
|
+
type: "string",
|
|
28786
|
+
default: "preview",
|
|
28787
|
+
describe: "The instance to make: the one the app declares under `instances` (only `preview` today)"
|
|
28788
|
+
}).option("yes", {
|
|
28789
|
+
type: "boolean",
|
|
28790
|
+
default: false,
|
|
28791
|
+
describe: "Make the instance without the one question before the first write (required without a terminal)"
|
|
28792
|
+
});
|
|
28793
|
+
// src/commands/instance-inputs/instance-inputs.ts
|
|
28794
|
+
/** Whether the layer's deploy filter lets the instance hold `name`: listed, or under a prefix. */
|
|
28795
|
+
function allowed(filter, name) {
|
|
28796
|
+
return filter.keys.includes(name) || filter.prefixes.some((prefix) => name.startsWith(prefix));
|
|
28797
|
+
}
|
|
28798
|
+
/**
|
|
28799
|
+
* Gives every name of an app's preview instance one source (spec `tech-new-instance-command`): made up, a constant, copied
|
|
28800
|
+
* from `prod`, one of the GitHub App's credentials, or a person's. The names are the declaration's lists, the App's
|
|
28801
|
+
* credential names and every `keys` entry of the layer's deploy filter, which is the one list of what the instance may
|
|
28802
|
+
* hold, so anything the filter lists that nothing else sources is the person's to make. Pure: it reads no Environment.
|
|
28803
|
+
*
|
|
28804
|
+
* @param input - The declaration, the layer's deploy filter and the App's credential names.
|
|
28805
|
+
* @returns The names in the order generate, value, copy, app, person; the last in the filter's order.
|
|
28806
|
+
* @throws {ConfigError} For a name that two lists claim, or one the filter would not let the instance hold (it would be
|
|
28807
|
+
* made and then never deployed).
|
|
28808
|
+
*/
|
|
28809
|
+
function instanceInputs(input) {
|
|
28810
|
+
const { app, declaration, filter, appNames } = input;
|
|
28811
|
+
const found = [
|
|
28812
|
+
...declaration.generate.map((name) => ({
|
|
28813
|
+
name,
|
|
28814
|
+
source: "generate"
|
|
28815
|
+
})),
|
|
28816
|
+
...Object.entries(declaration.values).map(([name, value]) => ({
|
|
28817
|
+
name,
|
|
28818
|
+
source: "value",
|
|
28819
|
+
value
|
|
28820
|
+
})),
|
|
28821
|
+
...declaration.copy.map((name) => ({
|
|
28822
|
+
name,
|
|
28823
|
+
source: "copy"
|
|
28824
|
+
})),
|
|
28825
|
+
...appNames.map((name) => ({
|
|
28826
|
+
name,
|
|
28827
|
+
source: "app"
|
|
28828
|
+
}))
|
|
28829
|
+
];
|
|
28830
|
+
for (const [index, entry] of found.entries()) {
|
|
28831
|
+
const earlier = found.slice(0, index).find((other) => other.name === entry.name);
|
|
28832
|
+
if (earlier) throw new ConfigError$1(`${app}: ${entry.name} is sourced twice, as ${earlier.source} and as ${entry.source}`);
|
|
28833
|
+
if (!allowed(filter, entry.name)) throw new ConfigError$1(`${app}: ${entry.name} is sourced (${entry.source}) but the layer's \`repo.secrets.deploy\` entry would not send it to the deployment`);
|
|
28834
|
+
}
|
|
28835
|
+
const rest = filter.keys.filter((name) => !found.some((entry) => entry.name === name)).map((name) => ({
|
|
28836
|
+
name,
|
|
28837
|
+
source: "person"
|
|
28838
|
+
}));
|
|
28839
|
+
return [...found, ...rest];
|
|
28840
|
+
}
|
|
28841
|
+
// src/commands/instance-token-guide/instance-token-guide.ts
|
|
28842
|
+
/**
|
|
28843
|
+
* For each name only a person can make, where to make it and what it needs: the plugin's own declaration of the token
|
|
28844
|
+
* (`PluginToken`: the vendor page, and the permissions its layer's token must and must not carry, read through
|
|
28845
|
+
* `tokenExpectations()`). A layer a token has no rules for yet (`preview` is new) reads `prod`'s, and `from` says so. A
|
|
28846
|
+
* name no plugin declares is listed with nothing more, because inventing a vendor page would be worse than none.
|
|
28847
|
+
*
|
|
28848
|
+
* @param names - The `person` names of `instanceInputs()`.
|
|
28849
|
+
* @param tokens - Every token the loaded plugins declare.
|
|
28850
|
+
* @param layer - The instance's layer (`preview`).
|
|
28851
|
+
*/
|
|
28852
|
+
function instanceTokenGuide(names, tokens, layer) {
|
|
28853
|
+
return names.map((name) => {
|
|
28854
|
+
const token = tokens.find((candidate) => candidate.envName === name || candidate.vendorEnvName === name);
|
|
28855
|
+
if (!token) return {
|
|
28856
|
+
name,
|
|
28857
|
+
declared: false,
|
|
28858
|
+
required: [],
|
|
28859
|
+
absent: []
|
|
28860
|
+
};
|
|
28861
|
+
const rules = tokenExpectations([token]);
|
|
28862
|
+
const own = rules.find((rule) => rule.layer === layer) ?? rules.find((rule) => rule.layer === "prod");
|
|
28863
|
+
return {
|
|
28864
|
+
name,
|
|
28865
|
+
declared: true,
|
|
28866
|
+
...token.page ? { page: token.page } : {},
|
|
28867
|
+
required: own ? [...own.required] : [],
|
|
28868
|
+
absent: own ? [...own.absent] : [],
|
|
28869
|
+
...own ? { from: own.layer } : {}
|
|
28870
|
+
};
|
|
28871
|
+
});
|
|
28872
|
+
}
|
|
28873
|
+
// src/commands/new-instance/resolve-copies/resolve-copies.ts
|
|
28874
|
+
/**
|
|
28875
|
+
* Settles which `copy` names can be copied. A name already in the instance's Environment is left as it is (a value is
|
|
28876
|
+
* never overwritten). One the `prod` Environment holds with a value that is not concealed is copied. Any other, whether
|
|
28877
|
+
* the Environment cannot be read, holds no such name, holds it blank or conceals it, becomes a person's input, with the
|
|
28878
|
+
* reason, so the run neither guesses nor reads a concealed value.
|
|
28879
|
+
*
|
|
28880
|
+
* @param inputs - `instanceInputs()`.
|
|
28881
|
+
* @param read - The `prod` Environment read with the `copy` names' values, or `undefined` when no name needed a copy.
|
|
28882
|
+
* @param has - Whether the instance's own Environment already holds a name with a value.
|
|
28883
|
+
* @param from - The `prod` Environment's name, for the reasons.
|
|
28884
|
+
* @returns The inputs with unavailable copies turned into `person`, the values to write by name, and why each was turned.
|
|
28885
|
+
*/
|
|
28886
|
+
function resolveCopies(inputs, read, has, from) {
|
|
28887
|
+
const values = /* @__PURE__ */ new Map();
|
|
28888
|
+
const demoted = [];
|
|
28889
|
+
return {
|
|
28890
|
+
inputs: inputs.map((input) => {
|
|
28891
|
+
if (input.source !== "copy" || has(input.name)) return input;
|
|
28892
|
+
const why = whyNot(input.name, read, from);
|
|
28893
|
+
if (typeof why === "string") {
|
|
28894
|
+
demoted.push({
|
|
28895
|
+
name: input.name,
|
|
28896
|
+
why
|
|
28897
|
+
});
|
|
28898
|
+
return {
|
|
28899
|
+
name: input.name,
|
|
28900
|
+
source: "person"
|
|
28901
|
+
};
|
|
28902
|
+
}
|
|
28903
|
+
values.set(input.name, why.value);
|
|
28904
|
+
return input;
|
|
28905
|
+
}),
|
|
28906
|
+
values,
|
|
28907
|
+
demoted
|
|
28908
|
+
};
|
|
28909
|
+
}
|
|
28910
|
+
/** The reason a name cannot be copied, or its value. */
|
|
28911
|
+
function whyNot(name, read, from) {
|
|
28912
|
+
if (!read || read.status === "unreadable") return `${from} could not be read${read ? `: ${read.reason}` : ""}`;
|
|
28913
|
+
if (read.status === "missing") return `${from} does not exist`;
|
|
28914
|
+
const entry = read.entries[name];
|
|
28915
|
+
if (!entry) return `${from} holds no ${name}`;
|
|
28916
|
+
if (entry.concealed) return `${name} is concealed in ${from}, and a concealed value is never copied`;
|
|
28917
|
+
if (entry.blank || entry.value === void 0) return `${name} is blank in ${from}`;
|
|
28918
|
+
return { value: entry.value };
|
|
28919
|
+
}
|
|
28920
|
+
// src/commands/new-instance/step-row/step-row.ts
|
|
28921
|
+
/**
|
|
28922
|
+
* A setup step (`ensureInstanceProject()` reports in them) as a row of `new instance`: `ok` and `fail` stay, and a step a
|
|
28923
|
+
* dry run did not run, or the provider skipped, is a skipped row that says which.
|
|
28924
|
+
*/
|
|
28925
|
+
function stepRow(step) {
|
|
28926
|
+
const status = step.status === "ok" || step.status === "fail" ? step.status : "skip";
|
|
28927
|
+
const detail = step.message ?? (step.status === "dry-run" ? "would run" : "");
|
|
28928
|
+
return {
|
|
28929
|
+
id: `instance:${step.capability}:${step.step}`,
|
|
28930
|
+
title: step.step,
|
|
28931
|
+
status,
|
|
28932
|
+
detail,
|
|
28933
|
+
problems: []
|
|
28934
|
+
};
|
|
28935
|
+
}
|
|
28936
|
+
// src/commands/new-instance/token-problem/token-problem.ts
|
|
28937
|
+
/**
|
|
28938
|
+
* One line a person can act on for a token they have to make: the variable, where it is made, what it must have and what
|
|
28939
|
+
* it must not, and which layer's rules those are. A token no plugin declares says so, because nothing more is known.
|
|
28940
|
+
* Names and addresses only.
|
|
28941
|
+
*/
|
|
28942
|
+
function tokenProblem(guide) {
|
|
28943
|
+
if (!guide.declared) return `${guide.name}: no plugin declares it, so make it where it comes from`;
|
|
28944
|
+
const where = guide.page ? `make it at ${guide.page}` : "its plugin names no page to make it at";
|
|
28945
|
+
const needs = guide.required.length > 0 ? `; it needs ${guide.required.join(", ")}` : "";
|
|
28946
|
+
const avoids = guide.absent.length > 0 ? `; it must not have ${guide.absent.join(", ")}` : "";
|
|
28947
|
+
const from = guide.from ? ` (the ${guide.from} layer's rules)` : "";
|
|
28948
|
+
return `${guide.name}: ${where}${needs}${avoids}${from}`;
|
|
28949
|
+
}
|
|
28950
|
+
// src/commands/new-instance/run-new-instance/run-new-instance.ts
|
|
28951
|
+
/** The steps in order, which is also how a stop says what is left: the step that stopped it and every one after. */
|
|
28952
|
+
const STEPS = [
|
|
28953
|
+
"the plan",
|
|
28954
|
+
"the Environment",
|
|
28955
|
+
"project and domain",
|
|
28956
|
+
"the GitHub App",
|
|
28957
|
+
"the import",
|
|
28958
|
+
"the tokens",
|
|
28959
|
+
"sync",
|
|
28960
|
+
"deploy",
|
|
28961
|
+
"the read-backs",
|
|
28962
|
+
"the App's installation"
|
|
28963
|
+
];
|
|
28964
|
+
/**
|
|
28965
|
+
* `holocron new instance`: makes a whole instance of an app, in the order that worked for the preview Sentinel (spec
|
|
28966
|
+
* `tech-new-instance-command`, step 7 of its rollout is the command around this): plan, the Environment, project and
|
|
28967
|
+
* domain, the GitHub App, one import file, the tokens only a person makes, sync, deploy, the read-backs and the App's
|
|
28968
|
+
* installation. It stops at the first step that does not work and says what is left; a rerun skips what is done (a name the
|
|
28969
|
+
* Environment already holds is never written again, so a generated secret is not rotated); `dryRun` runs the reads and writes
|
|
28970
|
+
* nothing; it asks once before the first write unless `yes`.
|
|
28971
|
+
*
|
|
28972
|
+
* Every effect is behind `deps`, so this function is only the order, the stops and the rows. No value is ever printed,
|
|
28973
|
+
* logged or returned: the entries it hands to `deps` are the only place one exists, and they are dropped when it returns.
|
|
28974
|
+
*/
|
|
28975
|
+
async function runNewInstance(input) {
|
|
28976
|
+
const { app, target, deps } = input;
|
|
28977
|
+
const yes = input.yes ?? false;
|
|
28978
|
+
const dryRun = input.dryRun ?? false;
|
|
28979
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
28980
|
+
const rows = [];
|
|
28981
|
+
let tokens = [];
|
|
28982
|
+
let installUrl;
|
|
28983
|
+
const add = (id, title, status, detail, problems = []) => {
|
|
28984
|
+
rows.push({
|
|
28985
|
+
id: `instance:${id}`,
|
|
28986
|
+
title,
|
|
28987
|
+
status,
|
|
28988
|
+
detail,
|
|
28989
|
+
problems
|
|
28990
|
+
});
|
|
28991
|
+
};
|
|
28992
|
+
const end = (status, stoppedAt) => {
|
|
28993
|
+
printCheckRows(rows, print);
|
|
28994
|
+
printCheckSummary(summariseChecks(rows), print);
|
|
28995
|
+
const left = stoppedAt ? STEPS.slice(STEPS.indexOf(stoppedAt)) : [];
|
|
28996
|
+
if (left.length > 0) print(`still to do: ${left.join(", ")}`);
|
|
28997
|
+
return {
|
|
28998
|
+
status,
|
|
28999
|
+
rows,
|
|
29000
|
+
tokens,
|
|
29001
|
+
left: [...left],
|
|
29002
|
+
...installUrl ? { installUrl } : {}
|
|
29003
|
+
};
|
|
29004
|
+
};
|
|
29005
|
+
/** Runs one of the effects that only says whether it worked. A dry run only says it would. */
|
|
29006
|
+
const effect = async (id, title, run, setup) => {
|
|
29007
|
+
if (dryRun) {
|
|
29008
|
+
add(id, title, "skip", "would run");
|
|
29009
|
+
return true;
|
|
29010
|
+
}
|
|
29011
|
+
const outcome = await run(setup);
|
|
29012
|
+
add(id, title, outcome.status, outcome.message ?? (outcome.status === "ok" ? "done" : "did not work"));
|
|
29013
|
+
return outcome.status === "ok";
|
|
29014
|
+
};
|
|
29015
|
+
let setup;
|
|
29016
|
+
let inputs;
|
|
29017
|
+
try {
|
|
29018
|
+
setup = await deps.load(app, target);
|
|
29019
|
+
inputs = instanceInputs({
|
|
29020
|
+
app,
|
|
29021
|
+
declaration: setup.declaration,
|
|
29022
|
+
filter: setup.filter,
|
|
29023
|
+
appNames: setup.appNames
|
|
29024
|
+
});
|
|
29025
|
+
} catch (err) {
|
|
29026
|
+
add("plan", "the plan", "fail", errorMessage(err));
|
|
29027
|
+
return end("fail", "the plan");
|
|
29028
|
+
}
|
|
29029
|
+
const own = await deps.readEnvironment(setup.environment);
|
|
29030
|
+
if (own.status !== "ok") {
|
|
29031
|
+
add("environment", "the Environment", "fail", own.status === "missing" ? `${setup.environment} does not exist: make it in the 1Password app (Developer, View Environments), then run this again` : `${setup.environment} could not be read: ${own.reason}`);
|
|
29032
|
+
return end("fail", "the Environment");
|
|
29033
|
+
}
|
|
29034
|
+
const holds = (read, name) => {
|
|
29035
|
+
const entry = read.entries[name];
|
|
29036
|
+
return entry !== void 0 && !entry.blank;
|
|
29037
|
+
};
|
|
29038
|
+
const has = (name) => holds(own, name);
|
|
29039
|
+
const copyNames = inputs.filter((input) => input.source === "copy" && !has(input.name)).map((input) => input.name);
|
|
29040
|
+
const copyRead = copyNames.length > 0 ? await deps.readEnvironment(setup.copyEnvironment, copyNames) : void 0;
|
|
29041
|
+
const resolved = resolveCopies(inputs, copyRead, has, setup.copyEnvironment);
|
|
29042
|
+
for (const { name, why } of resolved.demoted) add(`copy:${name}`, `${name} is not copied`, "skip", `${why}; it is yours to set`);
|
|
29043
|
+
const missing = (source) => resolved.inputs.filter((input) => input.source === source && !has(input.name));
|
|
29044
|
+
const toGenerate = missing("generate");
|
|
29045
|
+
const toSet = missing("value");
|
|
29046
|
+
const toCopy = missing("copy");
|
|
29047
|
+
const persons = missing("person").map((input) => input.name);
|
|
29048
|
+
const slots = persons.filter((name) => own.entries[name] === void 0);
|
|
29049
|
+
const appMissing = setup.appNames.length > 0 && setup.appNames.some((name) => !has(name));
|
|
29050
|
+
add("plan", "the plan", "ok", `${resolved.inputs.length} names in ${setup.environment} (${resolved.inputs.filter((input) => has(input.name)).length} already there): ${toGenerate.length} to make up, ${toSet.length} constants, ${toCopy.length} to copy from ${setup.copyEnvironment}, ${appMissing ? setup.appNames.length : 0} from the GitHub App, ${persons.length} tokens that are a person's`);
|
|
29051
|
+
const importNames = [
|
|
29052
|
+
...[
|
|
29053
|
+
...toGenerate,
|
|
29054
|
+
...toSet,
|
|
29055
|
+
...toCopy
|
|
29056
|
+
].map((input) => input.name),
|
|
29057
|
+
...appMissing ? setup.appNames : [],
|
|
29058
|
+
...slots
|
|
29059
|
+
];
|
|
29060
|
+
if (!dryRun && !yes) {
|
|
29061
|
+
const lines = [
|
|
29062
|
+
`make the project ${setup.project}${setup.domain ? ` and its domain ${setup.domain}` : ""}`,
|
|
29063
|
+
`hand ${importNames.length} names to ${setup.environment} for import: ${importNames.join(", ") || "(none)"}`,
|
|
29064
|
+
appMissing ? "make the GitHub App from its manifest (you press Create GitHub App once)" : "keep the GitHub App as it is"
|
|
29065
|
+
];
|
|
29066
|
+
if (!await deps.confirm(lines)) {
|
|
29067
|
+
add("confirm", "the question", "skip", "not confirmed: nothing was written");
|
|
29068
|
+
return end("cancelled", "project and domain");
|
|
29069
|
+
}
|
|
29070
|
+
}
|
|
29071
|
+
const projectSteps = await deps.ensureProject(setup, dryRun);
|
|
29072
|
+
rows.push(...projectSteps.map(stepRow));
|
|
29073
|
+
if (projectSteps.some((step) => step.status === "fail")) return end("fail", "project and domain");
|
|
29074
|
+
const collected = [];
|
|
29075
|
+
if (setup.appNames.length === 0) add("app", "the GitHub App", "skip", "no GitHub App is declared for this instance");
|
|
29076
|
+
else if (!appMissing) add("app", "the GitHub App", "ok", "the Environment already holds its credentials");
|
|
29077
|
+
else if (dryRun) add("app", "the GitHub App", "skip", `would make the App; its credentials: ${setup.appNames.join(", ")}`);
|
|
29078
|
+
else {
|
|
29079
|
+
const made = await deps.createApp(setup, (entries) => {
|
|
29080
|
+
collected.push(...entries);
|
|
29081
|
+
});
|
|
29082
|
+
if (made.status === "fail") {
|
|
29083
|
+
add("app", "the GitHub App", "fail", made.message ?? "the App was not made");
|
|
29084
|
+
return end("fail", "the GitHub App");
|
|
29085
|
+
}
|
|
29086
|
+
installUrl = made.installUrl;
|
|
29087
|
+
add("app", "the GitHub App", "ok", `made; its credentials: ${collected.map((entry) => entry.name).join(", ")}`);
|
|
29088
|
+
}
|
|
29089
|
+
let current = own;
|
|
29090
|
+
if (dryRun) add("import", "the import file", importNames.length === 0 ? "ok" : "skip", importNames.length === 0 ? "the Environment already holds every name" : `would hand off ${importNames.length} names: ${importNames.join(", ")}`);
|
|
29091
|
+
else {
|
|
29092
|
+
const entries = [
|
|
29093
|
+
...toGenerate.map((input) => ({
|
|
29094
|
+
name: input.name,
|
|
29095
|
+
value: deps.generate(input.name)
|
|
29096
|
+
})),
|
|
29097
|
+
...toSet.map((input) => ({
|
|
29098
|
+
name: input.name,
|
|
29099
|
+
value: input.value
|
|
29100
|
+
})),
|
|
29101
|
+
...toCopy.map((input) => ({
|
|
29102
|
+
name: input.name,
|
|
29103
|
+
value: resolved.values.get(input.name)
|
|
29104
|
+
})),
|
|
29105
|
+
...collected,
|
|
29106
|
+
...slots.map((name) => ({
|
|
29107
|
+
name,
|
|
29108
|
+
value: ""
|
|
29109
|
+
}))
|
|
29110
|
+
];
|
|
29111
|
+
if (entries.length === 0) add("import", "the import file", "ok", "the Environment already holds every name");
|
|
29112
|
+
else {
|
|
29113
|
+
const handed = await deps.handOff(entries, setup.environment);
|
|
29114
|
+
if (handed.status === "fail") {
|
|
29115
|
+
add("import", "the import file", "fail", handed.message ?? "the import file was not handed off");
|
|
29116
|
+
return end("fail", "the import");
|
|
29117
|
+
}
|
|
29118
|
+
const after = await deps.readEnvironment(setup.environment);
|
|
29119
|
+
if (after.status !== "ok") {
|
|
29120
|
+
add("import", "the import file", "fail", `${setup.environment} could not be read after the import${after.status === "unreadable" ? `: ${after.reason}` : ""}`);
|
|
29121
|
+
return end("fail", "the import");
|
|
29122
|
+
}
|
|
29123
|
+
const lost = entries.filter((entry) => entry.value !== "" && !holds(after, entry.name)).map((entry) => entry.name);
|
|
29124
|
+
if (lost.length > 0) {
|
|
29125
|
+
add("import", "the import file", "fail", `the import did not land: ${lost.join(", ")} still missing from ${setup.environment}`);
|
|
29126
|
+
return end("fail", "the import");
|
|
29127
|
+
}
|
|
29128
|
+
add("import", "the import file", "ok", `${entries.length} names handed off and imported`);
|
|
29129
|
+
current = after;
|
|
29130
|
+
}
|
|
29131
|
+
}
|
|
29132
|
+
const blank = persons.filter((name) => !holds(current, name));
|
|
29133
|
+
if (blank.length === 0) add("tokens", "the tokens", "ok", "no token is missing");
|
|
29134
|
+
else {
|
|
29135
|
+
tokens = instanceTokenGuide(blank, setup.tokens, setup.layer);
|
|
29136
|
+
const problems = tokens.map(tokenProblem);
|
|
29137
|
+
if (dryRun) add("tokens", "the tokens", "skip", `${blank.length} for a person to make: ${blank.join(", ")}`, problems);
|
|
29138
|
+
else {
|
|
29139
|
+
add("tokens", "the tokens", "fail", `${blank.length} still to make and fill in ${setup.environment}: ${blank.join(", ")}`, problems);
|
|
29140
|
+
return end("waiting", "the tokens");
|
|
29141
|
+
}
|
|
29142
|
+
}
|
|
29143
|
+
if (!await effect("sync", "sync the Environment to the project", deps.sync, setup)) return end("fail", "sync");
|
|
29144
|
+
if (!await effect("deploy", "deploy the instance", deps.deploy, setup)) return end("fail", "deploy");
|
|
29145
|
+
if (dryRun) add("read-back", "the read-backs", "skip", "would read the webhook, doctor github-app and doctor secrets");
|
|
29146
|
+
else {
|
|
29147
|
+
const found = await deps.readBack(setup);
|
|
29148
|
+
rows.push(...found);
|
|
29149
|
+
if (found.some((row) => row.status === "fail")) return end("fail", "the read-backs");
|
|
29150
|
+
}
|
|
29151
|
+
if (setup.appNames.length === 0) return end("ok");
|
|
29152
|
+
installUrl = installUrl ?? setup.installUrl;
|
|
29153
|
+
add("install", "install the GitHub App", installUrl ? "ok" : "skip", installUrl ? `install it on the repositories it should see: ${installUrl}` : "install it from its settings page; its link was printed when it was made");
|
|
29154
|
+
return end("ok", "the App's installation");
|
|
29155
|
+
}
|
|
29156
|
+
// src/commands/new-instance/new-instance.ts
|
|
29157
|
+
/**
|
|
29158
|
+
* `holocron new instance <app> --env <target>` (spec `tech-new-instance-command`): reads the arguments, builds the real
|
|
29159
|
+
* seams and hands them to `runNewInstance()`, which prints its own rows. A run that stopped for a token or a step that did
|
|
29160
|
+
* not work is a non-zero exit; a "no" at the question is not.
|
|
29161
|
+
*
|
|
29162
|
+
* @param argv - The parsed arguments of `holocron new instance`.
|
|
29163
|
+
* @param io - Builds the seams, and the orchestrator when a test supplies another.
|
|
29164
|
+
*/
|
|
29165
|
+
async function newInstance(argv, io) {
|
|
29166
|
+
const tokens = tokenContext(argv.token);
|
|
29167
|
+
if (!tokens) return;
|
|
29168
|
+
const [app] = await promptForPositionals(getEntry("new instance"), argv);
|
|
29169
|
+
const context = {
|
|
29170
|
+
cwd: argv.cwd,
|
|
29171
|
+
dryRun: argv.dryRun,
|
|
29172
|
+
tokens,
|
|
29173
|
+
...argv.org ? { org: argv.org } : {},
|
|
29174
|
+
print: (line) => console.error(line)
|
|
29175
|
+
};
|
|
29176
|
+
const result = await (io.run ?? runNewInstance)({
|
|
29177
|
+
app,
|
|
29178
|
+
target: argv.env,
|
|
29179
|
+
deps: io.createDeps(context),
|
|
29180
|
+
...argv.yes ? { yes: true } : {},
|
|
29181
|
+
...argv.dryRun ? { dryRun: true } : {}
|
|
29182
|
+
});
|
|
29183
|
+
if (result.status === "fail" || result.status === "waiting") process.exitCode = 1;
|
|
29184
|
+
}
|
|
29185
|
+
// src/commands/new-instance/new-instance.command.ts
|
|
29186
|
+
const newInstanceCommand = {
|
|
29187
|
+
command: "instance [app]",
|
|
29188
|
+
describe: "Make a whole app instance (project, domain, secrets, GitHub App, deploy), and name only the tokens a person creates",
|
|
29189
|
+
builder: newInstanceArgs,
|
|
29190
|
+
handler: async (argv) => newInstance(argv, { createDeps: createNewInstanceDeps })
|
|
29191
|
+
};
|
|
29192
|
+
// src/commands/new-work/git-assignee/git-assignee.ts
|
|
29193
|
+
const NOREPLY = /^(?:\d+\+)?([A-Za-z0-9-]+)@users\.noreply\.github\.com$/;
|
|
29194
|
+
/**
|
|
29195
|
+
* The GitHub login of the person at this machine, from git's own config (spec `tool-work-commands`, Decisions 4: the
|
|
29196
|
+
* default assignee is the git config user, never the token's identity, which is a bot under an agent). `read` answers
|
|
29197
|
+
* one config key. `github.user` is the login when set; otherwise a `users.noreply.github.com` email names it. A
|
|
29198
|
+
* `user.name` is a display name, not a login, so it is never guessed from; with neither, there is no default.
|
|
29199
|
+
*/
|
|
29200
|
+
function gitAssignee(read) {
|
|
29201
|
+
const login = read("github.user")?.trim();
|
|
29202
|
+
if (login) return login;
|
|
29203
|
+
return NOREPLY.exec(read("user.email")?.trim() ?? "")?.[1];
|
|
29204
|
+
}
|
|
29205
|
+
// src/commands/new-work/prompt-effort/prompt-effort.ts
|
|
29206
|
+
/** Asks which Effort the work is; `undefined` when the person leaves it unset. */
|
|
29207
|
+
async function promptEffort() {
|
|
29208
|
+
const answer = await select({
|
|
29209
|
+
message: "Effort:",
|
|
29210
|
+
choices: [
|
|
29211
|
+
{
|
|
29212
|
+
name: "high",
|
|
29213
|
+
value: "high"
|
|
29214
|
+
},
|
|
29215
|
+
{
|
|
29216
|
+
name: "medium",
|
|
29217
|
+
value: "medium"
|
|
29218
|
+
},
|
|
29219
|
+
{
|
|
29220
|
+
name: "low",
|
|
29221
|
+
value: "low"
|
|
29222
|
+
},
|
|
29223
|
+
{
|
|
29224
|
+
name: "leave it unset",
|
|
29225
|
+
value: "none"
|
|
29226
|
+
}
|
|
29227
|
+
]
|
|
29228
|
+
});
|
|
29229
|
+
return answer === "none" ? void 0 : answer;
|
|
29230
|
+
}
|
|
29231
|
+
// src/commands/new-work/read-git-config/read-git-config.ts
|
|
29232
|
+
/** One `git config --get` value in a directory, or `undefined` when the key is unset or git fails. */
|
|
29233
|
+
function readGitConfig(cwd, key, run = runGit) {
|
|
29234
|
+
try {
|
|
29235
|
+
return run([
|
|
29236
|
+
"config",
|
|
29237
|
+
"--get",
|
|
29238
|
+
key
|
|
29239
|
+
], cwd) || void 0;
|
|
29240
|
+
} catch {
|
|
29241
|
+
return;
|
|
29242
|
+
}
|
|
29243
|
+
}
|
|
29244
|
+
// src/commands/new-work/run-new-work/run-new-work.ts
|
|
29245
|
+
/**
|
|
29246
|
+
* `holocron new work` — files an issue with every field and, when asked, writes the spec stub (spec
|
|
29247
|
+
* `tool-work-commands`). It is `new issue` plus `new spec`: the issue goes through {@link runIssueCreate} (so the
|
|
29248
|
+
* fields, the board, the confirmation and `--dry-run` are that command's) and the spec through
|
|
29249
|
+
* {@link runIdeasPromote}, written to the working tree only. It makes no branch and no commit: that is `start work`,
|
|
29250
|
+
* which the last line names, with the spec's path. The assignee defaults to the git config user, never the token's
|
|
29251
|
+
* identity; Effort is asked on a terminal when it was not given (the CLI never chooses it). The issue's key is printed
|
|
29252
|
+
* by the first row, before anything else is done, so a failed spec leaves the issue as the anchor to resume from.
|
|
29253
|
+
*/
|
|
29254
|
+
const row$8 = (id, status, detail) => ({
|
|
29255
|
+
id,
|
|
29256
|
+
title: id,
|
|
29257
|
+
status,
|
|
29258
|
+
detail,
|
|
29259
|
+
problems: []
|
|
29260
|
+
});
|
|
29261
|
+
async function runNewWork(input) {
|
|
29262
|
+
/* v8 ignore next -- the console is only used outside tests, which inject `print` */
|
|
29263
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
29264
|
+
const dryRun = Boolean(input.context.dryRun);
|
|
29265
|
+
const root = input.context.repoRoot;
|
|
29266
|
+
const extra = [];
|
|
29267
|
+
const io = input.io ?? realPromoteIo;
|
|
29268
|
+
let specPath;
|
|
29269
|
+
if (input.spec) {
|
|
29270
|
+
const name = specName(input.title, input.specName);
|
|
29271
|
+
if (!name) {
|
|
29272
|
+
const detail = input.specName === void 0 ? "no spec name can be made from the title; pass --spec <name>" : `"${input.specName}" is not a spec name: use lower-case words joined by hyphens, such as tech-my-topic`;
|
|
29273
|
+
const rows = [row$8("spec", "fail", detail)];
|
|
29274
|
+
printCheckRows(rows, print);
|
|
29275
|
+
return {
|
|
29276
|
+
status: "fail",
|
|
29277
|
+
rows
|
|
29278
|
+
};
|
|
29279
|
+
}
|
|
29280
|
+
specPath = join(".notes", `${name}.spec.md`);
|
|
29281
|
+
if (io.exists(join(root, specPath))) {
|
|
29282
|
+
const rows = [row$8(specPath, "fail", "the spec already exists; it is never overwritten")];
|
|
29283
|
+
printCheckRows(rows, print);
|
|
29284
|
+
return {
|
|
29285
|
+
status: "fail",
|
|
29286
|
+
rows,
|
|
29287
|
+
specPath
|
|
29288
|
+
};
|
|
29289
|
+
}
|
|
29290
|
+
}
|
|
29291
|
+
const assignees = input.assignees && input.assignees.length > 0 ? input.assignees : [gitAssignee(input.gitConfig ?? ((key) => readGitConfig(root, key)))].filter((a) => Boolean(a));
|
|
29292
|
+
if (!input.assignees?.length && assignees.length === 0) extra.push(row$8("assignee", "skip", "git config has no GitHub login (`github.user`); pass --assignee to assign the issue"));
|
|
29293
|
+
let effort = input.effort;
|
|
29294
|
+
const interactive = input.interactive ?? Boolean(process.stdin.isTTY);
|
|
29295
|
+
if (!effort && !input.yes && !dryRun && interactive) effort = await (input.askEffort ?? promptEffort)();
|
|
29296
|
+
const created = await runIssueCreate({
|
|
29297
|
+
...input,
|
|
29298
|
+
...assignees.length > 0 ? { assignees } : {},
|
|
29299
|
+
...effort ? { effort } : {}
|
|
29300
|
+
});
|
|
29301
|
+
if (created.status === "cancelled") return {
|
|
29302
|
+
status: "cancelled",
|
|
29303
|
+
rows: []
|
|
29304
|
+
};
|
|
29305
|
+
printCheckRows(extra, print);
|
|
29306
|
+
const rows = [...created.rows, ...extra];
|
|
29307
|
+
if (created.status === "fail") return {
|
|
29308
|
+
status: "fail",
|
|
29309
|
+
rows,
|
|
29310
|
+
...created.key ? { key: created.key } : {}
|
|
29311
|
+
};
|
|
29312
|
+
if (!input.spec || !specPath) {
|
|
29313
|
+
if (created.key) print(` ${style.skip(`next: holocron start work ${created.key}`)}`);
|
|
29314
|
+
return {
|
|
29315
|
+
status: "ok",
|
|
29316
|
+
rows,
|
|
29317
|
+
...created.key ? { key: created.key } : {}
|
|
29318
|
+
};
|
|
29319
|
+
}
|
|
29320
|
+
if (dryRun || !created.key) {
|
|
29321
|
+
print(` ${style.skip(`would write ${specPath} from the new issue; nothing is written on a dry run`)}`);
|
|
29322
|
+
return {
|
|
29323
|
+
status: "ok",
|
|
29324
|
+
rows,
|
|
29325
|
+
specPath
|
|
29326
|
+
};
|
|
29327
|
+
}
|
|
29328
|
+
const spec = await runIdeasPromote({
|
|
29329
|
+
issue: created.key,
|
|
29330
|
+
...input.specName ? { name: input.specName } : {},
|
|
29331
|
+
loaded: input.loaded,
|
|
29332
|
+
context: input.context,
|
|
29333
|
+
yes: true,
|
|
29334
|
+
...input.loader ? { loader: input.loader } : {},
|
|
29335
|
+
io,
|
|
29336
|
+
print
|
|
29337
|
+
});
|
|
29338
|
+
const path = spec.path ?? specPath;
|
|
29339
|
+
const status = spec.status === "ok" ? "ok" : "fail";
|
|
29340
|
+
if (status === "ok") print(` ${style.skip(`next: holocron start work ${created.key} --spec ${path} (the spec is written, not committed)`)}`);
|
|
29341
|
+
else print(` ${style.skip(`the issue ${created.key} exists; fix the spec and run \`holocron new spec ${created.key}\``)}`);
|
|
29342
|
+
return {
|
|
29343
|
+
status,
|
|
29344
|
+
rows: [...rows, ...spec.rows],
|
|
29345
|
+
key: created.key,
|
|
29346
|
+
specPath: path
|
|
27486
29347
|
};
|
|
27487
29348
|
}
|
|
27488
29349
|
// src/commands/new-work/new-work.command.ts
|
|
@@ -29144,31 +31005,6 @@ const projectCreateCommand = {
|
|
|
29144
31005
|
})).status === "fail") process.exitCode = 1;
|
|
29145
31006
|
}
|
|
29146
31007
|
};
|
|
29147
|
-
// src/commands/generated-secrets/generated-secrets.ts
|
|
29148
|
-
/**
|
|
29149
|
-
* The secrets the CLI may make up (spec `tech-rotate-generated-secrets`). A name is here only when its value is random
|
|
29150
|
-
* and nobody else issues or holds a copy: a vendor's API token, or a signing secret the vendor also stores, must not be
|
|
29151
|
-
* invented, so anything not listed is refused by `generateSecretValue()`.
|
|
29152
|
-
*/
|
|
29153
|
-
const GENERATED_SECRETS = { CRON_SECRET: {
|
|
29154
|
-
bytes: 32,
|
|
29155
|
-
encoding: "hex",
|
|
29156
|
-
note: "the bearer Vercel's cron sends to Sentinel's /api/scheduled"
|
|
29157
|
-
} };
|
|
29158
|
-
/** The recipe for `name`, or `undefined` when the CLI does not make that secret. */
|
|
29159
|
-
function generatedSecret(name) {
|
|
29160
|
-
return Object.hasOwn(GENERATED_SECRETS, name) ? GENERATED_SECRETS[name] : void 0;
|
|
29161
|
-
}
|
|
29162
|
-
/**
|
|
29163
|
-
* A fresh value for a secret in {@link GENERATED_SECRETS}. The value is never printed or logged by the caller.
|
|
29164
|
-
*
|
|
29165
|
-
* @throws {Error} When `name` is not one the CLI generates (the message lists the ones it does).
|
|
29166
|
-
*/
|
|
29167
|
-
function generateSecretValue(name, random = randomBytes) {
|
|
29168
|
-
const recipe = generatedSecret(name);
|
|
29169
|
-
if (!recipe) throw new Error(`${name} is not a secret the CLI generates (${Object.keys(GENERATED_SECRETS).join(", ")}): a token a vendor issues cannot be made up`);
|
|
29170
|
-
return Buffer.from(random(recipe.bytes)).toString(recipe.encoding);
|
|
29171
|
-
}
|
|
29172
31008
|
// src/commands/secret-handoff/secret-handoff.ts
|
|
29173
31009
|
/**
|
|
29174
31010
|
* Hand one made-up secret to a person for import into a vault. The CLI cannot write to a 1Password Environment, so the
|
|
@@ -30256,8 +32092,8 @@ const newRepoCommand = {
|
|
|
30256
32092
|
// src/commands/new/new.command.ts
|
|
30257
32093
|
const newCommand = {
|
|
30258
32094
|
command: "new",
|
|
30259
|
-
describe: "Create a repo, plugin, channel, server, secret, token, tunnel, domain record, GitHub App, project, spec, issue, incident or work",
|
|
30260
|
-
builder: (y) => y.command(newRepoCommand).command(pluginCreateCommand).command(notificationsChannelAddCommand).command(githubAppCreateCommand).command(projectCreateCommand).command(secretSetCommand).command(notificationsCreateServerCommand).command(ideasPromoteCommand).command(issueCreateCommand).command(newWorkCommand).command(authSetCommand).command(tunnelUpCommand).command(newDomainCommand).command(newIncidentCommand).command(groupMenu("new")),
|
|
32095
|
+
describe: "Create a repo, plugin, channel, server, secret, token, tunnel, domain record, GitHub App, project, spec, issue, incident, instance or work",
|
|
32096
|
+
builder: (y) => y.command(newRepoCommand).command(pluginCreateCommand).command(notificationsChannelAddCommand).command(githubAppCreateCommand).command(projectCreateCommand).command(secretSetCommand).command(notificationsCreateServerCommand).command(ideasPromoteCommand).command(issueCreateCommand).command(newWorkCommand).command(authSetCommand).command(tunnelUpCommand).command(newDomainCommand).command(newIncidentCommand).command(newInstanceCommand).command(groupMenu("new")),
|
|
30261
32097
|
handler: () => {}
|
|
30262
32098
|
};
|
|
30263
32099
|
// src/commands/open-requests/parse-open-layers/parse-open-layers.ts
|
|
@@ -32010,7 +33846,7 @@ function writeLcov(ctx, repoRoot, packages) {
|
|
|
32010
33846
|
function percent(documented, total) {
|
|
32011
33847
|
return `${total === 0 ? 100 : Math.round(100 * documented / total)}%`;
|
|
32012
33848
|
}
|
|
32013
|
-
function summarise$
|
|
33849
|
+
function summarise$1(ctx, packages) {
|
|
32014
33850
|
let total = 0;
|
|
32015
33851
|
let documented = 0;
|
|
32016
33852
|
ctx.say({
|
|
@@ -32062,7 +33898,7 @@ function docsCoverageProbes(repoRoot, typedoc = runTypedoc(repoRoot), diff = rea
|
|
|
32062
33898
|
async run(ctx) {
|
|
32063
33899
|
const packages = measure();
|
|
32064
33900
|
writeLcov(ctx, repoRoot, packages);
|
|
32065
|
-
summarise$
|
|
33901
|
+
summarise$1(ctx, packages);
|
|
32066
33902
|
}
|
|
32067
33903
|
},
|
|
32068
33904
|
patch: {
|
|
@@ -32129,7 +33965,7 @@ function docsCoverageProbes(repoRoot, typedoc = runTypedoc(repoRoot), diff = rea
|
|
|
32129
33965
|
mkdirSync(dirname(file), { recursive: true });
|
|
32130
33966
|
writeFileSync(file, toLcov(packages));
|
|
32131
33967
|
});
|
|
32132
|
-
summarise$
|
|
33968
|
+
summarise$1(ctx, packages);
|
|
32133
33969
|
}
|
|
32134
33970
|
}
|
|
32135
33971
|
};
|
|
@@ -32491,7 +34327,7 @@ function scan(repos, needle) {
|
|
|
32491
34327
|
found: repos.flatMap((repo) => findReferences(repo, needle))
|
|
32492
34328
|
};
|
|
32493
34329
|
}
|
|
32494
|
-
function summarise
|
|
34330
|
+
function summarise(ctx, repos, found, needle, max) {
|
|
32495
34331
|
ctx.say({
|
|
32496
34332
|
status: "heading",
|
|
32497
34333
|
label: `References to ${needle}`
|
|
@@ -32557,7 +34393,7 @@ function ciProbes(org, clone = cloneOrg) {
|
|
|
32557
34393
|
});
|
|
32558
34394
|
return;
|
|
32559
34395
|
}
|
|
32560
|
-
summarise
|
|
34396
|
+
summarise(ctx, result.repos, result.found, needle(result.org), max);
|
|
32561
34397
|
}
|
|
32562
34398
|
},
|
|
32563
34399
|
"ref-list": {
|
|
@@ -35299,510 +37135,56 @@ async function runProjectSetup(input) {
|
|
|
35299
37135
|
if (options.boards.length === 0) {
|
|
35300
37136
|
rows.skip("no boards", "declare them in providers.projects: boards: [{ template, name }]");
|
|
35301
37137
|
return rows.finish(COMMAND);
|
|
35302
|
-
}
|
|
35303
|
-
const loaded = await loadTemplates(options.templatesDir, input.io ?? createFsTemplatesIo(input.context.repoRoot));
|
|
35304
|
-
for (const problem of loaded.problems) rows.fail("template", problem);
|
|
35305
|
-
for (const declared of options.boards) {
|
|
35306
|
-
const label = `board ${declared.name}`;
|
|
35307
|
-
const template = loaded.templates[declared.template];
|
|
35308
|
-
if (!template) {
|
|
35309
|
-
rows.fail(label, `template "${declared.template}" is not a built-in or a file in ${options.templatesDir}`);
|
|
35310
|
-
continue;
|
|
35311
|
-
}
|
|
35312
|
-
try {
|
|
35313
|
-
let board = await projects.find(options.owner, declared.name);
|
|
35314
|
-
let created = false;
|
|
35315
|
-
if (!board) {
|
|
35316
|
-
if (dryRun) {
|
|
35317
|
-
rows.ok(label, `would create from template ${template.name}, then bring it in line`);
|
|
35318
|
-
continue;
|
|
35319
|
-
}
|
|
35320
|
-
board = await projects.create(options.owner, declared.name, template);
|
|
35321
|
-
created = true;
|
|
35322
|
-
rows.ok(label, `created from template ${template.name}: ${board.url}`);
|
|
35323
|
-
}
|
|
35324
|
-
if (!projects.ensure) {
|
|
35325
|
-
rows.skip(label, "the provider cannot compare a board with a template");
|
|
35326
|
-
continue;
|
|
35327
|
-
}
|
|
35328
|
-
if (dryRun) {
|
|
35329
|
-
rows.ok(label, `would bring ${board.url} in line with template ${template.name}`);
|
|
35330
|
-
continue;
|
|
35331
|
-
}
|
|
35332
|
-
const report = await projects.ensure(options.owner, board, template);
|
|
35333
|
-
for (const change of report.changes) rows.ok(`${label}: ${change}`);
|
|
35334
|
-
for (const todo of report.todos) rows.fail(`${label}: ${todo}`, "a person has to do this");
|
|
35335
|
-
if (report.changes.length === 0 && report.todos.length === 0) rows.ok(label, created ? "matches its template" : "already matches its template");
|
|
35336
|
-
} catch (err) {
|
|
35337
|
-
rows.fail(label, errorMessage(err));
|
|
35338
|
-
}
|
|
35339
|
-
}
|
|
35340
|
-
return rows.finish(COMMAND);
|
|
35341
|
-
}
|
|
35342
|
-
// src/commands/project/project-setup/project-setup.command.ts
|
|
35343
|
-
const projectSetupCommand = {
|
|
35344
|
-
command: "project",
|
|
35345
|
-
describe: "Make each board providers.projects declares match its template, creating the ones that are missing",
|
|
35346
|
-
handler: async (argv) => {
|
|
35347
|
-
const tokens = tokenContext(argv.token);
|
|
35348
|
-
if (!tokens) return;
|
|
35349
|
-
const loaded = await loadConfig(argv.cwd);
|
|
35350
|
-
applyResolvedConfig(argv, loaded.resolved);
|
|
35351
|
-
if ((await runProjectSetup({
|
|
35352
|
-
loaded,
|
|
35353
|
-
context: {
|
|
35354
|
-
repoRoot: argv.cwd,
|
|
35355
|
-
dryRun: argv.dryRun,
|
|
35356
|
-
...tokens,
|
|
35357
|
-
org: resolveOrg(argv, loaded.resolved)
|
|
35358
|
-
},
|
|
35359
|
-
owner: argv.org
|
|
35360
|
-
})).status === "fail") process.exitCode = 1;
|
|
35361
|
-
}
|
|
35362
|
-
};
|
|
35363
|
-
// src/commands/setup/setup.args.ts
|
|
35364
|
-
const setupArgs = (y) => y.option("repo", {
|
|
35365
|
-
type: "string",
|
|
35366
|
-
global: false,
|
|
35367
|
-
describe: "Repo coords (\"owner/name\"). Defaults to plugin-specific resolution."
|
|
35368
|
-
}).option("yes", {
|
|
35369
|
-
type: "boolean",
|
|
35370
|
-
global: false,
|
|
35371
|
-
describe: "Change the organization's issue Types without asking (only when the org area declares some)."
|
|
35372
|
-
}).option("hooks", {
|
|
35373
|
-
type: "boolean",
|
|
35374
|
-
global: false,
|
|
35375
|
-
describe: "Install git hooks (.husky/pre-push → holocron run ci). Default: on for protection:'strict'. --no-hooks to skip."
|
|
35376
|
-
});
|
|
35377
|
-
// src/commands/setup/setup.command.ts
|
|
35378
|
-
const setupCommand = {
|
|
35379
|
-
command: "setup",
|
|
35380
|
-
describe: "Apply infra setup actions across every configured capability",
|
|
35381
|
-
builder: (y) => setupArgs(y).command(notificationsSetupCommand).command(projectSetupCommand),
|
|
35382
|
-
handler: async (argv) => {
|
|
35383
|
-
const tokens = tokenContext(argv.token);
|
|
35384
|
-
if (!tokens) return;
|
|
35385
|
-
const loaded = await loadConfig(argv.cwd);
|
|
35386
|
-
applyResolvedConfig(argv, loaded.resolved);
|
|
35387
|
-
if ((await runSetup({
|
|
35388
|
-
loaded,
|
|
35389
|
-
context: {
|
|
35390
|
-
repoRoot: argv.cwd,
|
|
35391
|
-
dryRun: argv.dryRun,
|
|
35392
|
-
...argv.repo ? { repo: argv.repo } : {},
|
|
35393
|
-
...tokens,
|
|
35394
|
-
org: resolveOrg(argv, loaded.resolved)
|
|
35395
|
-
},
|
|
35396
|
-
...argv.hooks !== void 0 ? { hooks: argv.hooks } : {},
|
|
35397
|
-
...argv.yes ? { yes: true } : {}
|
|
35398
|
-
})).summary.fail > 0) process.exitCode = 1;
|
|
35399
|
-
}
|
|
35400
|
-
};
|
|
35401
|
-
// src/commands/config-show/config-show.args.ts
|
|
35402
|
-
const configShowArgs = (y) => y.option("depth", {
|
|
35403
|
-
type: "number",
|
|
35404
|
-
describe: "Collapse objects/arrays nested deeper than N levels (TTY output only)"
|
|
35405
|
-
}).option("interactive", {
|
|
35406
|
-
type: "boolean",
|
|
35407
|
-
describe: "Browse the config in a foldable tree (default on a TTY; --no-interactive for static output)"
|
|
35408
|
-
});
|
|
35409
|
-
// src/commands/config-show/config-show.command.ts
|
|
35410
|
-
const configShowCommand = {
|
|
35411
|
-
command: "config",
|
|
35412
|
-
describe: "Print the resolved holocron config",
|
|
35413
|
-
builder: configShowArgs,
|
|
35414
|
-
handler: async (argv) => {
|
|
35415
|
-
const loaded = await loadConfig(argv.cwd);
|
|
35416
|
-
await viewJson(loaded.resolved, {
|
|
35417
|
-
depth: argv.depth,
|
|
35418
|
-
interactive: argv.interactive
|
|
35419
|
-
});
|
|
35420
|
-
}
|
|
35421
|
-
};
|
|
35422
|
-
// src/commands/show/show.command.ts
|
|
35423
|
-
const showCommand = {
|
|
35424
|
-
command: "show",
|
|
35425
|
-
describe: "Show the resolved holocron config",
|
|
35426
|
-
builder: (y) => y.command(configShowCommand).command(groupMenu("show")),
|
|
35427
|
-
handler: () => {}
|
|
35428
|
-
};
|
|
35429
|
-
// src/commands/start-work/start-work.command.ts
|
|
35430
|
-
const startWorkCommand = {
|
|
35431
|
-
command: "work <issue>",
|
|
35432
|
-
describe: "Start work on an issue: branch, worktree, first commit, push and a draft pull request",
|
|
35433
|
-
builder: (y) => y.positional("issue", {
|
|
35434
|
-
type: "string",
|
|
35435
|
-
demandOption: true,
|
|
35436
|
-
describe: "The issue: #1234, 1234, owner/repo#1234 or the tracker's own key"
|
|
35437
|
-
}).option("name", {
|
|
35438
|
-
type: "string",
|
|
35439
|
-
describe: "The branch and worktree name, kebab-case (default: from the title)"
|
|
35440
|
-
}).option("title", {
|
|
35441
|
-
type: "string",
|
|
35442
|
-
describe: "The pull request's title, a Conventional Commit line (default: made from the issue)"
|
|
35443
|
-
}).option("base", {
|
|
35444
|
-
type: "string",
|
|
35445
|
-
describe: "The branch to start from and merge into (default: repo.defaultBranch)"
|
|
35446
|
-
}).option("worktree", {
|
|
35447
|
-
type: "boolean",
|
|
35448
|
-
default: true,
|
|
35449
|
-
describe: "Make a worktree under .claude/worktrees; --no-worktree only makes the branch and switches to it"
|
|
35450
|
-
}).option("worktree-path", {
|
|
35451
|
-
type: "string",
|
|
35452
|
-
describe: "Where the worktree goes (default: .claude/worktrees/<name>)"
|
|
35453
|
-
}).option("spec", {
|
|
35454
|
-
type: "string",
|
|
35455
|
-
describe: "The work's spec file; it is the first commit, and the pull request carries only the spec"
|
|
35456
|
-
}).option("one-pr", {
|
|
35457
|
-
type: "boolean",
|
|
35458
|
-
describe: "With --spec: one pull request for the spec and the code, titled like the code"
|
|
35459
|
-
}).option("type", {
|
|
35460
|
-
type: "string",
|
|
35461
|
-
describe: "The issue's kind, deciding the commit type: bug, feature, task or a Type the organization declares (default: its title and labels)"
|
|
35462
|
-
}).option("effort", {
|
|
35463
|
-
type: "string",
|
|
35464
|
-
choices: [
|
|
35465
|
-
"high",
|
|
35466
|
-
"medium",
|
|
35467
|
-
"low"
|
|
35468
|
-
],
|
|
35469
|
-
describe: "Set the issue's Effort with its start date"
|
|
35470
|
-
}).option("assignee", {
|
|
35471
|
-
type: "string",
|
|
35472
|
-
array: true,
|
|
35473
|
-
describe: "A login to assign the pull request to, besides the issue's (repeatable)"
|
|
35474
|
-
}).option("project", {
|
|
35475
|
-
type: "string",
|
|
35476
|
-
describe: "Put the pull request on this board, by title"
|
|
35477
|
-
}).option("pr", {
|
|
35478
|
-
type: "boolean",
|
|
35479
|
-
default: true,
|
|
35480
|
-
describe: "Open the pull request; --no-pr stops after the push"
|
|
35481
|
-
}).option("yes", {
|
|
35482
|
-
type: "boolean",
|
|
35483
|
-
describe: "Start without asking (required without a terminal)"
|
|
35484
|
-
}),
|
|
35485
|
-
handler: async (argv) => {
|
|
35486
|
-
const tokens = tokenContext(argv.token);
|
|
35487
|
-
if (!tokens) return;
|
|
35488
|
-
const loaded = await loadConfig(argv.cwd);
|
|
35489
|
-
applyResolvedConfig(argv, loaded.resolved);
|
|
35490
|
-
const problem = kindProblem(argv.type, loaded.resolved.issueTypes);
|
|
35491
|
-
if (problem) {
|
|
35492
|
-
console.error(problem);
|
|
35493
|
-
process.exitCode = 1;
|
|
35494
|
-
return;
|
|
35495
|
-
}
|
|
35496
|
-
if ((await runStartWork({
|
|
35497
|
-
issue: String(argv.issue),
|
|
35498
|
-
loaded,
|
|
35499
|
-
context: {
|
|
35500
|
-
repoRoot: argv.cwd,
|
|
35501
|
-
dryRun: argv.dryRun,
|
|
35502
|
-
...tokens,
|
|
35503
|
-
org: resolveOrg(argv, loaded.resolved)
|
|
35504
|
-
},
|
|
35505
|
-
...argv.name ? { name: argv.name } : {},
|
|
35506
|
-
...argv.title ? { title: argv.title } : {},
|
|
35507
|
-
...argv.base ? { base: argv.base } : {},
|
|
35508
|
-
...argv.worktree === false ? { worktree: false } : {},
|
|
35509
|
-
...argv.worktreePath ? { worktreePath: argv.worktreePath } : {},
|
|
35510
|
-
...argv.spec ? { spec: argv.spec } : {},
|
|
35511
|
-
...argv.onePr ? { onePr: true } : {},
|
|
35512
|
-
...argv.type ? { kind: argv.type.toLowerCase() } : {},
|
|
35513
|
-
...argv.effort ? { effort: argv.effort } : {},
|
|
35514
|
-
...argv.assignee ? { assignees: argv.assignee.map(String) } : {},
|
|
35515
|
-
...argv.project ? { project: argv.project } : {},
|
|
35516
|
-
...argv.pr === false ? { noPr: true } : {},
|
|
35517
|
-
...argv.yes ? { yes: true } : {}
|
|
35518
|
-
})).status === "fail") process.exitCode = 1;
|
|
35519
|
-
}
|
|
35520
|
-
};
|
|
35521
|
-
// src/commands/start/start.command.ts
|
|
35522
|
-
const startCommand = {
|
|
35523
|
-
command: "start",
|
|
35524
|
-
describe: "Start a piece of work: its branch, worktree, first commit and draft pull request",
|
|
35525
|
-
builder: (y) => y.command(startWorkCommand).command(groupMenu("start")),
|
|
35526
|
-
handler: () => {}
|
|
35527
|
-
};
|
|
35528
|
-
// src/commands/ideas-sync/resolve-ideas-provider/resolve-ideas-provider.ts
|
|
35529
|
-
/**
|
|
35530
|
-
* The `ideas` provider `sync ideas` reads through: `providers.ideas` when the config names one. A config written
|
|
35531
|
-
* before the capability has only `ideas.dir` (#2004), so that, or `HOLOCRON_IDEAS_DIR` alone, reads as
|
|
35532
|
-
* `["obsidian", { dir }]`, the way a `HOLOCRON_` variable falls back to the bare name. `providers.ideas` wins over
|
|
35533
|
-
* `ideas.dir`. `undefined` when the config names no place for ideas at all.
|
|
35534
|
-
*/
|
|
35535
|
-
function resolveIdeasProvider(resolved, env) {
|
|
35536
|
-
const own = resolved.providers.ideas;
|
|
35537
|
-
if (own) return own;
|
|
35538
|
-
const dir = resolved.ideas?.dir;
|
|
35539
|
-
if (dir === void 0 && holocronEnv(env).get("IDEAS_DIR") === void 0) return void 0;
|
|
35540
|
-
return {
|
|
35541
|
-
cardinality: "single",
|
|
35542
|
-
tuple: {
|
|
35543
|
-
provider: "obsidian",
|
|
35544
|
-
packageName: resolvePluginPackage("obsidian"),
|
|
35545
|
-
options: dir === void 0 ? {} : { dir }
|
|
35546
|
-
}
|
|
35547
|
-
};
|
|
35548
|
-
}
|
|
35549
|
-
// src/commands/ideas-sync/run-ideas-sync/oldest-issue-key/oldest-issue-key.ts
|
|
35550
|
-
/**
|
|
35551
|
-
* The key of the oldest issue among `keys`, which is the one that wins when overlapping runs filed the same idea.
|
|
35552
|
-
* The `Issue` type carries no creation time, so the order is the key's number (its last run of digits: `#12`, `ENG-7`
|
|
35553
|
-
* and `owner/repo#12` give 12, 7 and 12), which rises with creation in one repository or team; a key with no number
|
|
35554
|
-
* sorts last. Two keys with the same number (different repositories) fall back to a plain string compare so every run
|
|
35555
|
-
* picks the same winner from the same set. Returns `undefined` for an empty list.
|
|
35556
|
-
*/
|
|
35557
|
-
function oldestIssueKey(keys) {
|
|
35558
|
-
const numberOf = (key) => {
|
|
35559
|
-
const digits = /(\d+)\D*$/.exec(key);
|
|
35560
|
-
return digits ? Number(digits[1]) : Number.POSITIVE_INFINITY;
|
|
35561
|
-
};
|
|
35562
|
-
let oldest;
|
|
35563
|
-
for (const key of keys) {
|
|
35564
|
-
if (oldest === void 0) {
|
|
35565
|
-
oldest = key;
|
|
35566
|
-
continue;
|
|
35567
|
-
}
|
|
35568
|
-
const a = numberOf(key);
|
|
35569
|
-
const b = numberOf(oldest);
|
|
35570
|
-
if (a < b || a === b && key < oldest) oldest = key;
|
|
35571
|
-
}
|
|
35572
|
-
return oldest;
|
|
35573
|
-
}
|
|
35574
|
-
// src/commands/ideas-sync/run-ideas-sync/pick-canonical-issue/pick-canonical-issue.ts
|
|
35575
|
-
/**
|
|
35576
|
-
* The issue that stands for an idea among the issues that carry its marker: the oldest open one (by
|
|
35577
|
-
* {@link oldestIssueKey}), or, when every one is closed, the oldest of all, because an issue closed on purpose still
|
|
35578
|
-
* means the idea was filed. A closed duplicate that a search lists first therefore never replaces the open issue.
|
|
35579
|
-
* Returns `undefined` for an empty list.
|
|
35580
|
-
*/
|
|
35581
|
-
function pickCanonicalIssue(hits) {
|
|
35582
|
-
const open = hits.filter((issue) => issue.statusCategory !== "done");
|
|
35583
|
-
const pool = open.length > 0 ? open : hits;
|
|
35584
|
-
const key = oldestIssueKey(pool.map((issue) => issue.key));
|
|
35585
|
-
return pool.find((issue) => issue.key === key);
|
|
35586
|
-
}
|
|
35587
|
-
// src/commands/ideas-sync/run-ideas-sync/converge-created-issue/converge-created-issue.ts
|
|
35588
|
-
/**
|
|
35589
|
-
* Makes the creation of an issue converge when two runs file the same idea at the same time. Both runs searched for
|
|
35590
|
-
* the marker before either created, so both created; each now searches again, and the oldest issue carrying the exact
|
|
35591
|
-
* `marker` (by {@link pickCanonicalIssue}: the oldest open one) is the winner. Both runs see the same issues, so they pick the same winner: the
|
|
35592
|
-
* run whose issue is the oldest keeps it, and the other comments on its own issue and closes it (`transition` to
|
|
35593
|
-
* `done`; the `Issues` capability has no closed-as-duplicate state), then reports the winner's key. Nothing here throws.
|
|
35594
|
-
* When a winner other than `created` is known, its key is always the one returned, so the note points at the canonical
|
|
35595
|
-
* issue even if commenting or closing the duplicate does not go through (then `warning` is set and the detail names
|
|
35596
|
-
* both keys). When the search itself does not go through no winner is known, so `created` is returned with a warning,
|
|
35597
|
-
* because a created issue is never left out of the note.
|
|
35598
|
-
*
|
|
35599
|
-
* @param issues - The tracker; only `search`, `comment` and `transition` are used.
|
|
35600
|
-
* @param marker - The exact hidden marker line of the idea, as written in the issue body.
|
|
35601
|
-
* @param created - The key of the issue this run has just created.
|
|
35602
|
-
*/
|
|
35603
|
-
async function convergeCreatedIssue(issues, marker, created) {
|
|
35604
|
-
let candidates;
|
|
35605
|
-
try {
|
|
35606
|
-
candidates = (await issues.search({
|
|
35607
|
-
text: marker,
|
|
35608
|
-
limit: 100
|
|
35609
|
-
})).filter((issue) => issue.body?.includes(marker) && issue.key !== created);
|
|
35610
|
-
} catch (err) {
|
|
35611
|
-
return {
|
|
35612
|
-
key: created,
|
|
35613
|
-
warning: true,
|
|
35614
|
-
detail: `filed as ${created}; could not check for a duplicate from an overlapping run (${describeError(err)}), so look for another issue with the same marker and close one by hand`
|
|
35615
|
-
};
|
|
35616
|
-
}
|
|
35617
|
-
const winner = pickCanonicalIssue([...candidates, {
|
|
35618
|
-
key: created,
|
|
35619
|
-
statusCategory: "open"
|
|
35620
|
-
}]).key;
|
|
35621
|
-
if (winner === created) return {
|
|
35622
|
-
key: created,
|
|
35623
|
-
warning: false,
|
|
35624
|
-
detail: `filed as ${created}`
|
|
35625
|
-
};
|
|
35626
|
-
try {
|
|
35627
|
-
await issues.comment(created, `Duplicate of ${winner}: the same idea was filed by two overlapping runs.`);
|
|
35628
|
-
await issues.transition(created, "done");
|
|
35629
|
-
} catch (err) {
|
|
35630
|
-
return {
|
|
35631
|
-
key: winner,
|
|
35632
|
-
warning: true,
|
|
35633
|
-
detail: `filed as ${winner}, the older issue for the idea, but the duplicate ${created} could not be closed (${describeError(err)}); close ${created} by hand`
|
|
35634
|
-
};
|
|
35635
|
-
}
|
|
35636
|
-
return {
|
|
35637
|
-
key: winner,
|
|
35638
|
-
warning: false,
|
|
35639
|
-
detail: `filed as ${winner} (closed duplicate ${created} from an overlapping run)`
|
|
35640
|
-
};
|
|
35641
|
-
}
|
|
35642
|
-
// src/commands/ideas-sync/run-ideas-sync/run-ideas-sync.ts
|
|
35643
|
-
/**
|
|
35644
|
-
* `holocron sync ideas` — files the idea notes that are ready.
|
|
35645
|
-
*
|
|
35646
|
-
* It reads every idea through the `ideas` provider (`providers.ideas`, or `ideas.dir` read as an Obsidian vault; the
|
|
35647
|
-
* Obsidian plugin skips folders whose name starts with `_` or `.`). An idea whose status is the filing state (default
|
|
35648
|
-
* `in-progress`) and that has no issue becomes an issue through the repo's `issues` provider, and the issue is then
|
|
35649
|
-
* recorded with `Ideas.markFiled` (for Obsidian, an `issue:` property in the tracker's own syntax), which is what makes
|
|
35650
|
-
* the step run once. An idea with attachments is reported and skipped, since an issue body cannot carry them. Only
|
|
35651
|
-
* ideas to be filed, and ideas that need the person's attention, get a row; the rest are counted. The issue body ends
|
|
35652
|
-
* with a hidden `<!-- holocron:idea <key> -->` line, and an issue that carries it is reused instead of making a second
|
|
35653
|
-
* one (found with one `Issues.search({ text })` per note about to be filed, confirmed by the exact marker in the body;
|
|
35654
|
-
* GitHub searches its 2000 most recently updated issues, so an older one is still missed, and each search uses rate
|
|
35655
|
-
* limit). Two runs that overlap can both miss the marker and both create; each then searches once more after its
|
|
35656
|
-
* create (`convergeCreatedIssue()`), the older issue wins and the other run closes its own with a comment, so both
|
|
35657
|
-
* notes end with one key. It never deletes anything, and an idea it cannot file is a
|
|
35658
|
-
* failing row (the run goes on). It writes, so it asks first unless `--dry-run` or `--yes` (without a terminal it refuses instead).
|
|
35659
|
-
*/
|
|
35660
|
-
/** The state that files a note when the config names none. */
|
|
35661
|
-
const DEFAULT_FILING_STATE = "in-progress";
|
|
35662
|
-
const row$3 = (id, status, detail) => ({
|
|
35663
|
-
id,
|
|
35664
|
-
title: id,
|
|
35665
|
-
status,
|
|
35666
|
-
detail,
|
|
35667
|
-
problems: []
|
|
35668
|
-
});
|
|
35669
|
-
/**
|
|
35670
|
-
* The hidden line that ties an issue to its note. A later run looks for it before it creates an issue, so a note whose
|
|
35671
|
-
* `issue:` could not be written is not filed twice.
|
|
35672
|
-
*/
|
|
35673
|
-
const marker = (key) => `<!-- holocron:idea ${key} -->`;
|
|
35674
|
-
/** The issue's body: the idea's text, the line that traces the issue to its idea, and the hidden marker. */
|
|
35675
|
-
const issueBody = (idea) => `${idea.body.trim()}\n\nFiled from idea: ${idea.title}\n${marker(idea.key)}`;
|
|
35676
|
-
async function runIdeasSync(input) {
|
|
35677
|
-
/* v8 ignore next -- the console is only used outside tests, which inject `print` */
|
|
35678
|
-
const print = input.print ?? ((line) => console.log(line));
|
|
35679
|
-
const dryRun = Boolean(input.context.dryRun);
|
|
35680
|
-
let notReady = 0;
|
|
35681
|
-
const finish = (rows, status) => {
|
|
35682
|
-
printCheckRows(rows, print);
|
|
35683
|
-
const summary = summariseChecks(rows);
|
|
35684
|
-
printCheckSummary(summary, print);
|
|
35685
|
-
if (notReady > 0) print(` ${notReady} note(s) not ready (another status, or already filed), shown in no row`);
|
|
35686
|
-
return {
|
|
35687
|
-
status: status ?? (summary.fail > 0 ? "fail" : "ok"),
|
|
35688
|
-
rows
|
|
35689
|
-
};
|
|
35690
|
-
};
|
|
35691
|
-
print(style.header(`Holocron sync ideas${dryRun ? " (dry-run)" : ""}`));
|
|
35692
|
-
print("");
|
|
35693
|
-
const entry = resolveIdeasProvider(input.loaded.resolved, input.env);
|
|
35694
|
-
if (!entry) return finish([row$3("ideas", "fail", "no `ideas` provider: set `providers.ideas` (`[\"obsidian\", { dir }]`) in holocron.config or HOLOCRON_IDEAS_DIR")]);
|
|
35695
|
-
/* v8 ignore start -- the real loader is only built outside tests, which always inject one */
|
|
35696
|
-
const reader = input.ideasLoader ?? new PluginLoader({
|
|
35697
|
-
...input.loaded.resolved,
|
|
35698
|
-
providers: { ideas: entry }
|
|
35699
|
-
}, input.context);
|
|
35700
|
-
/* v8 ignore stop */
|
|
35701
|
-
await reader.load();
|
|
35702
|
-
assertPluginsResolvable(reader, "sync ideas");
|
|
35703
|
-
if (!reader.has("ideas")) {
|
|
35704
|
-
const failure = reader.loadFailures().find((f) => f.key === "ideas");
|
|
35705
|
-
return finish([row$3("ideas", "fail", `the \`ideas\` provider is not available${failure ? ` (${describeError(failure.error)})` : ""}`)]);
|
|
35706
|
-
}
|
|
35707
|
-
const ideas = reader.get("ideas");
|
|
35708
|
-
let records;
|
|
35709
|
-
try {
|
|
35710
|
-
records = await ideas.list();
|
|
35711
|
-
} catch (err) {
|
|
35712
|
-
return finish([row$3("ideas", "fail", describeError(err))]);
|
|
35713
|
-
}
|
|
35714
|
-
const fileState = input.loaded.resolved.ideas?.states?.file ?? DEFAULT_FILING_STATE;
|
|
35715
|
-
const rows = [];
|
|
35716
|
-
const ready = [];
|
|
35717
|
-
for (const idea of records) if (idea.error !== void 0) rows.push(row$3(idea.key, "fail", idea.error));
|
|
35718
|
-
else if (idea.status !== fileState || idea.issue !== void 0) notReady++;
|
|
35719
|
-
else if (idea.attachments.length > 0) rows.push(row$3(idea.key, "skip", `has embedded files an issue cannot carry (${idea.attachments.join(", ")}); not filed`));
|
|
35720
|
-
else ready.push(idea);
|
|
35721
|
-
if (ready.length === 0) return finish(rows);
|
|
35722
|
-
if (dryRun) {
|
|
35723
|
-
for (const idea of ready) rows.push(row$3(idea.key, "skip", `would file "${idea.title}"`));
|
|
35724
|
-
return finish(rows.sort((a, b) => a.id.localeCompare(b.id)));
|
|
35725
|
-
}
|
|
35726
|
-
if (!input.yes) {
|
|
35727
|
-
if (!(input.interactive ?? Boolean(process.stdin.isTTY))) throw new NonInteractiveError(`\`sync ideas\` creates ${ready.length} issue(s) and edits the notes; pass --yes to run it without asking, or --dry-run to preview`);
|
|
35728
|
-
if (!await (input.confirm ?? ((message) => confirm({
|
|
35729
|
-
message,
|
|
35730
|
-
default: false
|
|
35731
|
-
})))(`File ${ready.length} idea(s) as issues and record the issue in each note?`)) {
|
|
35732
|
-
print(` ${style.skip("cancelled; nothing was changed")}`);
|
|
35733
|
-
return {
|
|
35734
|
-
status: "cancelled",
|
|
35735
|
-
rows: []
|
|
35736
|
-
};
|
|
35737
|
-
}
|
|
35738
|
-
}
|
|
35739
|
-
/* v8 ignore next -- the real loader is only built outside tests, which always inject one */
|
|
35740
|
-
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
35741
|
-
await loader.load();
|
|
35742
|
-
assertPluginsResolvable(loader, "sync ideas");
|
|
35743
|
-
const issues = loader.has("issues") ? loader.get("issues") : void 0;
|
|
35744
|
-
for (const idea of ready) {
|
|
35745
|
-
const path = idea.key;
|
|
35746
|
-
if (!issues) {
|
|
35747
|
-
rows.push(row$3(path, "fail", "the config has no `issues` provider to file it with"));
|
|
35748
|
-
continue;
|
|
35749
|
-
}
|
|
35750
|
-
let existing;
|
|
35751
|
-
try {
|
|
35752
|
-
existing = pickCanonicalIssue((await issues.search({
|
|
35753
|
-
text: marker(path),
|
|
35754
|
-
limit: 100
|
|
35755
|
-
})).filter((issue) => issue.body?.includes(marker(path))));
|
|
35756
|
-
} catch (err) {
|
|
35757
|
-
rows.push(row$3(path, "fail", `could not check for an existing issue, so none was created: ${describeError(err)}`));
|
|
35758
|
-
continue;
|
|
35759
|
-
}
|
|
35760
|
-
let key;
|
|
35761
|
-
let detail = `already filed as ${existing?.key}`;
|
|
35762
|
-
let warning = false;
|
|
35763
|
-
if (existing) key = existing.key;
|
|
35764
|
-
else {
|
|
35765
|
-
let created;
|
|
35766
|
-
try {
|
|
35767
|
-
({key: created} = await issues.create({
|
|
35768
|
-
summary: idea.title,
|
|
35769
|
-
body: issueBody(idea)
|
|
35770
|
-
}));
|
|
35771
|
-
} catch (err) {
|
|
35772
|
-
rows.push(row$3(path, "fail", `could not create the issue: ${describeError(err)}`));
|
|
35773
|
-
continue;
|
|
35774
|
-
}
|
|
35775
|
-
({key, detail, warning} = await convergeCreatedIssue(issues, marker(path), created));
|
|
37138
|
+
}
|
|
37139
|
+
const loaded = await loadTemplates(options.templatesDir, input.io ?? createFsTemplatesIo(input.context.repoRoot));
|
|
37140
|
+
for (const problem of loaded.problems) rows.fail("template", problem);
|
|
37141
|
+
for (const declared of options.boards) {
|
|
37142
|
+
const label = `board ${declared.name}`;
|
|
37143
|
+
const template = loaded.templates[declared.template];
|
|
37144
|
+
if (!template) {
|
|
37145
|
+
rows.fail(label, `template "${declared.template}" is not a built-in or a file in ${options.templatesDir}`);
|
|
37146
|
+
continue;
|
|
35776
37147
|
}
|
|
35777
37148
|
try {
|
|
35778
|
-
await
|
|
35779
|
-
|
|
35780
|
-
|
|
35781
|
-
|
|
35782
|
-
|
|
37149
|
+
let board = await projects.find(options.owner, declared.name);
|
|
37150
|
+
let created = false;
|
|
37151
|
+
if (!board) {
|
|
37152
|
+
if (dryRun) {
|
|
37153
|
+
rows.ok(label, `would create from template ${template.name}, then bring it in line`);
|
|
37154
|
+
continue;
|
|
37155
|
+
}
|
|
37156
|
+
board = await projects.create(options.owner, declared.name, template);
|
|
37157
|
+
created = true;
|
|
37158
|
+
rows.ok(label, `created from template ${template.name}: ${board.url}`);
|
|
37159
|
+
}
|
|
37160
|
+
if (!projects.ensure) {
|
|
37161
|
+
rows.skip(label, "the provider cannot compare a board with a template");
|
|
37162
|
+
continue;
|
|
37163
|
+
}
|
|
37164
|
+
if (dryRun) {
|
|
37165
|
+
rows.ok(label, `would bring ${board.url} in line with template ${template.name}`);
|
|
37166
|
+
continue;
|
|
37167
|
+
}
|
|
37168
|
+
const report = await projects.ensure(options.owner, board, template);
|
|
37169
|
+
for (const change of report.changes) rows.ok(`${label}: ${change}`);
|
|
37170
|
+
for (const todo of report.todos) rows.fail(`${label}: ${todo}`, "a person has to do this");
|
|
37171
|
+
if (report.changes.length === 0 && report.todos.length === 0) rows.ok(label, created ? "matches its template" : "already matches its template");
|
|
35783
37172
|
} catch (err) {
|
|
35784
|
-
rows.
|
|
35785
|
-
...row$3(path, "fail", `issue ${key} was created but \`issue:\` was not written: ${describeError(err)}`),
|
|
35786
|
-
problems: [`add \`issue: ${key}\` to the note by hand`]
|
|
35787
|
-
});
|
|
37173
|
+
rows.fail(label, errorMessage(err));
|
|
35788
37174
|
}
|
|
35789
37175
|
}
|
|
35790
|
-
return
|
|
37176
|
+
return rows.finish(COMMAND);
|
|
35791
37177
|
}
|
|
35792
|
-
// src/commands/
|
|
35793
|
-
const
|
|
35794
|
-
command: "
|
|
35795
|
-
describe: "
|
|
35796
|
-
builder: (y) => y.option("yes", {
|
|
35797
|
-
type: "boolean",
|
|
35798
|
-
describe: "File without asking (required without a terminal)"
|
|
35799
|
-
}),
|
|
37178
|
+
// src/commands/project/project-setup/project-setup.command.ts
|
|
37179
|
+
const projectSetupCommand = {
|
|
37180
|
+
command: "project",
|
|
37181
|
+
describe: "Make each board providers.projects declares match its template, creating the ones that are missing",
|
|
35800
37182
|
handler: async (argv) => {
|
|
35801
37183
|
const tokens = tokenContext(argv.token);
|
|
35802
37184
|
if (!tokens) return;
|
|
35803
37185
|
const loaded = await loadConfig(argv.cwd);
|
|
35804
37186
|
applyResolvedConfig(argv, loaded.resolved);
|
|
35805
|
-
if ((await
|
|
37187
|
+
if ((await runProjectSetup({
|
|
35806
37188
|
loaded,
|
|
35807
37189
|
context: {
|
|
35808
37190
|
repoRoot: argv.cwd,
|
|
@@ -35810,488 +37192,496 @@ const ideasSyncCommand = {
|
|
|
35810
37192
|
...tokens,
|
|
35811
37193
|
org: resolveOrg(argv, loaded.resolved)
|
|
35812
37194
|
},
|
|
35813
|
-
|
|
37195
|
+
owner: argv.org
|
|
35814
37196
|
})).status === "fail") process.exitCode = 1;
|
|
35815
37197
|
}
|
|
35816
37198
|
};
|
|
35817
|
-
// src/commands/
|
|
35818
|
-
const
|
|
37199
|
+
// src/commands/setup/setup.args.ts
|
|
37200
|
+
const setupArgs = (y) => y.option("repo", {
|
|
35819
37201
|
type: "string",
|
|
35820
|
-
|
|
35821
|
-
|
|
37202
|
+
global: false,
|
|
37203
|
+
describe: "Repo coords (\"owner/name\"). Defaults to plugin-specific resolution."
|
|
37204
|
+
}).option("yes", {
|
|
35822
37205
|
type: "boolean",
|
|
35823
|
-
|
|
35824
|
-
describe: "
|
|
37206
|
+
global: false,
|
|
37207
|
+
describe: "Change the organization's issue Types without asking (only when the org area declares some)."
|
|
37208
|
+
}).option("hooks", {
|
|
37209
|
+
type: "boolean",
|
|
37210
|
+
global: false,
|
|
37211
|
+
describe: "Install git hooks (.husky/pre-push → holocron run ci). Default: on for protection:'strict'. --no-hooks to skip."
|
|
35825
37212
|
});
|
|
35826
|
-
// src/commands/
|
|
35827
|
-
const
|
|
35828
|
-
command: "
|
|
35829
|
-
describe: "
|
|
35830
|
-
builder:
|
|
37213
|
+
// src/commands/setup/setup.command.ts
|
|
37214
|
+
const setupCommand = {
|
|
37215
|
+
command: "setup",
|
|
37216
|
+
describe: "Apply infra setup actions across every configured capability",
|
|
37217
|
+
builder: (y) => setupArgs(y).command(notificationsSetupCommand).command(projectSetupCommand),
|
|
35831
37218
|
handler: async (argv) => {
|
|
35832
37219
|
const tokens = tokenContext(argv.token);
|
|
35833
37220
|
if (!tokens) return;
|
|
35834
37221
|
const loaded = await loadConfig(argv.cwd);
|
|
35835
37222
|
applyResolvedConfig(argv, loaded.resolved);
|
|
35836
|
-
if ((await
|
|
37223
|
+
if ((await runSetup({
|
|
35837
37224
|
loaded,
|
|
35838
37225
|
context: {
|
|
35839
37226
|
repoRoot: argv.cwd,
|
|
35840
37227
|
dryRun: argv.dryRun,
|
|
37228
|
+
...argv.repo ? { repo: argv.repo } : {},
|
|
35841
37229
|
...tokens,
|
|
35842
37230
|
org: resolveOrg(argv, loaded.resolved)
|
|
35843
37231
|
},
|
|
35844
|
-
...argv.
|
|
35845
|
-
|
|
37232
|
+
...argv.hooks !== void 0 ? { hooks: argv.hooks } : {},
|
|
37233
|
+
...argv.yes ? { yes: true } : {}
|
|
37234
|
+
})).summary.fail > 0) process.exitCode = 1;
|
|
37235
|
+
}
|
|
37236
|
+
};
|
|
37237
|
+
// src/commands/config-show/config-show.args.ts
|
|
37238
|
+
const configShowArgs = (y) => y.option("depth", {
|
|
37239
|
+
type: "number",
|
|
37240
|
+
describe: "Collapse objects/arrays nested deeper than N levels (TTY output only)"
|
|
37241
|
+
}).option("interactive", {
|
|
37242
|
+
type: "boolean",
|
|
37243
|
+
describe: "Browse the config in a foldable tree (default on a TTY; --no-interactive for static output)"
|
|
37244
|
+
});
|
|
37245
|
+
// src/commands/config-show/config-show.command.ts
|
|
37246
|
+
const configShowCommand = {
|
|
37247
|
+
command: "config",
|
|
37248
|
+
describe: "Print the resolved holocron config",
|
|
37249
|
+
builder: configShowArgs,
|
|
37250
|
+
handler: async (argv) => {
|
|
37251
|
+
const loaded = await loadConfig(argv.cwd);
|
|
37252
|
+
await viewJson(loaded.resolved, {
|
|
37253
|
+
depth: argv.depth,
|
|
37254
|
+
interactive: argv.interactive
|
|
37255
|
+
});
|
|
37256
|
+
}
|
|
37257
|
+
};
|
|
37258
|
+
// src/commands/show/show.command.ts
|
|
37259
|
+
const showCommand = {
|
|
37260
|
+
command: "show",
|
|
37261
|
+
describe: "Show the resolved holocron config",
|
|
37262
|
+
builder: (y) => y.command(configShowCommand).command(groupMenu("show")),
|
|
37263
|
+
handler: () => {}
|
|
37264
|
+
};
|
|
37265
|
+
// src/commands/start-work/start-work.command.ts
|
|
37266
|
+
const startWorkCommand = {
|
|
37267
|
+
command: "work <issue>",
|
|
37268
|
+
describe: "Start work on an issue: branch, worktree, first commit, push and a draft pull request",
|
|
37269
|
+
builder: (y) => y.positional("issue", {
|
|
37270
|
+
type: "string",
|
|
37271
|
+
demandOption: true,
|
|
37272
|
+
describe: "The issue: #1234, 1234, owner/repo#1234 or the tracker's own key"
|
|
37273
|
+
}).option("name", {
|
|
37274
|
+
type: "string",
|
|
37275
|
+
describe: "The branch and worktree name, kebab-case (default: from the title)"
|
|
37276
|
+
}).option("title", {
|
|
37277
|
+
type: "string",
|
|
37278
|
+
describe: "The pull request's title, a Conventional Commit line (default: made from the issue)"
|
|
37279
|
+
}).option("base", {
|
|
37280
|
+
type: "string",
|
|
37281
|
+
describe: "The branch to start from and merge into (default: repo.defaultBranch)"
|
|
37282
|
+
}).option("worktree", {
|
|
37283
|
+
type: "boolean",
|
|
37284
|
+
default: true,
|
|
37285
|
+
describe: "Make a worktree under .claude/worktrees; --no-worktree only makes the branch and switches to it"
|
|
37286
|
+
}).option("worktree-path", {
|
|
37287
|
+
type: "string",
|
|
37288
|
+
describe: "Where the worktree goes (default: .claude/worktrees/<name>)"
|
|
37289
|
+
}).option("spec", {
|
|
37290
|
+
type: "string",
|
|
37291
|
+
describe: "The work's spec file; it is the first commit, and the pull request carries only the spec"
|
|
37292
|
+
}).option("one-pr", {
|
|
37293
|
+
type: "boolean",
|
|
37294
|
+
describe: "With --spec: one pull request for the spec and the code, titled like the code"
|
|
37295
|
+
}).option("type", {
|
|
37296
|
+
type: "string",
|
|
37297
|
+
describe: "The issue's kind, deciding the commit type: bug, feature, task or a Type the organization declares (default: its title and labels)"
|
|
37298
|
+
}).option("effort", {
|
|
37299
|
+
type: "string",
|
|
37300
|
+
choices: [
|
|
37301
|
+
"high",
|
|
37302
|
+
"medium",
|
|
37303
|
+
"low"
|
|
37304
|
+
],
|
|
37305
|
+
describe: "Set the issue's Effort with its start date"
|
|
37306
|
+
}).option("assignee", {
|
|
37307
|
+
type: "string",
|
|
37308
|
+
array: true,
|
|
37309
|
+
describe: "A login to assign the pull request to, besides the issue's (repeatable)"
|
|
37310
|
+
}).option("project", {
|
|
37311
|
+
type: "string",
|
|
37312
|
+
describe: "Put the pull request on this board, by title"
|
|
37313
|
+
}).option("pr", {
|
|
37314
|
+
type: "boolean",
|
|
37315
|
+
default: true,
|
|
37316
|
+
describe: "Open the pull request; --no-pr stops after the push"
|
|
37317
|
+
}).option("yes", {
|
|
37318
|
+
type: "boolean",
|
|
37319
|
+
describe: "Start without asking (required without a terminal)"
|
|
37320
|
+
}),
|
|
37321
|
+
handler: async (argv) => {
|
|
37322
|
+
const tokens = tokenContext(argv.token);
|
|
37323
|
+
if (!tokens) return;
|
|
37324
|
+
const loaded = await loadConfig(argv.cwd);
|
|
37325
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
37326
|
+
const problem = kindProblem(argv.type, loaded.resolved.issueTypes);
|
|
37327
|
+
if (problem) {
|
|
37328
|
+
console.error(problem);
|
|
37329
|
+
process.exitCode = 1;
|
|
37330
|
+
return;
|
|
37331
|
+
}
|
|
37332
|
+
if ((await runStartWork({
|
|
37333
|
+
issue: String(argv.issue),
|
|
37334
|
+
loaded,
|
|
37335
|
+
context: {
|
|
37336
|
+
repoRoot: argv.cwd,
|
|
37337
|
+
dryRun: argv.dryRun,
|
|
37338
|
+
...tokens,
|
|
37339
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
37340
|
+
},
|
|
37341
|
+
...argv.name ? { name: argv.name } : {},
|
|
37342
|
+
...argv.title ? { title: argv.title } : {},
|
|
37343
|
+
...argv.base ? { base: argv.base } : {},
|
|
37344
|
+
...argv.worktree === false ? { worktree: false } : {},
|
|
37345
|
+
...argv.worktreePath ? { worktreePath: argv.worktreePath } : {},
|
|
37346
|
+
...argv.spec ? { spec: argv.spec } : {},
|
|
37347
|
+
...argv.onePr ? { onePr: true } : {},
|
|
37348
|
+
...argv.type ? { kind: argv.type.toLowerCase() } : {},
|
|
37349
|
+
...argv.effort ? { effort: argv.effort } : {},
|
|
37350
|
+
...argv.assignee ? { assignees: argv.assignee.map(String) } : {},
|
|
37351
|
+
...argv.project ? { project: argv.project } : {},
|
|
37352
|
+
...argv.pr === false ? { noPr: true } : {},
|
|
37353
|
+
...argv.yes ? { yes: true } : {}
|
|
35846
37354
|
})).status === "fail") process.exitCode = 1;
|
|
35847
37355
|
}
|
|
35848
37356
|
};
|
|
35849
|
-
// src/commands/
|
|
35850
|
-
|
|
35851
|
-
|
|
35852
|
-
|
|
35853
|
-
|
|
35854
|
-
|
|
35855
|
-
|
|
35856
|
-
|
|
35857
|
-
* @param environmentId - The vault environment being synced.
|
|
35858
|
-
* @throws When an entry's `scope` is not `repo`, `env=<name>` or `org=<name>`.
|
|
35859
|
-
*/
|
|
35860
|
-
function secretRoutes(entries, environmentId) {
|
|
35861
|
-
return (entries ?? []).filter((entry) => entry.environment === environmentId).map((entry) => {
|
|
35862
|
-
const scope = parseScope(entry.scope ?? "repo");
|
|
35863
|
-
return {
|
|
35864
|
-
scope: scope.kind === "organization" && entry.repos ? {
|
|
35865
|
-
...scope,
|
|
35866
|
-
visibility: "selected",
|
|
35867
|
-
repos: entry.repos.map(repoName)
|
|
35868
|
-
} : scope,
|
|
35869
|
-
...entry.keys ? { keys: entry.keys } : {}
|
|
35870
|
-
};
|
|
35871
|
-
});
|
|
35872
|
-
}
|
|
35873
|
-
// src/commands/secrets-sync/github-name/github-name.ts
|
|
35874
|
-
/**
|
|
35875
|
-
* Why GitHub would refuse `name` as an Actions secret or variable name, or `undefined` when it would accept it.
|
|
35876
|
-
*
|
|
35877
|
-
* GitHub's rules (the same for repository, environment and organization secrets and variables): letters, digits and
|
|
35878
|
-
* underscores only, no spaces, not starting with a digit, and not starting with `GITHUB_` (reserved, in any case).
|
|
35879
|
-
* A name that breaks one gets a bare 422 from the API, which no retry can fix, so the sync checks first.
|
|
35880
|
-
*
|
|
35881
|
-
* @param name - The secret or variable name.
|
|
35882
|
-
*/
|
|
35883
|
-
function githubNameProblem(name) {
|
|
35884
|
-
if (name === "") return "GitHub names cannot be empty";
|
|
35885
|
-
if (!/^[A-Za-z0-9_]+$/.test(name)) return "GitHub names may only contain letters, digits and underscores";
|
|
35886
|
-
if (/^[0-9]/.test(name)) return "GitHub names cannot start with a number";
|
|
35887
|
-
if (/^GITHUB_/i.test(name)) return "GitHub reserves names starting with GITHUB_";
|
|
35888
|
-
}
|
|
35889
|
-
// src/commands/secrets-sync/restore-pem/restore-pem.ts
|
|
35890
|
-
/** A PEM block written on one line: the begin marker, the body, the end marker, with spaces between them. */
|
|
35891
|
-
const COLLAPSED = /^(-----BEGIN [A-Z0-9 ]+-----) ([\s\S]+?) (-----END [A-Z0-9 ]+-----)$/;
|
|
35892
|
-
/** Base64 lines in a PEM are 64 characters wide. */
|
|
35893
|
-
const LINE_WIDTH = 64;
|
|
37357
|
+
// src/commands/start/start.command.ts
|
|
37358
|
+
const startCommand = {
|
|
37359
|
+
command: "start",
|
|
37360
|
+
describe: "Start a piece of work: its branch, worktree, first commit and draft pull request",
|
|
37361
|
+
builder: (y) => y.command(startWorkCommand).command(groupMenu("start")),
|
|
37362
|
+
handler: () => {}
|
|
37363
|
+
};
|
|
37364
|
+
// src/commands/ideas-sync/resolve-ideas-provider/resolve-ideas-provider.ts
|
|
35894
37365
|
/**
|
|
35895
|
-
*
|
|
35896
|
-
*
|
|
35897
|
-
*
|
|
35898
|
-
*
|
|
35899
|
-
*
|
|
35900
|
-
* Anything else is returned as it came: a PEM already on its lines, a value that is not a PEM, a block whose end marker
|
|
35901
|
-
* does not match its begin marker, and a legacy encrypted key (its body holds `Proc-Type:` header fields, whose own
|
|
35902
|
-
* line breaks cannot be rebuilt). Running it twice gives the same result as running it once.
|
|
37366
|
+
* The `ideas` provider `sync ideas` reads through: `providers.ideas` when the config names one. A config written
|
|
37367
|
+
* before the capability has only `ideas.dir` (#2004), so that, or `HOLOCRON_IDEAS_DIR` alone, reads as
|
|
37368
|
+
* `["obsidian", { dir }]`, the way a `HOLOCRON_` variable falls back to the bare name. `providers.ideas` wins over
|
|
37369
|
+
* `ideas.dir`. `undefined` when the config names no place for ideas at all.
|
|
35903
37370
|
*/
|
|
35904
|
-
function
|
|
35905
|
-
const
|
|
35906
|
-
if (
|
|
35907
|
-
const
|
|
35908
|
-
if (
|
|
35909
|
-
|
|
35910
|
-
|
|
37371
|
+
function resolveIdeasProvider(resolved, env) {
|
|
37372
|
+
const own = resolved.providers.ideas;
|
|
37373
|
+
if (own) return own;
|
|
37374
|
+
const dir = resolved.ideas?.dir;
|
|
37375
|
+
if (dir === void 0 && holocronEnv(env).get("IDEAS_DIR") === void 0) return void 0;
|
|
37376
|
+
return {
|
|
37377
|
+
cardinality: "single",
|
|
37378
|
+
tuple: {
|
|
37379
|
+
provider: "obsidian",
|
|
37380
|
+
packageName: resolvePluginPackage("obsidian"),
|
|
37381
|
+
options: dir === void 0 ? {} : { dir }
|
|
37382
|
+
}
|
|
37383
|
+
};
|
|
35911
37384
|
}
|
|
35912
|
-
// src/commands/
|
|
35913
|
-
/**
|
|
35914
|
-
* `holocron sync secrets` — vault → destinations.
|
|
35915
|
-
*
|
|
35916
|
-
* Reads a named environment from the configured `vault` (1P
|
|
35917
|
-
* Environment / similar) as KEY=VALUE pairs, then fans those values
|
|
35918
|
-
* out to the configured destinations:
|
|
35919
|
-
*
|
|
35920
|
-
* - `secrets` capability (e.g., GH Actions secrets) — repo-scope
|
|
35921
|
-
* - `deployment` capability (e.g., Vercel env vars) — per-target
|
|
35922
|
-
* - local `.env` file (optional, planned for v5.1 — currently skipped
|
|
35923
|
-
* with a soft "not yet" note)
|
|
35924
|
-
*
|
|
35925
|
-
* Per-secret routing rules:
|
|
35926
|
-
*
|
|
35927
|
-
* - `deployment` (for each target the caller asks for, defaults: production + preview) and a Worker's secrets fail
|
|
35928
|
-
* closed (#2061): they receive only the keys `repo.secrets.deploy` names for this environment (an exact `keys`
|
|
35929
|
-
* list and/or a `prefix`), passed in as `deployFilter`. With none, the run throws a `ConfigError` before it reads
|
|
35930
|
-
* the vault. A name outside the filter is reported by name only and never reaches the provider.
|
|
35931
|
-
* - `secrets` (GH Actions) fails closed too (#2104): with no `repo.secrets.sync` entry for the environment, no
|
|
35932
|
-
* `--github-secret` (`--github-secret-scope` alone names no keys and is refused) and no deployment or Worker destination, the run throws a
|
|
35933
|
-
* `ConfigError` before the vault is read, `--dry-run` included. A deployment or Worker sync alone writes nothing
|
|
35934
|
-
* to `secrets`. Where a destination is named, `secrets` defaults to every key, repo-scoped — and a
|
|
35935
|
-
* caller can pass `githubSecretKeys` (an allowlist, from repeatable
|
|
35936
|
-
* `--github-secret KEY` CLI values) to restrict `secrets` to only
|
|
35937
|
-
* those keys, and `githubSecretScope` (same `{ kind }` shape `secret
|
|
35938
|
-
* set`'s own `--scope repo|env=NAME|org=NAME` parses to) to apply one
|
|
35939
|
-
* scope to all of them. A key not in the allowlist is skipped for
|
|
35940
|
-
* `secrets` entirely — still synced to `deployment` if configured.
|
|
35941
|
-
* Needed for a vault holding a mix of deploy-only secrets and one
|
|
35942
|
-
* CI-consumed, org-wide secret (holocron#781's Sentinel case: 4
|
|
35943
|
-
* Vercel-only keys + one org-scoped Axiom ingest token that
|
|
35944
|
-
* a workflow in `theholocron/.github` also read).
|
|
35945
|
-
* - With no `--github-secret`, the routes come from `repo.secrets.sync`: every
|
|
35946
|
-
* entry for this environment gives `secrets` its own keys and scope, one
|
|
35947
|
-
* step per scope, so one environment can fill organization and repository
|
|
35948
|
-
* secrets in one run.
|
|
35949
|
-
* - `repo.variables.sync` entries for this environment give Actions variables: each key goes through the `source`
|
|
35950
|
-
* provider's `syncVariables` (repo scope) or `syncOrgVariables`, one call per key, without pruning. An
|
|
35951
|
-
* environment with only variable entries pushes nothing to `secrets` or `deployment`.
|
|
35952
|
-
* - A key that is blank in the vault is skipped in every destination, and a
|
|
35953
|
-
* listed key the vault does not hold is a skipped row.
|
|
35954
|
-
*
|
|
35955
|
-
* The vault MUST implement `readEnvironment(envId)` (optional method).
|
|
35956
|
-
* If it doesn't, the command errors with a hint to populate the keys
|
|
35957
|
-
* individually via `holocron new secret` (also planned for v5.1).
|
|
35958
|
-
*/
|
|
37385
|
+
// src/commands/ideas-sync/run-ideas-sync/oldest-issue-key/oldest-issue-key.ts
|
|
35959
37386
|
/**
|
|
35960
|
-
* The `
|
|
35961
|
-
* `
|
|
35962
|
-
|
|
35963
|
-
|
|
35964
|
-
|
|
35965
|
-
|
|
35966
|
-
|
|
35967
|
-
|
|
35968
|
-
|
|
35969
|
-
|
|
35970
|
-
|
|
35971
|
-
|
|
35972
|
-
|
|
35973
|
-
|
|
35974
|
-
|
|
35975
|
-
|
|
35976
|
-
repoRoot: input.context.repoRoot,
|
|
35977
|
-
...input.gitExec ? { gitExec: input.gitExec } : {}
|
|
35978
|
-
});
|
|
35979
|
-
const print = input.print ?? ((line) => console.log(line));
|
|
35980
|
-
const logger = input.logger ?? getLogger();
|
|
35981
|
-
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
35982
|
-
await withSpinner("Loading plugins…", () => loader.load());
|
|
35983
|
-
assertPluginsResolvable(loader, "sync secrets");
|
|
35984
|
-
logger.info({
|
|
35985
|
-
environment: input.environmentId,
|
|
35986
|
-
dryRun: (input.context.dryRun ?? false) || void 0
|
|
35987
|
-
}, "sync secrets: start");
|
|
35988
|
-
const dryRun = input.context.dryRun ?? false;
|
|
35989
|
-
const variablesOnly = (input.variableRoutes?.length ?? 0) > 0 && input.secretRoutes?.length === 0 && !input.projectId;
|
|
35990
|
-
if ((loader.has("deployment") && !variablesOnly && Boolean(input.projectId) || input.workerScript) && !input.deployFilter) throw new ConfigError$1(`no \`repo.secrets.deploy\` entry for environment ${JSON.stringify(input.environmentId)}: a deployment or a Worker receives only the keys named by \`keys\` or \`prefix\`, never every key. Add { environment: ${JSON.stringify(input.environmentId)}, prefix: "<PREFIX>_" } (or keys: [...]) to repo.secrets.deploy`);
|
|
35991
|
-
const namesSecretsDestination = input.secretRoutes !== void 0 || Boolean(input.githubSecretKeys?.length);
|
|
35992
|
-
if (!namesSecretsDestination && input.githubSecretScope !== void 0) throw new ConfigError$1(`--github-secret-scope names a scope but no keys: pass the keys to write with --github-secret <KEY>, or declare environment ${JSON.stringify(input.environmentId)} in \`repo.secrets.sync\``);
|
|
35993
|
-
if (!namesSecretsDestination && !input.projectId && !input.workerScript) throw new ConfigError$1(noSecretsEntryMessage(input.environmentId, input.loaded.resolved.repo?.secrets?.sync ?? []));
|
|
35994
|
-
for (const route of input.secretRoutes ?? [{ scope: input.githubSecretScope ?? { kind: "repo" } }]) if (route.scope.kind === "organization" && !route.scope.repos?.length) throw new ConfigError$1(`organization secrets (org=${route.scope.name}) need an explicit reader list: declare them in \`repo.secrets.sync\` with \`repos: [...]\` (visibility "selected"), never "all"`);
|
|
35995
|
-
const targets = input.targets ?? ["production", "preview"];
|
|
35996
|
-
print(style.header(`Holocron sync secrets — environment ${input.environmentId}${dryRun ? " (dry-run)" : ""}`));
|
|
35997
|
-
print(style.dim(` vault: ${vaultProviderName(loader)}`));
|
|
35998
|
-
print("");
|
|
35999
|
-
const vault = loader.get("vault");
|
|
36000
|
-
if (!vault.readEnvironment) throw new Error(`vault provider (${vault.providerName}) does not implement readEnvironment — sync needs bulk env reads`);
|
|
36001
|
-
let envVars;
|
|
36002
|
-
try {
|
|
36003
|
-
envVars = await withSpinner(`Reading vault environment ${input.environmentId}…`, () => vault.readEnvironment(input.environmentId));
|
|
36004
|
-
} catch (err) {
|
|
36005
|
-
const message = describeError(err);
|
|
36006
|
-
print(` ${style.fail(`could not read vault environment ${input.environmentId}: ${message}`)}`);
|
|
36007
|
-
logger.warn({
|
|
36008
|
-
environment: input.environmentId,
|
|
36009
|
-
reason: logReason(err)
|
|
36010
|
-
}, "sync secrets: vault read failed");
|
|
36011
|
-
return summarise([{
|
|
36012
|
-
destination: `vault:${vault.providerName}`,
|
|
36013
|
-
scope: `environment=${input.environmentId}`,
|
|
36014
|
-
key: "(all)",
|
|
36015
|
-
status: "fail",
|
|
36016
|
-
message
|
|
36017
|
-
}], logger, print, dryRun);
|
|
36018
|
-
}
|
|
36019
|
-
const keys = Object.keys(envVars).sort();
|
|
36020
|
-
print(style.step(`read ${keys.length} keys from vault`));
|
|
36021
|
-
print("");
|
|
36022
|
-
const deploySplit = input.deployFilter ? splitDeployKeys(keys, input.deployFilter) : void 0;
|
|
36023
|
-
const rows = [];
|
|
36024
|
-
if (loader.has("secrets")) {
|
|
36025
|
-
const secrets = loader.get("secrets");
|
|
36026
|
-
const routes = input.secretRoutes ?? (input.githubSecretKeys?.length ? [{
|
|
36027
|
-
scope: input.githubSecretScope ?? { kind: "repo" },
|
|
36028
|
-
keys: input.githubSecretKeys
|
|
36029
|
-
}] : []);
|
|
36030
|
-
for (const route of routes) {
|
|
36031
|
-
print(style.step(routes.length > 1 ? `secrets (${scopeLabel(route.scope)})` : "secrets"));
|
|
36032
|
-
const access = await readAccess(secrets, route.scope, print);
|
|
36033
|
-
for (const key of route.keys ?? keys) {
|
|
36034
|
-
const row = await pushRow(`secrets:${secrets.providerName}`, scopeLabel(route.scope), key, envVars, dryRun, async (value) => {
|
|
36035
|
-
await secrets.setSecret(route.scope, key, value);
|
|
36036
|
-
}, nameCheck(secrets.providerName));
|
|
36037
|
-
if (access && (row.status === "ok" || row.status === "dry-run")) row.message = accessNote({
|
|
36038
|
-
visibility: "selected",
|
|
36039
|
-
repos: access.wanted
|
|
36040
|
-
}, access.current?.get(key.toUpperCase()), access.current !== void 0);
|
|
36041
|
-
rows.push(row);
|
|
36042
|
-
print(formatRow(row));
|
|
36043
|
-
}
|
|
36044
|
-
}
|
|
36045
|
-
}
|
|
36046
|
-
const variableRoutes = input.variableRoutes ?? [];
|
|
36047
|
-
if (variableRoutes.length > 0) {
|
|
36048
|
-
const source = loader.has("source") ? loader.get("source") : void 0;
|
|
36049
|
-
for (const route of variableRoutes) {
|
|
36050
|
-
const scope = scopeLabel(route.scope);
|
|
36051
|
-
print(style.step(`variables (${scope})`));
|
|
36052
|
-
const destination = `variables:${source?.providerName ?? "source"}`;
|
|
36053
|
-
const org = route.scope.kind === "organization" ? route.scope.name : void 0;
|
|
36054
|
-
const unsupported = !source ? "needs a `source` provider in holocron.config.ts" : org === void 0 && !source.syncVariables ? `source provider (${source.providerName}) does not implement syncVariables` : org !== void 0 && !source.syncOrgVariables ? `source provider (${source.providerName}) does not implement syncOrgVariables` : void 0;
|
|
36055
|
-
if (unsupported) {
|
|
36056
|
-
const row = {
|
|
36057
|
-
destination,
|
|
36058
|
-
scope,
|
|
36059
|
-
key: "(all)",
|
|
36060
|
-
status: "fail",
|
|
36061
|
-
message: unsupported
|
|
36062
|
-
};
|
|
36063
|
-
rows.push(row);
|
|
36064
|
-
print(formatRow(row));
|
|
36065
|
-
continue;
|
|
36066
|
-
}
|
|
36067
|
-
for (const key of route.keys) {
|
|
36068
|
-
rows.push(await pushRow(destination, scope, key, envVars, dryRun, async (value) => {
|
|
36069
|
-
if (org === void 0) await source.syncVariables({ [key]: value }, { prune: false });
|
|
36070
|
-
else await source.syncOrgVariables(org, { [key]: {
|
|
36071
|
-
value,
|
|
36072
|
-
visibility: route.visibility ?? "all"
|
|
36073
|
-
} }, { prune: false });
|
|
36074
|
-
}, nameCheck(source.providerName)));
|
|
36075
|
-
print(formatRow(rows[rows.length - 1]));
|
|
36076
|
-
}
|
|
36077
|
-
}
|
|
36078
|
-
}
|
|
36079
|
-
if (loader.has("deployment") && !variablesOnly) {
|
|
36080
|
-
const deploy = loader.get("deployment");
|
|
36081
|
-
if (!input.projectId) {
|
|
36082
|
-
print(style.step("deployment"));
|
|
36083
|
-
const row = {
|
|
36084
|
-
destination: `deployment:${deploy.providerName}`,
|
|
36085
|
-
scope: "no projectId",
|
|
36086
|
-
key: "(all)",
|
|
36087
|
-
status: "skip",
|
|
36088
|
-
message: "projectId required for deployment env-var sync (pass --project-id)"
|
|
36089
|
-
};
|
|
36090
|
-
rows.push(row);
|
|
36091
|
-
print(formatRow(row));
|
|
36092
|
-
} else for (const target of targets) {
|
|
36093
|
-
print(style.step(`deployment (target=${target})`));
|
|
36094
|
-
const destination = `deployment:${deploy.providerName}`;
|
|
36095
|
-
reportFiltered(destination, `target=${target}`, deploySplit.filtered, input.deployFilter, rows, print);
|
|
36096
|
-
for (const key of deploySplit.send) {
|
|
36097
|
-
rows.push(await pushRow(destination, `target=${target}`, key, envVars, dryRun, async (value) => {
|
|
36098
|
-
await deploy.setEnvVar(input.projectId, target, key, value);
|
|
36099
|
-
}));
|
|
36100
|
-
print(formatRow(rows[rows.length - 1]));
|
|
36101
|
-
}
|
|
36102
|
-
}
|
|
36103
|
-
}
|
|
36104
|
-
if (input.workerScript) {
|
|
36105
|
-
const script = input.workerScript;
|
|
36106
|
-
print(style.step(`workers (script=${script})`));
|
|
36107
|
-
const workers = loader.has("workers") ? loader.get("workers") : void 0;
|
|
36108
|
-
if (!workers?.setSecret) {
|
|
36109
|
-
const row = {
|
|
36110
|
-
destination: "workers",
|
|
36111
|
-
scope: `script=${script}`,
|
|
36112
|
-
key: "(all)",
|
|
36113
|
-
status: "fail",
|
|
36114
|
-
message: workers ? `workers provider (${workers.providerName}) cannot set secrets` : workersMissing(loader)
|
|
36115
|
-
};
|
|
36116
|
-
rows.push(row);
|
|
36117
|
-
print(formatRow(row));
|
|
36118
|
-
} else {
|
|
36119
|
-
reportFiltered(`workers:${workers.providerName}`, `script=${script}`, deploySplit.filtered, input.deployFilter, rows, print);
|
|
36120
|
-
for (const key of deploySplit.send) {
|
|
36121
|
-
rows.push(await pushRow(`workers:${workers.providerName}`, `script=${script}`, key, envVars, dryRun, async (value) => {
|
|
36122
|
-
await workers.setSecret(script, key, value);
|
|
36123
|
-
}));
|
|
36124
|
-
print(formatRow(rows[rows.length - 1]));
|
|
36125
|
-
}
|
|
37387
|
+
* The key of the oldest issue among `keys`, which is the one that wins when overlapping runs filed the same idea.
|
|
37388
|
+
* The `Issue` type carries no creation time, so the order is the key's number (its last run of digits: `#12`, `ENG-7`
|
|
37389
|
+
* and `owner/repo#12` give 12, 7 and 12), which rises with creation in one repository or team; a key with no number
|
|
37390
|
+
* sorts last. Two keys with the same number (different repositories) fall back to a plain string compare so every run
|
|
37391
|
+
* picks the same winner from the same set. Returns `undefined` for an empty list.
|
|
37392
|
+
*/
|
|
37393
|
+
function oldestIssueKey(keys) {
|
|
37394
|
+
const numberOf = (key) => {
|
|
37395
|
+
const digits = /(\d+)\D*$/.exec(key);
|
|
37396
|
+
return digits ? Number(digits[1]) : Number.POSITIVE_INFINITY;
|
|
37397
|
+
};
|
|
37398
|
+
let oldest;
|
|
37399
|
+
for (const key of keys) {
|
|
37400
|
+
if (oldest === void 0) {
|
|
37401
|
+
oldest = key;
|
|
37402
|
+
continue;
|
|
36126
37403
|
}
|
|
37404
|
+
const a = numberOf(key);
|
|
37405
|
+
const b = numberOf(oldest);
|
|
37406
|
+
if (a < b || a === b && key < oldest) oldest = key;
|
|
36127
37407
|
}
|
|
36128
|
-
return
|
|
37408
|
+
return oldest;
|
|
36129
37409
|
}
|
|
37410
|
+
// src/commands/ideas-sync/run-ideas-sync/pick-canonical-issue/pick-canonical-issue.ts
|
|
36130
37411
|
/**
|
|
36131
|
-
*
|
|
36132
|
-
*
|
|
37412
|
+
* The issue that stands for an idea among the issues that carry its marker: the oldest open one (by
|
|
37413
|
+
* {@link oldestIssueKey}), or, when every one is closed, the oldest of all, because an issue closed on purpose still
|
|
37414
|
+
* means the idea was filed. A closed duplicate that a search lists first therefore never replaces the open issue.
|
|
37415
|
+
* Returns `undefined` for an empty list.
|
|
36133
37416
|
*/
|
|
36134
|
-
function
|
|
36135
|
-
const
|
|
36136
|
-
|
|
36137
|
-
|
|
36138
|
-
|
|
36139
|
-
key,
|
|
36140
|
-
status: "skip",
|
|
36141
|
-
message: `filtered: not in repo.secrets.deploy (${allowed})`
|
|
36142
|
-
});
|
|
36143
|
-
if (filtered.length > 0) print(style.dim(` · not sent (${filtered.length}, outside ${allowed}): ${filtered.join(", ")}`));
|
|
37417
|
+
function pickCanonicalIssue(hits) {
|
|
37418
|
+
const open = hits.filter((issue) => issue.statusCategory !== "done");
|
|
37419
|
+
const pool = open.length > 0 ? open : hits;
|
|
37420
|
+
const key = oldestIssueKey(pool.map((issue) => issue.key));
|
|
37421
|
+
return pool.find((issue) => issue.key === key);
|
|
36144
37422
|
}
|
|
37423
|
+
// src/commands/ideas-sync/run-ideas-sync/converge-created-issue/converge-created-issue.ts
|
|
36145
37424
|
/**
|
|
36146
|
-
*
|
|
36147
|
-
*
|
|
36148
|
-
*
|
|
37425
|
+
* Makes the creation of an issue converge when two runs file the same idea at the same time. Both runs searched for
|
|
37426
|
+
* the marker before either created, so both created; each now searches again, and the oldest issue carrying the exact
|
|
37427
|
+
* `marker` (by {@link pickCanonicalIssue}: the oldest open one) is the winner. Both runs see the same issues, so they pick the same winner: the
|
|
37428
|
+
* run whose issue is the oldest keeps it, and the other comments on its own issue and closes it (`transition` to
|
|
37429
|
+
* `done`; the `Issues` capability has no closed-as-duplicate state), then reports the winner's key. Nothing here throws.
|
|
37430
|
+
* When a winner other than `created` is known, its key is always the one returned, so the note points at the canonical
|
|
37431
|
+
* issue even if commenting or closing the duplicate does not go through (then `warning` is set and the detail names
|
|
37432
|
+
* both keys). When the search itself does not go through no winner is known, so `created` is returned with a warning,
|
|
37433
|
+
* because a created issue is never left out of the note.
|
|
37434
|
+
*
|
|
37435
|
+
* @param issues - The tracker; only `search`, `comment` and `transition` are used.
|
|
37436
|
+
* @param marker - The exact hidden marker line of the idea, as written in the issue body.
|
|
37437
|
+
* @param created - The key of the issue this run has just created.
|
|
36149
37438
|
*/
|
|
36150
|
-
async function
|
|
36151
|
-
|
|
36152
|
-
const wanted = scope.repos;
|
|
36153
|
-
if (!secrets.listSecretAccess) return { wanted };
|
|
37439
|
+
async function convergeCreatedIssue(issues, marker, created) {
|
|
37440
|
+
let candidates;
|
|
36154
37441
|
try {
|
|
36155
|
-
|
|
37442
|
+
candidates = (await issues.search({
|
|
37443
|
+
text: marker,
|
|
37444
|
+
limit: 100
|
|
37445
|
+
})).filter((issue) => issue.body?.includes(marker) && issue.key !== created);
|
|
37446
|
+
} catch (err) {
|
|
36156
37447
|
return {
|
|
36157
|
-
|
|
36158
|
-
|
|
37448
|
+
key: created,
|
|
37449
|
+
warning: true,
|
|
37450
|
+
detail: `filed as ${created}; could not check for a duplicate from an overlapping run (${describeError(err)}), so look for another issue with the same marker and close one by hand`
|
|
36159
37451
|
};
|
|
36160
|
-
} catch (err) {
|
|
36161
|
-
print(style.dim(` · could not read who can read the organization's secrets (${describeError(err)})`));
|
|
36162
|
-
return { wanted };
|
|
36163
37452
|
}
|
|
36164
|
-
|
|
36165
|
-
|
|
36166
|
-
|
|
36167
|
-
|
|
36168
|
-
|
|
36169
|
-
|
|
36170
|
-
|
|
36171
|
-
|
|
36172
|
-
...r.message ? { detail: r.message } : {}
|
|
36173
|
-
}, `sync secrets: ${r.key} → ${r.destination}`);
|
|
36174
|
-
const summary = rows.reduce((acc, r) => {
|
|
36175
|
-
if (r.status === "ok") acc.ok += 1;
|
|
36176
|
-
else if (r.status === "fail") acc.fail += 1;
|
|
36177
|
-
else if (r.status === "skip") acc.skip += 1;
|
|
36178
|
-
else if (r.status === "dry-run") acc.dryRun += 1;
|
|
36179
|
-
return acc;
|
|
36180
|
-
}, {
|
|
36181
|
-
ok: 0,
|
|
36182
|
-
fail: 0,
|
|
36183
|
-
skip: 0,
|
|
36184
|
-
dryRun: 0
|
|
36185
|
-
});
|
|
36186
|
-
logger[summary.fail > 0 ? "warn" : "info"]({
|
|
36187
|
-
...summary,
|
|
36188
|
-
keys: rows.length
|
|
36189
|
-
}, "sync secrets: done");
|
|
36190
|
-
print("");
|
|
36191
|
-
const summaryLine = `${summary.ok} ok, ${summary.fail} fail, ${summary.skip} skipped${dryRun ? `, ${summary.dryRun} would-do` : ""}`;
|
|
36192
|
-
print(summary.fail > 0 ? style.fail(summaryLine) : style.success(summaryLine));
|
|
36193
|
-
return {
|
|
36194
|
-
rows,
|
|
36195
|
-
summary
|
|
36196
|
-
};
|
|
36197
|
-
}
|
|
36198
|
-
/**
|
|
36199
|
-
* One key to one destination. A key the vault does not hold, or holds blank, is a skipped row: a blank is a placeholder
|
|
36200
|
-
* for a value still to be found, and pushing it would overwrite a working secret with nothing (which no provider can
|
|
36201
|
-
* read back to undo). Everything else goes through {@link runRow}.
|
|
36202
|
-
*/
|
|
36203
|
-
async function pushRow(destination, scope, key, envVars, dryRun, body, nameProblem) {
|
|
36204
|
-
const problem = nameProblem?.(key);
|
|
36205
|
-
if (problem) return {
|
|
36206
|
-
destination,
|
|
36207
|
-
scope,
|
|
36208
|
-
key,
|
|
36209
|
-
status: "skip",
|
|
36210
|
-
message: `invalid name: ${problem}`
|
|
36211
|
-
};
|
|
36212
|
-
const value = Object.hasOwn(envVars, key) ? envVars[key] : void 0;
|
|
36213
|
-
if (value === void 0) return {
|
|
36214
|
-
destination,
|
|
36215
|
-
scope,
|
|
36216
|
-
key,
|
|
36217
|
-
status: "skip",
|
|
36218
|
-
message: "not in the vault environment"
|
|
36219
|
-
};
|
|
36220
|
-
if (value.trim() === "") return {
|
|
36221
|
-
destination,
|
|
36222
|
-
scope,
|
|
36223
|
-
key,
|
|
36224
|
-
status: "skip",
|
|
36225
|
-
message: "blank in the vault environment"
|
|
36226
|
-
};
|
|
36227
|
-
return runRow(destination, scope, key, dryRun, () => body(restorePem(value)));
|
|
36228
|
-
}
|
|
36229
|
-
/** The name check for a destination: GitHub's rules when the provider is `github`, none for any other. */
|
|
36230
|
-
function nameCheck(providerName) {
|
|
36231
|
-
return providerName === "github" ? githubNameProblem : void 0;
|
|
36232
|
-
}
|
|
36233
|
-
async function runRow(destination, scope, key, dryRun, body) {
|
|
36234
|
-
if (dryRun) return {
|
|
36235
|
-
destination,
|
|
36236
|
-
scope,
|
|
36237
|
-
key,
|
|
36238
|
-
status: "dry-run"
|
|
37453
|
+
const winner = pickCanonicalIssue([...candidates, {
|
|
37454
|
+
key: created,
|
|
37455
|
+
statusCategory: "open"
|
|
37456
|
+
}]).key;
|
|
37457
|
+
if (winner === created) return {
|
|
37458
|
+
key: created,
|
|
37459
|
+
warning: false,
|
|
37460
|
+
detail: `filed as ${created}`
|
|
36239
37461
|
};
|
|
36240
37462
|
try {
|
|
36241
|
-
await
|
|
36242
|
-
|
|
36243
|
-
destination,
|
|
36244
|
-
scope,
|
|
36245
|
-
key,
|
|
36246
|
-
status: "ok"
|
|
36247
|
-
};
|
|
37463
|
+
await issues.comment(created, `Duplicate of ${winner}: the same idea was filed by two overlapping runs.`);
|
|
37464
|
+
await issues.transition(created, "done");
|
|
36248
37465
|
} catch (err) {
|
|
36249
37466
|
return {
|
|
36250
|
-
|
|
36251
|
-
|
|
36252
|
-
|
|
36253
|
-
status: "fail",
|
|
36254
|
-
message: errorMessage(err)
|
|
37467
|
+
key: winner,
|
|
37468
|
+
warning: true,
|
|
37469
|
+
detail: `filed as ${winner}, the older issue for the idea, but the duplicate ${created} could not be closed (${describeError(err)}); close ${created} by hand`
|
|
36255
37470
|
};
|
|
36256
37471
|
}
|
|
37472
|
+
return {
|
|
37473
|
+
key: winner,
|
|
37474
|
+
warning: false,
|
|
37475
|
+
detail: `filed as ${winner} (closed duplicate ${created} from an overlapping run)`
|
|
37476
|
+
};
|
|
36257
37477
|
}
|
|
36258
|
-
|
|
36259
|
-
const detail = row.message ? style.dim(` (${row.message})`) : "";
|
|
36260
|
-
const label = `${row.key}${detail}`;
|
|
36261
|
-
if (row.status === "ok") return ` ${style.success(label)}`;
|
|
36262
|
-
if (row.status === "fail") return ` ${style.fail(label)}`;
|
|
36263
|
-
if (row.status === "dry-run") return ` ${style.dim(`… ${label}`)}`;
|
|
36264
|
-
return ` ${style.dim(`· ${label}`)}`;
|
|
36265
|
-
}
|
|
36266
|
-
function scopeLabel(scope) {
|
|
36267
|
-
if (scope.kind === "repo") return "scope=repo";
|
|
36268
|
-
if (scope.kind === "organization") return `scope=organization,org=${scope.name}`;
|
|
36269
|
-
return `scope=environment,env=${scope.name}`;
|
|
36270
|
-
}
|
|
36271
|
-
function vaultProviderName(loader) {
|
|
36272
|
-
if (!loader.has("vault")) return "<missing>";
|
|
36273
|
-
return loader.get("vault").providerName;
|
|
36274
|
-
}
|
|
36275
|
-
// src/commands/secrets-sync/variable-routes.ts
|
|
37478
|
+
// src/commands/ideas-sync/run-ideas-sync/run-ideas-sync.ts
|
|
36276
37479
|
/**
|
|
36277
|
-
*
|
|
36278
|
-
* it gives its keys and the scope they land at (`repo` when omitted). An environment no entry names has none.
|
|
37480
|
+
* `holocron sync ideas` — files the idea notes that are ready.
|
|
36279
37481
|
*
|
|
36280
|
-
*
|
|
36281
|
-
*
|
|
36282
|
-
*
|
|
37482
|
+
* It reads every idea through the `ideas` provider (`providers.ideas`, or `ideas.dir` read as an Obsidian vault; the
|
|
37483
|
+
* Obsidian plugin skips folders whose name starts with `_` or `.`). An idea whose status is the filing state (default
|
|
37484
|
+
* `in-progress`) and that has no issue becomes an issue through the repo's `issues` provider, and the issue is then
|
|
37485
|
+
* recorded with `Ideas.markFiled` (for Obsidian, an `issue:` property in the tracker's own syntax), which is what makes
|
|
37486
|
+
* the step run once. An idea with attachments is reported and skipped, since an issue body cannot carry them. Only
|
|
37487
|
+
* ideas to be filed, and ideas that need the person's attention, get a row; the rest are counted. The issue body ends
|
|
37488
|
+
* with a hidden `<!-- holocron:idea <key> -->` line, and an issue that carries it is reused instead of making a second
|
|
37489
|
+
* one (found with one `Issues.search({ text })` per note about to be filed, confirmed by the exact marker in the body;
|
|
37490
|
+
* GitHub searches its 2000 most recently updated issues, so an older one is still missed, and each search uses rate
|
|
37491
|
+
* limit). Two runs that overlap can both miss the marker and both create; each then searches once more after its
|
|
37492
|
+
* create (`convergeCreatedIssue()`), the older issue wins and the other run closes its own with a comment, so both
|
|
37493
|
+
* notes end with one key. It never deletes anything, and an idea it cannot file is a
|
|
37494
|
+
* failing row (the run goes on). It writes, so it asks first unless `--dry-run` or `--yes` (without a terminal it refuses instead).
|
|
36283
37495
|
*/
|
|
36284
|
-
|
|
36285
|
-
|
|
36286
|
-
|
|
36287
|
-
|
|
37496
|
+
/** The state that files a note when the config names none. */
|
|
37497
|
+
const DEFAULT_FILING_STATE = "in-progress";
|
|
37498
|
+
const row$3 = (id, status, detail) => ({
|
|
37499
|
+
id,
|
|
37500
|
+
title: id,
|
|
37501
|
+
status,
|
|
37502
|
+
detail,
|
|
37503
|
+
problems: []
|
|
37504
|
+
});
|
|
37505
|
+
/**
|
|
37506
|
+
* The hidden line that ties an issue to its note. A later run looks for it before it creates an issue, so a note whose
|
|
37507
|
+
* `issue:` could not be written is not filed twice.
|
|
37508
|
+
*/
|
|
37509
|
+
const marker = (key) => `<!-- holocron:idea ${key} -->`;
|
|
37510
|
+
/** The issue's body: the idea's text, the line that traces the issue to its idea, and the hidden marker. */
|
|
37511
|
+
const issueBody = (idea) => `${idea.body.trim()}\n\nFiled from idea: ${idea.title}\n${marker(idea.key)}`;
|
|
37512
|
+
async function runIdeasSync(input) {
|
|
37513
|
+
/* v8 ignore next -- the console is only used outside tests, which inject `print` */
|
|
37514
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
37515
|
+
const dryRun = Boolean(input.context.dryRun);
|
|
37516
|
+
let notReady = 0;
|
|
37517
|
+
const finish = (rows, status) => {
|
|
37518
|
+
printCheckRows(rows, print);
|
|
37519
|
+
const summary = summariseChecks(rows);
|
|
37520
|
+
printCheckSummary(summary, print);
|
|
37521
|
+
if (notReady > 0) print(` ${notReady} note(s) not ready (another status, or already filed), shown in no row`);
|
|
36288
37522
|
return {
|
|
36289
|
-
|
|
36290
|
-
|
|
36291
|
-
...entry.visibility ? { visibility: entry.visibility } : {}
|
|
37523
|
+
status: status ?? (summary.fail > 0 ? "fail" : "ok"),
|
|
37524
|
+
rows
|
|
36292
37525
|
};
|
|
36293
|
-
}
|
|
37526
|
+
};
|
|
37527
|
+
print(style.header(`Holocron sync ideas${dryRun ? " (dry-run)" : ""}`));
|
|
37528
|
+
print("");
|
|
37529
|
+
const entry = resolveIdeasProvider(input.loaded.resolved, input.env);
|
|
37530
|
+
if (!entry) return finish([row$3("ideas", "fail", "no `ideas` provider: set `providers.ideas` (`[\"obsidian\", { dir }]`) in holocron.config or HOLOCRON_IDEAS_DIR")]);
|
|
37531
|
+
/* v8 ignore start -- the real loader is only built outside tests, which always inject one */
|
|
37532
|
+
const reader = input.ideasLoader ?? new PluginLoader({
|
|
37533
|
+
...input.loaded.resolved,
|
|
37534
|
+
providers: { ideas: entry }
|
|
37535
|
+
}, input.context);
|
|
37536
|
+
/* v8 ignore stop */
|
|
37537
|
+
await reader.load();
|
|
37538
|
+
assertPluginsResolvable(reader, "sync ideas");
|
|
37539
|
+
if (!reader.has("ideas")) {
|
|
37540
|
+
const failure = reader.loadFailures().find((f) => f.key === "ideas");
|
|
37541
|
+
return finish([row$3("ideas", "fail", `the \`ideas\` provider is not available${failure ? ` (${describeError(failure.error)})` : ""}`)]);
|
|
37542
|
+
}
|
|
37543
|
+
const ideas = reader.get("ideas");
|
|
37544
|
+
let records;
|
|
37545
|
+
try {
|
|
37546
|
+
records = await ideas.list();
|
|
37547
|
+
} catch (err) {
|
|
37548
|
+
return finish([row$3("ideas", "fail", describeError(err))]);
|
|
37549
|
+
}
|
|
37550
|
+
const fileState = input.loaded.resolved.ideas?.states?.file ?? DEFAULT_FILING_STATE;
|
|
37551
|
+
const rows = [];
|
|
37552
|
+
const ready = [];
|
|
37553
|
+
for (const idea of records) if (idea.error !== void 0) rows.push(row$3(idea.key, "fail", idea.error));
|
|
37554
|
+
else if (idea.status !== fileState || idea.issue !== void 0) notReady++;
|
|
37555
|
+
else if (idea.attachments.length > 0) rows.push(row$3(idea.key, "skip", `has embedded files an issue cannot carry (${idea.attachments.join(", ")}); not filed`));
|
|
37556
|
+
else ready.push(idea);
|
|
37557
|
+
if (ready.length === 0) return finish(rows);
|
|
37558
|
+
if (dryRun) {
|
|
37559
|
+
for (const idea of ready) rows.push(row$3(idea.key, "skip", `would file "${idea.title}"`));
|
|
37560
|
+
return finish(rows.sort((a, b) => a.id.localeCompare(b.id)));
|
|
37561
|
+
}
|
|
37562
|
+
if (!input.yes) {
|
|
37563
|
+
if (!(input.interactive ?? Boolean(process.stdin.isTTY))) throw new NonInteractiveError(`\`sync ideas\` creates ${ready.length} issue(s) and edits the notes; pass --yes to run it without asking, or --dry-run to preview`);
|
|
37564
|
+
if (!await (input.confirm ?? ((message) => confirm({
|
|
37565
|
+
message,
|
|
37566
|
+
default: false
|
|
37567
|
+
})))(`File ${ready.length} idea(s) as issues and record the issue in each note?`)) {
|
|
37568
|
+
print(` ${style.skip("cancelled; nothing was changed")}`);
|
|
37569
|
+
return {
|
|
37570
|
+
status: "cancelled",
|
|
37571
|
+
rows: []
|
|
37572
|
+
};
|
|
37573
|
+
}
|
|
37574
|
+
}
|
|
37575
|
+
/* v8 ignore next -- the real loader is only built outside tests, which always inject one */
|
|
37576
|
+
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
37577
|
+
await loader.load();
|
|
37578
|
+
assertPluginsResolvable(loader, "sync ideas");
|
|
37579
|
+
const issues = loader.has("issues") ? loader.get("issues") : void 0;
|
|
37580
|
+
for (const idea of ready) {
|
|
37581
|
+
const path = idea.key;
|
|
37582
|
+
if (!issues) {
|
|
37583
|
+
rows.push(row$3(path, "fail", "the config has no `issues` provider to file it with"));
|
|
37584
|
+
continue;
|
|
37585
|
+
}
|
|
37586
|
+
let existing;
|
|
37587
|
+
try {
|
|
37588
|
+
existing = pickCanonicalIssue((await issues.search({
|
|
37589
|
+
text: marker(path),
|
|
37590
|
+
limit: 100
|
|
37591
|
+
})).filter((issue) => issue.body?.includes(marker(path))));
|
|
37592
|
+
} catch (err) {
|
|
37593
|
+
rows.push(row$3(path, "fail", `could not check for an existing issue, so none was created: ${describeError(err)}`));
|
|
37594
|
+
continue;
|
|
37595
|
+
}
|
|
37596
|
+
let key;
|
|
37597
|
+
let detail = `already filed as ${existing?.key}`;
|
|
37598
|
+
let warning = false;
|
|
37599
|
+
if (existing) key = existing.key;
|
|
37600
|
+
else {
|
|
37601
|
+
let created;
|
|
37602
|
+
try {
|
|
37603
|
+
({key: created} = await issues.create({
|
|
37604
|
+
summary: idea.title,
|
|
37605
|
+
body: issueBody(idea)
|
|
37606
|
+
}));
|
|
37607
|
+
} catch (err) {
|
|
37608
|
+
rows.push(row$3(path, "fail", `could not create the issue: ${describeError(err)}`));
|
|
37609
|
+
continue;
|
|
37610
|
+
}
|
|
37611
|
+
({key, detail, warning} = await convergeCreatedIssue(issues, marker(path), created));
|
|
37612
|
+
}
|
|
37613
|
+
try {
|
|
37614
|
+
await ideas.markFiled(path, key);
|
|
37615
|
+
rows.push({
|
|
37616
|
+
...row$3(path, "ok", detail),
|
|
37617
|
+
problems: warning ? ["a duplicate issue for this idea may be open: close the extra one by hand"] : []
|
|
37618
|
+
});
|
|
37619
|
+
} catch (err) {
|
|
37620
|
+
rows.push({
|
|
37621
|
+
...row$3(path, "fail", `issue ${key} was created but \`issue:\` was not written: ${describeError(err)}`),
|
|
37622
|
+
problems: [`add \`issue: ${key}\` to the note by hand`]
|
|
37623
|
+
});
|
|
37624
|
+
}
|
|
37625
|
+
}
|
|
37626
|
+
return finish(rows.sort((a, b) => a.id.localeCompare(b.id)));
|
|
36294
37627
|
}
|
|
37628
|
+
// src/commands/ideas-sync/ideas-sync.command.ts
|
|
37629
|
+
const ideasSyncCommand = {
|
|
37630
|
+
command: "ideas",
|
|
37631
|
+
describe: "File the idea notes that are ready as issues, and record the issue in each note",
|
|
37632
|
+
builder: (y) => y.option("yes", {
|
|
37633
|
+
type: "boolean",
|
|
37634
|
+
describe: "File without asking (required without a terminal)"
|
|
37635
|
+
}),
|
|
37636
|
+
handler: async (argv) => {
|
|
37637
|
+
const tokens = tokenContext(argv.token);
|
|
37638
|
+
if (!tokens) return;
|
|
37639
|
+
const loaded = await loadConfig(argv.cwd);
|
|
37640
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
37641
|
+
if ((await runIdeasSync({
|
|
37642
|
+
loaded,
|
|
37643
|
+
context: {
|
|
37644
|
+
repoRoot: argv.cwd,
|
|
37645
|
+
dryRun: argv.dryRun,
|
|
37646
|
+
...tokens,
|
|
37647
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
37648
|
+
},
|
|
37649
|
+
...argv.yes ? { yes: true } : {}
|
|
37650
|
+
})).status === "fail") process.exitCode = 1;
|
|
37651
|
+
}
|
|
37652
|
+
};
|
|
37653
|
+
// src/commands/notifications-sync-roles/notifications-sync-roles.args.ts
|
|
37654
|
+
const notificationsSyncRolesArgs = (y) => y.option("provider", {
|
|
37655
|
+
type: "string",
|
|
37656
|
+
describe: "Which notifications provider, when several can manage roles"
|
|
37657
|
+
}).option("keep", {
|
|
37658
|
+
type: "boolean",
|
|
37659
|
+
default: false,
|
|
37660
|
+
describe: "Give the role to new team members but do not take it from people who left"
|
|
37661
|
+
});
|
|
37662
|
+
// src/commands/notifications-sync-roles/notifications-sync-roles.command.ts
|
|
37663
|
+
const notificationsSyncRolesCommand = {
|
|
37664
|
+
command: "roles",
|
|
37665
|
+
describe: "Make who holds a server role match a team, through the links file",
|
|
37666
|
+
builder: notificationsSyncRolesArgs,
|
|
37667
|
+
handler: async (argv) => {
|
|
37668
|
+
const tokens = tokenContext(argv.token);
|
|
37669
|
+
if (!tokens) return;
|
|
37670
|
+
const loaded = await loadConfig(argv.cwd);
|
|
37671
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
37672
|
+
if ((await runNotificationsSyncRoles({
|
|
37673
|
+
loaded,
|
|
37674
|
+
context: {
|
|
37675
|
+
repoRoot: argv.cwd,
|
|
37676
|
+
dryRun: argv.dryRun,
|
|
37677
|
+
...tokens,
|
|
37678
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
37679
|
+
},
|
|
37680
|
+
...argv.provider ? { provider: argv.provider } : {},
|
|
37681
|
+
keep: argv.keep
|
|
37682
|
+
})).status === "fail") process.exitCode = 1;
|
|
37683
|
+
}
|
|
37684
|
+
};
|
|
36295
37685
|
// src/commands/secrets-sync/secrets-sync.args.ts
|
|
36296
37686
|
const secretsSyncArgs = (y) => y.option("env", {
|
|
36297
37687
|
type: "string",
|
|
@@ -38847,103 +40237,6 @@ const syncArgs = (y) => y.positional("steps", {
|
|
|
38847
40237
|
global: false,
|
|
38848
40238
|
describe: "Repo coords (\"owner/name\"). Defaults to plugin-specific resolution."
|
|
38849
40239
|
});
|
|
38850
|
-
// src/commands/app-layer/app-layer.ts
|
|
38851
|
-
/**
|
|
38852
|
-
* The vault layer an app's secrets for a deployment target are read from: `production` reads `prod` and `preview` reads
|
|
38853
|
-
* its own `preview` layer, never `prod` (spec `tech-sentinel-preview-instance`), so a preview deployment is given only
|
|
38854
|
-
* what its own Environment holds.
|
|
38855
|
-
*/
|
|
38856
|
-
function appLayer(target) {
|
|
38857
|
-
return target === "production" ? "prod" : "preview";
|
|
38858
|
-
}
|
|
38859
|
-
// src/commands/app-sync/app-sync.ts
|
|
38860
|
-
/**
|
|
38861
|
-
* `holocron sync <app> --env <env>`: reads the app's vault Environment of each target's layer (`prod` for production,
|
|
38862
|
-
* `preview` for preview, never one for the other) and sends the secrets `repo.secrets.deploy` names for that layer to the
|
|
38863
|
-
* app's destinations, the way `sync secrets --project-id <app> --target <target>` or `--worker <app>` would: the Vercel
|
|
38864
|
-
* project when the app has a `deployment` provider, the Worker script when it has a `workers` provider, both named after
|
|
38865
|
-
* the app folder. Before anything is written the project must serve the app's
|
|
38866
|
-
* configured `domain`. An app with neither destination has nothing to sync and is reported, not failed.
|
|
38867
|
-
*
|
|
38868
|
-
* @param input - The app, the environment, its loaded config and the seams tests replace.
|
|
38869
|
-
*/
|
|
38870
|
-
async function runAppSync(input) {
|
|
38871
|
-
const { app, env } = input;
|
|
38872
|
-
const print = input.print ?? ((line) => console.log(line));
|
|
38873
|
-
const fail = (message) => {
|
|
38874
|
-
print(` ${style.fail(message)}`);
|
|
38875
|
-
return {
|
|
38876
|
-
status: "fail",
|
|
38877
|
-
message
|
|
38878
|
-
};
|
|
38879
|
-
};
|
|
38880
|
-
if (app.configError) return fail(`${app.name}: its holocron.config cannot be read: ${app.configError}`);
|
|
38881
|
-
const plan = appPlan(app.config);
|
|
38882
|
-
if (!plan.deployment && !plan.workers) {
|
|
38883
|
-
const message = `${app.name}: no deployment or Worker is configured, so there are no secrets to sync; nothing to do`;
|
|
38884
|
-
print(` ${style.dim(message)}`);
|
|
38885
|
-
return {
|
|
38886
|
-
status: "nothing",
|
|
38887
|
-
message
|
|
38888
|
-
};
|
|
38889
|
-
}
|
|
38890
|
-
if (!plan.deployKeys) return fail(`${app.name}: its config has no \`repo.secrets.deploy\` entry, and a deployment or Worker receives only the secrets that names`);
|
|
38891
|
-
const { loaded, context, loader } = await input.load();
|
|
38892
|
-
const destinations = [plan.deployment ? `${app.name} (project)` : "", plan.workers ? `${app.name} (Worker)` : ""];
|
|
38893
|
-
print(style.header(`Holocron sync ${app.name} → ${destinations.filter(Boolean).join(" + ")}${context.dryRun ? " (dry-run)" : ""}`));
|
|
38894
|
-
const instances = /* @__PURE__ */ new Map();
|
|
38895
|
-
if (plan.deployment) {
|
|
38896
|
-
await loader.load();
|
|
38897
|
-
if (!loader.has("deployment")) return fail(`${app.name}: the deployment provider did not load`);
|
|
38898
|
-
try {
|
|
38899
|
-
for (const target of env.targets) instances.set(target, appInstance(app.name, plan.deployment.options, target));
|
|
38900
|
-
} catch (err) {
|
|
38901
|
-
return fail(errorMessage(err));
|
|
38902
|
-
}
|
|
38903
|
-
for (const instance of instances.values()) {
|
|
38904
|
-
const checked = await checkProjectDomain(loader.get("deployment"), instance.project, instance.domain);
|
|
38905
|
-
if (checked.status === "fail") return fail(checked.message);
|
|
38906
|
-
print(` ${style.dim(checked.message)}`);
|
|
38907
|
-
}
|
|
38908
|
-
}
|
|
38909
|
-
const resolved = loaded.resolved;
|
|
38910
|
-
const failed = [];
|
|
38911
|
-
let written = 0;
|
|
38912
|
-
let skipped = 0;
|
|
38913
|
-
for (const target of env.targets) {
|
|
38914
|
-
const environment = await input.resolveEnvironment(appLayer(target));
|
|
38915
|
-
const instance = instances.get(target);
|
|
38916
|
-
const routes = secretRoutes(resolved.repo?.secrets?.sync, environment);
|
|
38917
|
-
const variables = variableRoutes(resolved.repo?.variables?.sync, environment);
|
|
38918
|
-
const variablesOnly = variables.length > 0 && routes.length === 0;
|
|
38919
|
-
const filter = deployFilter(resolved.repo?.secrets?.deploy, environment);
|
|
38920
|
-
const report = await input.syncSecrets({
|
|
38921
|
-
loaded,
|
|
38922
|
-
context,
|
|
38923
|
-
loader,
|
|
38924
|
-
environmentId: environment,
|
|
38925
|
-
...instance ? {
|
|
38926
|
-
projectId: instance.project,
|
|
38927
|
-
targets: [instance.production ? "production" : target]
|
|
38928
|
-
} : {},
|
|
38929
|
-
...plan.workers ? { workerScript: app.name } : {},
|
|
38930
|
-
...filter ? { deployFilter: filter } : {},
|
|
38931
|
-
...routes.length ? { secretRoutes: routes } : variablesOnly ? { secretRoutes: [] } : {},
|
|
38932
|
-
...variables.length ? { variableRoutes: variables } : {}
|
|
38933
|
-
});
|
|
38934
|
-
written += report.summary.ok;
|
|
38935
|
-
skipped += report.summary.skip;
|
|
38936
|
-
if (report.summary.fail > 0) failed.push(`${target}: ${report.summary.fail} secret(s) did not sync`);
|
|
38937
|
-
}
|
|
38938
|
-
if (failed.length > 0) return {
|
|
38939
|
-
status: "fail",
|
|
38940
|
-
message: `${app.name}: ${failed.join("; ")}`
|
|
38941
|
-
};
|
|
38942
|
-
return {
|
|
38943
|
-
status: "ok",
|
|
38944
|
-
message: `${app.name} synced (${written} written, ${skipped} skipped)`
|
|
38945
|
-
};
|
|
38946
|
-
}
|
|
38947
40240
|
// src/commands/sync/sync-app.ts
|
|
38948
40241
|
/**
|
|
38949
40242
|
* The `sync <app> --env <env>` path of the `sync` command (spec `tool-app-deploy-sync`). The first step is the app's
|