@theholocron/cli 5.0.0-alpha.351 → 5.0.0-alpha.353
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 +17 -2
- package/dist/cli.mjs +212 -16
- package/dist/cli.mjs.map +1 -1
- package/dist/{config-system-C6MsRNbo.d.mts → config-system-CTQ_I-Vm.d.mts} +44 -1
- package/dist/{config-system-5rdWyUAw.mjs → config-system-DKtlo5Pb.mjs} +99 -13
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +3 -3
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -194,6 +194,7 @@ the list is never read):
|
|
|
194
194
|
| --------------------------- | ---------------------------------------------------------------------------------- |
|
|
195
195
|
| `.holocron/notifications.*` | the `layout` option of the `providers.notifications` entry (which keeps `guildId`) |
|
|
196
196
|
| `.holocron/repo.*` | keys of `repo` (`defaultBranch` stays inline: Sentinel needs it first) |
|
|
197
|
+
| `.holocron/org.*` | provider options the config leaves out (`teamId`, `accountId`), see below |
|
|
197
198
|
|
|
198
199
|
The file's default export is the value (`.ts` keeps its comments; `.json` needs no `import`, for repos with no
|
|
199
200
|
`package.json`). If both exist for one area, `.ts` wins over `.json`. A missing directory changes nothing. Setting the
|
|
@@ -237,6 +238,18 @@ is no per-key precedence: the loader does not let an inline key win, it refuses
|
|
|
237
238
|
repo's `.holocron/repo.ts` holds `teams`, `topics`, `variables` and `secrets`, names and identifiers only, typed with
|
|
238
239
|
`satisfies RepoConfig` (a type-only import).
|
|
239
240
|
|
|
241
|
+
**The `org` area** (#1820). The organization's constants that are provider options and that CI does not need:
|
|
242
|
+
`.holocron/org.ts` is `{ cloudflare: { accountId }, vercel: { teamId }, checkly: { accountId } }` (typed with
|
|
243
|
+
`satisfies OrgConfig`). The loader fills each of these into every provider entry of that name that leaves the option
|
|
244
|
+
out, so the config can say `deployment: ["vercel", { domain }]` and `monitoring: "checkly"`. The same option set inline
|
|
245
|
+
and in the file is an error that names both (`vercel.teamId is set in providers.deployment and in
|
|
246
|
+
.holocron/org.ts`), with no merge and no precedence. A provider key or an option the area does not know is an error; a
|
|
247
|
+
provider the config does not use is ignored. A config reads only the `.holocron/` beside it, so an app with its own
|
|
248
|
+
`holocron.config.ts` (`apps/sentinel`) has its own `.holocron/org.ts`. Anything CI needs (`CLOUDFLARE_ACCOUNT_ID`,
|
|
249
|
+
`TURBO_TEAM`, `AXIOM_DATASET`) stays out: it lives in 1Password and syncs to a GitHub variable (`repo.variables.sync`),
|
|
250
|
+
and nothing else carries a copy. `.holocron/org.md` (the agent contract the CLI embeds) is not an area: only
|
|
251
|
+
`.ts`, `.js`, `.mjs`, `.cjs` and `.json` are read.
|
|
252
|
+
|
|
240
253
|
### repo options
|
|
241
254
|
|
|
242
255
|
Additional `repo` fields recognised by `holocron repo setup`:
|
|
@@ -247,7 +260,7 @@ Additional `repo` fields recognised by `holocron repo setup`:
|
|
|
247
260
|
| `repo.topics` | `string[]` | GitHub topics set on the repository. |
|
|
248
261
|
| `repo.protection` | `"balanced" \| "strict" \| "none"` | Branch-protection preset applied by `holocron repo setup`. For `"strict"`, the required status checks are derived from the task manifest — see below. |
|
|
249
262
|
| `repo.properties` | `RepoProperties` | Org-level custom property values synced to the GitHub dashboard. |
|
|
250
|
-
| `repo.variables` | `{ repo?, org?, prune? }`
|
|
263
|
+
| `repo.variables` | `{ repo?, org?, sync?, prune? }` | GitHub Actions variables created and updated by `holocron repo setup`. Undeclared ones are left alone unless `prune` is on. `sync: [{ environment, keys, scope?, visibility? }]` names the vault environment `holocron secrets sync` fills Actions variables from (a separate environment from the secrets one; names only, a blank value is skipped, `doctor variables` expects the names). A name given as a literal and in `sync`, or `prune` with `sync`, is a config error. |
|
|
251
264
|
| `repo.secrets` | `{ repo?, org?, environments?, sync? }` | Names of the secrets that must exist, checked (never written) by `holocron doctor secrets`. Names only. The notification layout's secrets and a Chromatic project token are expected without being listed. `sync: [{ environment, keys?, scope? }]` declares the vault environments `secrets sync` fills from (it follows these entries, one step per scope, unless `--github-secret` is given; a blank value is skipped); the doctor expects their keys (every key the `vault` provider lists when `keys` is omitted, names only) at the `scope` (`repo`, `env=<name>`, `org=<name>`). |
|
|
252
265
|
|
|
253
266
|
### Custom properties synced to GitHub
|
|
@@ -610,7 +623,7 @@ commands and the config are provider-neutral; Discord is the first provider.
|
|
|
610
623
|
| `holocron notifications sync-roles` | Makes who holds a role match a GitHub team, through the links file (`--keep` only adds; `--provider` picks one) |
|
|
611
624
|
| `holocron project reconcile [board]` | Sets item statuses where a rule says so: an open blocker means `blocked`, no blocker left means `planned`, closed means `done` (status only; `--dry-run` previews; an open item with no status is reported). Runs hourly from `platform.projectReconcile.yml`, which `repo setup` writes when `providers.projects` declares boards |
|
|
612
625
|
| `holocron doctor notifications [--built-only] [--deliver] [--post]` | Step by step: does the server match the layout, do the secrets exist, and does a person (not the bot) own it. A full run also leaves one `🧪 test:` post in the layout's `testChannel`; `--built-only` posts nothing; `--deliver` posts to every channel and removes each post; `--post [channel]` posts the result as the bot (the failures, or only the summary when none failed). It also reads the Checkly feed (webhook, alert channel, subscriptions), the Comlink relay (Worker, route, bindings, the tracker's integration and rule) and the Notifications workflow (the file, and the secrets it reads), posting nothing, so `--built-only` keeps those steps |
|
|
613
|
-
| `holocron doctor variables` | Do the Actions variables `repo.variables` declares exist, with those values (and, for the organization's, that visibility)? One row for the repository and one for the organization, each only when declared. Read-only. An undeclared variable counts only with `prune`; a scope that cannot be read (no provider, no org token) is a skip, not a failure
|
|
626
|
+
| `holocron doctor variables` | Do the Actions variables `repo.variables` declares exist, with those values (and, for the organization's, that visibility)? One row for the repository and one for the organization, each only when declared. Read-only. A `repo.variables.sync` entry adds one row that checks its names exist (no value is read or shown). An undeclared variable counts only with `prune`; a scope that cannot be read (no provider, no org token) is a skip, not a failure |
|
|
614
627
|
| `holocron doctor ci` | Has the repo moved to the flat task vocabulary? One row each for the `tasks:` entries (a deprecated alias, with the id that replaces it), the generated callers (file, workflow and job name equal the task id), the `ci` aggregate's `expected` list (no id missing or stale) and where the callers point (`theholocron/.github` or holocron `ci-v1`). Read-only, no provider needed; exits 1 on a failure. The ruleset's checks are `doctor repo`'s |
|
|
615
628
|
| `holocron doctor environments` | Do the deployment environments exist? The ones `repo setup` creates (`staging`, `production`, when an `environments` provider is configured) plus every environment `repo.secrets.environments` names. One row. A missing one fails; an extra one is never a problem; no provider with some named is a skip |
|
|
616
629
|
| `holocron doctor project [--post [channel]]` | Does each board `providers.projects.boards` declares exist and match its template? One row per board, status list, field, view and automation rule; the board's extras and the items `project reconcile` would fix (no status, closed but not done, open blocker but not blocked, blocked without a blocker) are `info` rows, never a failure. A template file that does not read fails, naming the file. Read-only; `--post` shares the failing rows through the `notifications` bot. |
|
|
@@ -629,6 +642,8 @@ Channels fed by the error tracker add `feeds: { errors: true }` and a layout `re
|
|
|
629
642
|
|
|
630
643
|
`holocron secrets sync <env> --worker <script>` also sets every key of the vault environment on a deployed Worker as a secret, through the optional `Workers.setSecret(script, name, value)` (write-only; the Cloudflare plugin implements it). The Worker must already exist. Sync only adds and updates: it never removes a binding, because a Worker also holds secrets that are not in the vault (for Comlink, the `COMLINK_<SOURCE>_WEBHOOK` that `notifications setup` sets), so a key deleted from the vault must be deleted from the Worker separately. Keys are written one at a time and each is reported; if one fails, the exit code is 1 and re-running finishes the rest, since every write is idempotent.
|
|
631
644
|
|
|
645
|
+
`holocron secrets sync <env>` also writes GitHub Actions **variables** when `repo.variables.sync` has an entry for that environment: each key goes through the `source` provider's `syncVariables` (repo scope) or `syncOrgVariables` (`org=<name>`), one call per key and never pruning, so a name the vault lacks or holds blank is skipped and GitHub keeps its value. Keep these in a vault environment of their own (a vault does not tell a visible value from a secret one, and a variable is readable afterwards). An environment declared only by variable entries pushes nothing to `secrets` or `deployment`. Values are never printed. `doctor variables` checks that the names exist at their scope.
|
|
646
|
+
|
|
632
647
|
`holocron secrets list [--scope repo|environment|organization] [--env <name>] [--json]` prints the names (never the values; GitHub does not return them) of the secrets at each scope, sorted, under a heading per scope. With no `--scope` it lists the repository, plus the organization (`--org`, `HOLOCRON_ORG` or the config's `org`) and the `--env` environment when they are known; `--scope` lists one. A scope that cannot be listed is reported under its heading and the rest are still listed; the exit code is 1 if any failed. `--json` prints `[{ scope, names, error? }]`. It is read-only, so `--dry-run` does not apply. Comparing the names with what the config expects is `doctor secrets`, which also covers the keys of the vault environments declared in `repo.secrets.sync`.
|
|
633
648
|
|
|
634
649
|
A channel with `kind: "forum"` is a forum, with `tags` (each a `name`, an `emoji` and whether it is `moderated`); `setup` adds and corrects the tags but never removes one, and a text channel of the same name must be deleted first, since neither kind can become the other. A forum takes no `webhook` or `feeds`.
|
package/dist/cli.mjs
CHANGED
|
@@ -112,6 +112,34 @@ var MissingTokenError = class extends Error {
|
|
|
112
112
|
/** Lets a caller tell this error from any other by name, across package copies. */
|
|
113
113
|
name = "MissingTokenError";
|
|
114
114
|
};
|
|
115
|
+
// src/config/validate-variables-sync/validate-variables-sync.ts
|
|
116
|
+
/** GitHub treats variable names as case-insensitive, so every comparison goes through this. */
|
|
117
|
+
const key = (name) => name.toUpperCase();
|
|
118
|
+
/**
|
|
119
|
+
* Check `repo.variables.sync`: each entry names a vault environment, one or more keys and a scope that is `repo` or
|
|
120
|
+
* `org=<name>`; a name may not also be a literal value of the same scope (one source per name); and `prune` cannot
|
|
121
|
+
* be combined with `sync`, because `repo setup` would delete the variables the sync wrote.
|
|
122
|
+
*
|
|
123
|
+
* @param variables - `repo.variables`, if the config has it.
|
|
124
|
+
* @throws {ConfigError} Naming the first problem found.
|
|
125
|
+
*/
|
|
126
|
+
function validateVariablesSync(variables) {
|
|
127
|
+
const entries = variables?.sync;
|
|
128
|
+
if (!entries || entries.length === 0) return;
|
|
129
|
+
if (variables?.prune === true) throw new ConfigError("`repo.variables.prune` cannot be combined with `repo.variables.sync`: pruning would delete the variables the sync writes");
|
|
130
|
+
for (const entry of entries) {
|
|
131
|
+
if (typeof entry.environment !== "string" || entry.environment.trim() === "") throw new ConfigError("a `repo.variables.sync` entry needs the name of a vault environment");
|
|
132
|
+
const label = `\`repo.variables.sync\` entry for ${JSON.stringify(entry.environment)}`;
|
|
133
|
+
if (!Array.isArray(entry.keys) || entry.keys.length === 0 || entry.keys.some((k) => typeof k !== "string" || k === "")) throw new ConfigError(`${label} needs \`keys\`, a list of variable names`);
|
|
134
|
+
const scope = entry.scope ?? "repo";
|
|
135
|
+
const org = scope.startsWith("org=") ? scope.slice(4) : void 0;
|
|
136
|
+
if (scope !== "repo" && (org === void 0 || org === "")) throw new ConfigError(`${label} has scope ${JSON.stringify(scope)}: use "repo" or "org=<name>"`);
|
|
137
|
+
if (entry.visibility !== void 0 && entry.visibility !== "all" && entry.visibility !== "private") throw new ConfigError(`${label} has visibility ${JSON.stringify(entry.visibility)}: use "all" or "private"`);
|
|
138
|
+
const literal = new Set(Object.keys((org === void 0 ? variables?.repo : variables?.org) ?? {}).map(key));
|
|
139
|
+
const both = entry.keys.filter((k) => literal.has(key(k)));
|
|
140
|
+
if (both.length > 0) throw new ConfigError(`${label} lists ${both.join(", ")}, which \`repo.variables.${org === void 0 ? "repo" : "org"}\` also gives a value: keep one source per name`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
115
143
|
// src/config/config/config.ts
|
|
116
144
|
const PLUGIN_PREFIX = "@theholocron/holocron-plugin-";
|
|
117
145
|
const COMMUNITY_PREFIX = "holocron-plugin-";
|
|
@@ -233,6 +261,7 @@ function resolveConfig(raw) {
|
|
|
233
261
|
if (typeof environment !== "string" || environment.trim() === "") throw new ConfigError$1("`credentials.environment` must be the name of an environment, got an empty value");
|
|
234
262
|
}
|
|
235
263
|
if (raw.dev !== void 0) validateDev(raw.dev);
|
|
264
|
+
validateVariablesSync(raw.repo?.variables);
|
|
236
265
|
const credentialsEntry = providers.credentials;
|
|
237
266
|
if (credentialsEntry?.cardinality === "many") for (const tuple of credentialsEntry.tuples) {
|
|
238
267
|
const own = tuple.options.environment;
|
|
@@ -269,8 +298,9 @@ function resolveConfig(raw) {
|
|
|
269
298
|
}
|
|
270
299
|
// src/config/compose/merge-sync/merge-sync.ts
|
|
271
300
|
/**
|
|
272
|
-
* Merge two lists of `repo.secrets.sync` entries. An entry is the same sync when its
|
|
273
|
-
* the keys then add up, and an entry that names no keys (every key the vault holds) stays
|
|
301
|
+
* Merge two lists of `repo.secrets.sync` (or `repo.variables.sync`) entries. An entry is the same sync when its
|
|
302
|
+
* environment and scope match; the keys then add up, and an entry that names no keys (every key the vault holds) stays
|
|
303
|
+
* that way.
|
|
274
304
|
*/
|
|
275
305
|
function mergeSync(a, b) {
|
|
276
306
|
const merged = /* @__PURE__ */ new Map();
|
|
@@ -293,7 +323,7 @@ const properties = shallowMerge();
|
|
|
293
323
|
const teamsByKey = mergeByKey((t) => typeof t === "string" ? t : t.slug);
|
|
294
324
|
/**
|
|
295
325
|
* Merge one capability's `repo` fragment onto what earlier ones gave. Scalars: last writer wins. `properties`: shallow
|
|
296
|
-
* merge. `variables`: merged per scope (`repo`, `org`). `secrets`: each name list is a union, and `sync` entries merge by
|
|
326
|
+
* merge. `variables`: merged per scope (`repo`, `org`), and `sync` entries by environment and scope. `secrets`: each name list is a union, and `sync` entries merge by
|
|
297
327
|
* environment and scope. `topics`: union. `teams`: merged by slug.
|
|
298
328
|
*/
|
|
299
329
|
function mergeRepo(prev, next) {
|
|
@@ -313,7 +343,8 @@ function mergeRepo(prev, next) {
|
|
|
313
343
|
...repo.variables?.org || variables.org ? { org: {
|
|
314
344
|
...repo.variables?.org,
|
|
315
345
|
...variables.org
|
|
316
|
-
} } : {}
|
|
346
|
+
} } : {},
|
|
347
|
+
...repo.variables?.sync || variables.sync ? { sync: mergeSync(repo.variables?.sync, variables.sync) } : {}
|
|
317
348
|
};
|
|
318
349
|
if (secrets) {
|
|
319
350
|
const environments = { ...repo.secrets?.environments };
|
|
@@ -390,19 +421,23 @@ async function deriveDefaults$1(found) {
|
|
|
390
421
|
// src/config/load-config/holocron-areas/holocron-areas.ts
|
|
391
422
|
/**
|
|
392
423
|
* The closed list of area files `loadConfig` reads from `.holocron/` (the directory is `.<config name>`, set by kyber):
|
|
393
|
-
* `.holocron/notifications.*` fills `providers.notifications`' `layout`,
|
|
424
|
+
* `.holocron/notifications.*` fills `providers.notifications`' `layout`, `.holocron/repo.*` fills keys of `repo`, and `.holocron/org.*` fills provider options (`teamId`, `accountId`) a config leaves out.
|
|
394
425
|
* A file not on this list is never read.
|
|
395
426
|
*/
|
|
396
|
-
const HOLOCRON_AREAS = [
|
|
427
|
+
const HOLOCRON_AREAS = [
|
|
428
|
+
"notifications",
|
|
429
|
+
"repo",
|
|
430
|
+
"org"
|
|
431
|
+
];
|
|
397
432
|
// src/config/load-config/place-notifications/place-notifications.ts
|
|
398
|
-
const isTuple = (entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && typeof entry[1] === "object" && entry[1] !== null && !Array.isArray(entry[1]);
|
|
399
|
-
const providerName = (entry) => isTuple(entry) ? entry[0] : entry;
|
|
433
|
+
const isTuple$1 = (entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && typeof entry[1] === "object" && entry[1] !== null && !Array.isArray(entry[1]);
|
|
434
|
+
const providerName = (entry) => isTuple$1(entry) ? entry[0] : entry;
|
|
400
435
|
/** Index of the entry the layout belongs to in a multi-provider list: the first `discord`. */
|
|
401
436
|
function findDiscord(entries) {
|
|
402
437
|
return entries.findIndex((entry) => providerName(entry) === "discord");
|
|
403
438
|
}
|
|
404
439
|
function withLayout(entry, layout) {
|
|
405
|
-
return isTuple(entry) ? [entry[0], {
|
|
440
|
+
return isTuple$1(entry) ? [entry[0], {
|
|
406
441
|
...entry[1],
|
|
407
442
|
layout
|
|
408
443
|
}] : [entry, { layout }];
|
|
@@ -418,14 +453,14 @@ function placeNotifications(raw, area) {
|
|
|
418
453
|
const hint = `Set it in one place: remove the inline \`layout\` or delete ${area.path}`;
|
|
419
454
|
let placed;
|
|
420
455
|
if (entry === void 0) throw new ConfigError(`${area.path} holds the notifications layout, but providers.notifications is not set. Add \`notifications: ["discord", { guildId }]\` to providers`);
|
|
421
|
-
else if (Array.isArray(entry) && !isTuple(entry)) {
|
|
456
|
+
else if (Array.isArray(entry) && !isTuple$1(entry)) {
|
|
422
457
|
const index = findDiscord(entry);
|
|
423
458
|
if (index === -1) throw new ConfigError(`${area.path} holds the notifications layout, but providers.notifications has no discord entry`);
|
|
424
459
|
const target = entry[index];
|
|
425
|
-
if (isTuple(target) && target[1].layout !== void 0) throw new ConfigError(`the notifications layout is set in providers.notifications and in ${area.path}. ${hint}`);
|
|
460
|
+
if (isTuple$1(target) && target[1].layout !== void 0) throw new ConfigError(`the notifications layout is set in providers.notifications and in ${area.path}. ${hint}`);
|
|
426
461
|
placed = entry.map((item, i) => i === index ? withLayout(item, area.value) : item);
|
|
427
462
|
} else {
|
|
428
|
-
if (isTuple(entry) && entry[1].layout !== void 0) throw new ConfigError(`the notifications layout is set in providers.notifications and in ${area.path}. ${hint}`);
|
|
463
|
+
if (isTuple$1(entry) && entry[1].layout !== void 0) throw new ConfigError(`the notifications layout is set in providers.notifications and in ${area.path}. ${hint}`);
|
|
429
464
|
placed = withLayout(entry, area.value);
|
|
430
465
|
}
|
|
431
466
|
return {
|
|
@@ -436,6 +471,56 @@ function placeNotifications(raw, area) {
|
|
|
436
471
|
}
|
|
437
472
|
};
|
|
438
473
|
}
|
|
474
|
+
// src/config/load-config/place-org/place-org.ts
|
|
475
|
+
/** The options each provider key of `.holocron/org.*` may hold. Checked against `OrgConfig` by the type. */
|
|
476
|
+
const ORG_OPTIONS = {
|
|
477
|
+
cloudflare: ["accountId"],
|
|
478
|
+
vercel: ["teamId"],
|
|
479
|
+
checkly: ["accountId"]
|
|
480
|
+
};
|
|
481
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
482
|
+
const isTuple = (entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && isObject(entry[1]);
|
|
483
|
+
/** Check the shape of the area file: a closed list of providers, each with a closed list of string options. */
|
|
484
|
+
function validate(area) {
|
|
485
|
+
if (!isObject(area.value)) throw new ConfigError(`${area.path} must export the org settings as an object`);
|
|
486
|
+
for (const [provider, options] of Object.entries(area.value)) {
|
|
487
|
+
const allowed = ORG_OPTIONS[provider];
|
|
488
|
+
if (allowed === void 0) throw new ConfigError(`${area.path} has an unknown provider "${provider}". Known: ${Object.keys(ORG_OPTIONS).join(", ")}`);
|
|
489
|
+
if (!isObject(options)) throw new ConfigError(`${area.path}: "${provider}" must be an object of options`);
|
|
490
|
+
for (const [option, value] of Object.entries(options)) {
|
|
491
|
+
if (!allowed.includes(option)) throw new ConfigError(`${area.path}: "${provider}.${option}" is not an org option. Known: ${allowed.join(", ")}`);
|
|
492
|
+
if (typeof value !== "string" || value === "") throw new ConfigError(`${area.path}: "${provider}.${option}" must be a non-empty string`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return area.value;
|
|
496
|
+
}
|
|
497
|
+
/** Fill one entry when it names a provider the area holds; throws when the config already sets one of its options. */
|
|
498
|
+
function fill(entry, org, capability, path) {
|
|
499
|
+
const [provider, options] = isTuple(entry) ? entry : [entry, {}];
|
|
500
|
+
const values = org[provider];
|
|
501
|
+
if (values === void 0 || Object.keys(values).length === 0) return entry;
|
|
502
|
+
for (const option of Object.keys(values)) if (options[option] !== void 0) throw new ConfigError(`${provider}.${option} is set in providers.${capability} and in ${path}. Set it in one place: remove the inline option or the key from ${path}`);
|
|
503
|
+
return [provider, {
|
|
504
|
+
...options,
|
|
505
|
+
...values
|
|
506
|
+
}];
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Fill the provider options of `.holocron/org.*` into the providers the config uses. A provider entry (a name, a
|
|
510
|
+
* `[name, options]` tuple, or either inside a list) that names a provider the file holds gets each option it leaves
|
|
511
|
+
* out. An option set inline and in the file is a `ConfigError` naming both (no merge, no precedence); a provider the
|
|
512
|
+
* config does not use is ignored; a provider or option the file lists but `OrgConfig` does not know is an error.
|
|
513
|
+
*/
|
|
514
|
+
function placeOrg(raw, area) {
|
|
515
|
+
const org = validate(area);
|
|
516
|
+
if (raw.providers === void 0) return raw;
|
|
517
|
+
const providers = { ...raw.providers };
|
|
518
|
+
for (const [capability, entry] of Object.entries(raw.providers)) providers[capability] = Array.isArray(entry) && !isTuple(entry) ? entry.map((item) => fill(item, org, capability, area.path)) : fill(entry, org, capability, area.path);
|
|
519
|
+
return {
|
|
520
|
+
...raw,
|
|
521
|
+
providers
|
|
522
|
+
};
|
|
523
|
+
}
|
|
439
524
|
// src/config/load-config/place-repo/place-repo.ts
|
|
440
525
|
/**
|
|
441
526
|
* Add the keys of `.holocron/repo.*` to `repo`. The keys of the two sources must differ (`repo.defaultBranch` stays
|
|
@@ -458,13 +543,14 @@ function placeRepo(raw, area) {
|
|
|
458
543
|
// src/config/load-config/place-areas/place-areas.ts
|
|
459
544
|
/**
|
|
460
545
|
* Put the area files of `.holocron/` into the config as loaded, before `deriveDefaults` runs: `notifications` becomes
|
|
461
|
-
* the `layout` of the notifications provider and `repo` supplies keys of `repo
|
|
546
|
+
* the `layout` of the notifications provider and `repo` supplies keys of `repo` and `org` fills the provider options a config leaves out. A value set both inline and in a file
|
|
462
547
|
* is a `ConfigError` naming both (no merge, no precedence). With no area files the config is returned as it was.
|
|
463
548
|
*/
|
|
464
549
|
function placeAreas(areas, raw) {
|
|
465
550
|
let result = raw;
|
|
466
551
|
for (const area of areas) if (area.area === "notifications") result = placeNotifications(result, area);
|
|
467
552
|
else if (area.area === "repo") result = placeRepo(result, area);
|
|
553
|
+
else if (area.area === "org") result = placeOrg(result, area);
|
|
468
554
|
return result;
|
|
469
555
|
}
|
|
470
556
|
// src/config/config-system.ts
|
|
@@ -9517,12 +9603,61 @@ const doctorSecretsCommand = {
|
|
|
9517
9603
|
})).status === "fail") process.exitCode = 1;
|
|
9518
9604
|
}
|
|
9519
9605
|
};
|
|
9606
|
+
// src/commands/doctor-variables/sync-checks.ts
|
|
9607
|
+
/** Re-keys what GitHub holds by the spelling the config declares, since GitHub treats names as case-insensitive. */
|
|
9608
|
+
function bySpelling$1(declared, have) {
|
|
9609
|
+
const spelled = new Map(declared.map((name) => [name.toUpperCase(), name]));
|
|
9610
|
+
return new Map(Object.entries(have).map(([name, value]) => [spelled.get(name.toUpperCase()) ?? name, value]));
|
|
9611
|
+
}
|
|
9612
|
+
/**
|
|
9613
|
+
* The checks `repo.variables.sync` adds to `holocron doctor variables`: one per entry, that every key it lists exists
|
|
9614
|
+
* at its scope. The values live in the vault, which the doctor does not read, so only names (and, for an organization
|
|
9615
|
+
* entry, the visibility it writes) are compared and a value is never shown. A scope that is not `repo` or `org=<name>`
|
|
9616
|
+
* is rejected when the config loads, so it is not handled here.
|
|
9617
|
+
*
|
|
9618
|
+
* @param entries - `repo.variables.sync`, if the config has it.
|
|
9619
|
+
*/
|
|
9620
|
+
function syncVariableChecks(entries) {
|
|
9621
|
+
return (entries ?? []).map((entry) => {
|
|
9622
|
+
const scope = entry.scope ?? "repo";
|
|
9623
|
+
const org = scope.startsWith("org=") ? scope.slice(4) : void 0;
|
|
9624
|
+
return {
|
|
9625
|
+
id: `sync-${entry.environment}-${scope}`,
|
|
9626
|
+
title: `${org === void 0 ? "repository" : `${org} organization`} variables from ${entry.environment} exist`,
|
|
9627
|
+
async run(source) {
|
|
9628
|
+
const checked = entry.keys.length;
|
|
9629
|
+
if (org === void 0) {
|
|
9630
|
+
if (!source.listVariables) return { skip: "provider does not implement listVariables" };
|
|
9631
|
+
const have = bySpelling$1(entry.keys, await source.listVariables());
|
|
9632
|
+
return {
|
|
9633
|
+
problems: declaredVsActual(new Map(entry.keys.map((name) => [name, true])), new Map([...have.keys()].map((name) => [name, true])), {
|
|
9634
|
+
noun: "variable",
|
|
9635
|
+
flagExtra: false
|
|
9636
|
+
}),
|
|
9637
|
+
checked
|
|
9638
|
+
};
|
|
9639
|
+
}
|
|
9640
|
+
if (!source.listOrgVariables) return { skip: "provider does not implement listOrgVariables" };
|
|
9641
|
+
const have = bySpelling$1(entry.keys, await source.listOrgVariables(org));
|
|
9642
|
+
return {
|
|
9643
|
+
problems: declaredVsActual(new Map(entry.keys.map((name) => [name, entry.visibility ?? "all"])), new Map([...have].map(([name, v]) => [name, v.visibility])), {
|
|
9644
|
+
noun: "organization variable",
|
|
9645
|
+
flagExtra: false,
|
|
9646
|
+
show: (visibility) => `visibility ${visibility}`
|
|
9647
|
+
}),
|
|
9648
|
+
checked
|
|
9649
|
+
};
|
|
9650
|
+
}
|
|
9651
|
+
};
|
|
9652
|
+
});
|
|
9653
|
+
}
|
|
9520
9654
|
// src/commands/doctor-variables/doctor-variables.ts
|
|
9521
9655
|
/**
|
|
9522
9656
|
* `holocron doctor variables` — do the Actions variables `repo.variables` declares exist, with those values?
|
|
9523
9657
|
*
|
|
9524
9658
|
* Read-only. One row for the repository's variables and one for the organization's, each only when the config
|
|
9525
|
-
* declares that scope
|
|
9659
|
+
* declares that scope, and one per `repo.variables.sync` entry that checks its names exist (the values are in the
|
|
9660
|
+
* vault, so none is compared or shown). A variable that exists but is not declared is a problem only with `repo.variables.prune`,
|
|
9526
9661
|
* since without it `repo setup` leaves it alone. A scope that cannot be read because there is no provider, the
|
|
9527
9662
|
* provider cannot list variables, or the token is missing is a skip with the reason, not a failure.
|
|
9528
9663
|
*/
|
|
@@ -9568,6 +9703,7 @@ async function runDoctorVariables(input) {
|
|
|
9568
9703
|
};
|
|
9569
9704
|
}
|
|
9570
9705
|
});
|
|
9706
|
+
checks.push(...syncVariableChecks(variables?.sync));
|
|
9571
9707
|
const rows = [];
|
|
9572
9708
|
if (checks.length === 0) rows.push({
|
|
9573
9709
|
id: "variables",
|
|
@@ -20822,6 +20958,9 @@ function restorePem(value) {
|
|
|
20822
20958
|
* entry for this environment gives `secrets` its own keys and scope, one
|
|
20823
20959
|
* step per scope, so one environment can fill organization and repository
|
|
20824
20960
|
* secrets in one run.
|
|
20961
|
+
* - `repo.variables.sync` entries for this environment give Actions variables: each key goes through the `source`
|
|
20962
|
+
* provider's `syncVariables` (repo scope) or `syncOrgVariables`, one call per key, without pruning. An
|
|
20963
|
+
* environment with only variable entries pushes nothing to `secrets` or `deployment`.
|
|
20825
20964
|
* - A key that is blank in the vault is skipped in every destination, and a
|
|
20826
20965
|
* listed key the vault does not hold is a skipped row.
|
|
20827
20966
|
*
|
|
@@ -20890,7 +21029,41 @@ async function runSecretsSync(input) {
|
|
|
20890
21029
|
}
|
|
20891
21030
|
}
|
|
20892
21031
|
}
|
|
20893
|
-
|
|
21032
|
+
const variableRoutes = input.variableRoutes ?? [];
|
|
21033
|
+
if (variableRoutes.length > 0) {
|
|
21034
|
+
const source = loader.has("source") ? loader.get("source") : void 0;
|
|
21035
|
+
for (const route of variableRoutes) {
|
|
21036
|
+
const scope = scopeLabel(route.scope);
|
|
21037
|
+
print(style.step(`variables (${scope})`));
|
|
21038
|
+
const destination = `variables:${source?.providerName ?? "source"}`;
|
|
21039
|
+
const org = route.scope.kind === "organization" ? route.scope.name : void 0;
|
|
21040
|
+
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;
|
|
21041
|
+
if (unsupported) {
|
|
21042
|
+
const row = {
|
|
21043
|
+
destination,
|
|
21044
|
+
scope,
|
|
21045
|
+
key: "(all)",
|
|
21046
|
+
status: "fail",
|
|
21047
|
+
message: unsupported
|
|
21048
|
+
};
|
|
21049
|
+
rows.push(row);
|
|
21050
|
+
print(formatRow(row));
|
|
21051
|
+
continue;
|
|
21052
|
+
}
|
|
21053
|
+
for (const key of route.keys) {
|
|
21054
|
+
rows.push(await pushRow(destination, scope, key, envVars, dryRun, async (value) => {
|
|
21055
|
+
if (org === void 0) await source.syncVariables({ [key]: value }, { prune: false });
|
|
21056
|
+
else await source.syncOrgVariables(org, { [key]: {
|
|
21057
|
+
value,
|
|
21058
|
+
visibility: route.visibility ?? "all"
|
|
21059
|
+
} }, { prune: false });
|
|
21060
|
+
}));
|
|
21061
|
+
print(formatRow(rows[rows.length - 1]));
|
|
21062
|
+
}
|
|
21063
|
+
}
|
|
21064
|
+
}
|
|
21065
|
+
const variablesOnly = variableRoutes.length > 0 && input.secretRoutes?.length === 0 && !input.projectId;
|
|
21066
|
+
if (loader.has("deployment") && !variablesOnly) {
|
|
20894
21067
|
const deploy = loader.get("deployment");
|
|
20895
21068
|
if (!input.projectId) {
|
|
20896
21069
|
print(style.step("deployment"));
|
|
@@ -21034,6 +21207,26 @@ function vaultProviderName(loader) {
|
|
|
21034
21207
|
if (!loader.has("vault")) return "<missing>";
|
|
21035
21208
|
return loader.get("vault").providerName;
|
|
21036
21209
|
}
|
|
21210
|
+
// src/commands/secrets-sync/variable-routes.ts
|
|
21211
|
+
/**
|
|
21212
|
+
* The routes into Actions variables that `repo.variables.sync` declares for one vault environment: every entry naming
|
|
21213
|
+
* it gives its keys and the scope they land at (`repo` when omitted). An environment no entry names has none.
|
|
21214
|
+
*
|
|
21215
|
+
* @param entries - `repo.variables.sync`, if the config has it.
|
|
21216
|
+
* @param environmentId - The vault environment being synced.
|
|
21217
|
+
* @throws When an entry's `scope` is not `repo` or `org=<name>`.
|
|
21218
|
+
*/
|
|
21219
|
+
function variableRoutes(entries, environmentId) {
|
|
21220
|
+
return (entries ?? []).filter((entry) => entry.environment === environmentId).map((entry) => {
|
|
21221
|
+
const scope = parseScope(entry.scope ?? "repo");
|
|
21222
|
+
if (scope.kind === "environment") throw new Error(`invalid variable scope "${entry.scope}" — expected "repo" or "org=<name>"`);
|
|
21223
|
+
return {
|
|
21224
|
+
scope,
|
|
21225
|
+
keys: entry.keys,
|
|
21226
|
+
...entry.visibility ? { visibility: entry.visibility } : {}
|
|
21227
|
+
};
|
|
21228
|
+
});
|
|
21229
|
+
}
|
|
21037
21230
|
// src/commands/secrets-sync/secrets-sync.args.ts
|
|
21038
21231
|
const secretsSyncArgs = (y) => y.positional("environmentId", {
|
|
21039
21232
|
type: "string",
|
|
@@ -21069,6 +21262,8 @@ const secretsSyncCommand = {
|
|
|
21069
21262
|
const loaded = await loadConfig(argv.cwd);
|
|
21070
21263
|
applyResolvedConfig(argv, loaded.resolved);
|
|
21071
21264
|
const routes = argv.githubSecret?.length ? [] : secretRoutes(loaded.resolved.repo?.secrets?.sync, environmentId);
|
|
21265
|
+
const variables = variableRoutes(loaded.resolved.repo?.variables?.sync, environmentId);
|
|
21266
|
+
const variablesOnly = variables.length > 0 && routes.length === 0 && !argv.githubSecret?.length;
|
|
21072
21267
|
if ((await runSecretsSync({
|
|
21073
21268
|
loaded,
|
|
21074
21269
|
context: {
|
|
@@ -21082,7 +21277,8 @@ const secretsSyncCommand = {
|
|
|
21082
21277
|
...argv.worker ? { workerScript: argv.worker } : {},
|
|
21083
21278
|
...argv.githubSecret?.length ? { githubSecretKeys: argv.githubSecret } : {},
|
|
21084
21279
|
githubSecretScope,
|
|
21085
|
-
...routes.length ? { secretRoutes: routes } : {},
|
|
21280
|
+
...routes.length ? { secretRoutes: routes } : variablesOnly ? { secretRoutes: [] } : {},
|
|
21281
|
+
...variables.length ? { variableRoutes: variables } : {},
|
|
21086
21282
|
targets: argv.target
|
|
21087
21283
|
})).summary.fail > 0) process.exitCode = 1;
|
|
21088
21284
|
}
|