@theholocron/cli 5.0.0-alpha.537 → 5.0.0-alpha.539
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 +31 -0
- package/dist/cli.mjs +519 -96
- package/dist/cli.mjs.map +1 -1
- package/package.json +16 -16
package/dist/cli.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { homedir, tmpdir } from "node:os";
|
|
4
4
|
import path, { basename, dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
|
|
5
|
-
import { PREFIX as PREFIX$1, createEnvLookup, detectEnvironment, firstEnv, holocronEnv } from "@theholocron/env-utils/lookup";
|
|
5
|
+
import { PREFIX as PREFIX$1, createEnvLookup, detectEnvironment, environment, firstEnv, holocronEnv } from "@theholocron/env-utils/lookup";
|
|
6
6
|
import { ProviderApiError, ProviderApiError as ProviderApiError$1, createRestClient, onRetry } from "@theholocron/http-client";
|
|
7
7
|
import { addGlobalOptions, groupMenu as groupMenu$1, tokenContext as tokenContext$1 } from "@theholocron/kyber/flags";
|
|
8
8
|
import { checkForUpdates } from "@theholocron/kyber/notifier";
|
|
@@ -411,7 +411,11 @@ const deployEntry = {
|
|
|
411
411
|
default: "production",
|
|
412
412
|
message: "Named environment to deploy into (leave the option off for a branch preview):"
|
|
413
413
|
}],
|
|
414
|
-
skipOptions: [
|
|
414
|
+
skipOptions: [
|
|
415
|
+
"files",
|
|
416
|
+
"env",
|
|
417
|
+
"environment"
|
|
418
|
+
],
|
|
415
419
|
supportsDryRun: true
|
|
416
420
|
};
|
|
417
421
|
// src/commands/deploy/deploy-on-release.entry.ts
|
|
@@ -2011,7 +2015,11 @@ const syncEntry = {
|
|
|
2011
2015
|
name: "sync",
|
|
2012
2016
|
description: "Sync state from config to the provider and local files (labels, properties, teams, topics, keywords, description, homepage, readme, workflows, scripts, wiki)",
|
|
2013
2017
|
positionals: [],
|
|
2014
|
-
skipOptions: [
|
|
2018
|
+
skipOptions: [
|
|
2019
|
+
"repo",
|
|
2020
|
+
"env",
|
|
2021
|
+
"environment"
|
|
2022
|
+
],
|
|
2015
2023
|
supportsDryRun: true
|
|
2016
2024
|
};
|
|
2017
2025
|
// src/commands/sync-github/sync-github.entry.ts
|
|
@@ -3657,7 +3665,7 @@ function placeAreas(areas, raw) {
|
|
|
3657
3665
|
return result;
|
|
3658
3666
|
}
|
|
3659
3667
|
// src/credentials-environments/environment-layers/environment-layers.ts
|
|
3660
|
-
/** The suffix each layer's Environment carries: `<org/repo> - <suffix>`. `test`
|
|
3668
|
+
/** The suffix each layer's Environment carries: `<org/repo> - <suffix>`. `test` and `preview` have none. */
|
|
3661
3669
|
const SUFFIX = {
|
|
3662
3670
|
local: "local",
|
|
3663
3671
|
development: "dev",
|
|
@@ -3667,11 +3675,11 @@ const SUFFIX = {
|
|
|
3667
3675
|
/**
|
|
3668
3676
|
* The Environments a layer reads, in the order they are tried (#2063, #2058). A machine (`local`) reads
|
|
3669
3677
|
* `<slug> - local` and then `<slug> - dev`: that is the only fallback there is. `development` reads `- dev`, `ci`
|
|
3670
|
-
* reads `- ci` and `production` reads `- prod`; a missing name is a missing name. `test`
|
|
3678
|
+
* reads `- ci` and `production` reads `- prod`; a missing name is a missing name. `test` and `preview` read none (a preview deployment gets its values from the deployment, not from a vault). Only `- local`
|
|
3671
3679
|
* is optional.
|
|
3672
3680
|
*/
|
|
3673
3681
|
function environmentLayers(slug, layer) {
|
|
3674
|
-
if (layer === "test") return [];
|
|
3682
|
+
if (layer === "test" || layer === "preview") return [];
|
|
3675
3683
|
const candidate = (suffix, optional) => ({
|
|
3676
3684
|
name: layerEnvironment(slug, suffix),
|
|
3677
3685
|
optional
|
|
@@ -10149,7 +10157,7 @@ const deployStageCommand = {
|
|
|
10149
10157
|
// src/commands/deploy/deploy.args.ts
|
|
10150
10158
|
const deployArgs = (y) => y.positional("branch", {
|
|
10151
10159
|
type: "string",
|
|
10152
|
-
describe: "Git branch to deploy (omit when using --files)"
|
|
10160
|
+
describe: "Git branch to deploy, or a workspace app's name with --env (omit when using --files)"
|
|
10153
10161
|
}).option("project-id", {
|
|
10154
10162
|
type: "string",
|
|
10155
10163
|
describe: "Deployment project id (required to trigger a deployment, e.g. Vercel prj_*)"
|
|
@@ -10157,57 +10165,276 @@ const deployArgs = (y) => y.positional("branch", {
|
|
|
10157
10165
|
type: "string",
|
|
10158
10166
|
choices: ["production", "staging"],
|
|
10159
10167
|
describe: "Named environment to deploy into. Omit for a branch preview."
|
|
10168
|
+
}).option("env", {
|
|
10169
|
+
type: "string",
|
|
10170
|
+
array: true,
|
|
10171
|
+
nargs: 1,
|
|
10172
|
+
alias: "environment",
|
|
10173
|
+
global: false,
|
|
10174
|
+
describe: "Deploy a workspace app by name (`deploy <app> --env production`): an environment to deploy to, `production` or `preview`; repeat the flag for both. The app is found under the workspace; from inside its folder the name may be left off."
|
|
10160
10175
|
}).option("files", {
|
|
10161
10176
|
type: "string",
|
|
10162
10177
|
describe: "Deploy from a local directory of source files instead of a Git branch — calls deployFunction(), no linked repo required. Conflicts with `branch`."
|
|
10163
10178
|
}).conflicts("files", "branch");
|
|
10164
|
-
// src/commands/
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
|
|
10170
|
-
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
}
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
}
|
|
10183
|
-
|
|
10184
|
-
|
|
10185
|
-
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10189
|
-
|
|
10190
|
-
|
|
10191
|
-
|
|
10192
|
-
|
|
10193
|
-
|
|
10194
|
-
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
|
|
10198
|
-
|
|
10199
|
-
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
|
|
10179
|
+
// src/commands/app-domain-check/app-domain-check.ts
|
|
10180
|
+
/**
|
|
10181
|
+
* Checks that the deployment project `project` serves `domain`, the one the app's own config names, so a name that does
|
|
10182
|
+
* not belong to the app stops the command before anything is written. A provider that cannot list a project's domains,
|
|
10183
|
+
* or an app that declares no domain, is `skipped` with the reason, never a failure.
|
|
10184
|
+
*
|
|
10185
|
+
* @param deployment - The app's `deployment` capability.
|
|
10186
|
+
* @param project - The project name (the app folder's name).
|
|
10187
|
+
* @param domain - The app's configured domain, when it has one.
|
|
10188
|
+
*/
|
|
10189
|
+
async function checkProjectDomain(deployment, project, domain) {
|
|
10190
|
+
if (!domain) return {
|
|
10191
|
+
status: "skipped",
|
|
10192
|
+
message: `no \`domain\` in the app's config, so ${project}'s domain was not checked`
|
|
10193
|
+
};
|
|
10194
|
+
if (!deployment.listDomains) return {
|
|
10195
|
+
status: "skipped",
|
|
10196
|
+
message: `${deployment.providerName} cannot list a project's domains, so ${project}'s domain was not checked`
|
|
10197
|
+
};
|
|
10198
|
+
let served;
|
|
10199
|
+
try {
|
|
10200
|
+
served = await deployment.listDomains(project);
|
|
10201
|
+
} catch (err) {
|
|
10202
|
+
return {
|
|
10203
|
+
status: "fail",
|
|
10204
|
+
message: `cannot read the domains of ${deployment.providerName} project "${project}": ${errorMessage(err)}`
|
|
10205
|
+
};
|
|
10206
|
+
}
|
|
10207
|
+
if (served.includes(domain)) return {
|
|
10208
|
+
status: "ok",
|
|
10209
|
+
message: `${project} serves ${domain}`
|
|
10210
|
+
};
|
|
10211
|
+
return {
|
|
10212
|
+
status: "fail",
|
|
10213
|
+
message: `${deployment.providerName} project "${project}" does not serve ${domain} (it serves ${served.length ? served.join(", ") : "no domain"}); nothing was written`
|
|
10214
|
+
};
|
|
10215
|
+
}
|
|
10216
|
+
// src/commands/app-plan/app-plan.ts
|
|
10217
|
+
/**
|
|
10218
|
+
* Reads what an app's own config declares: its `deployment` and `workers` providers and whether `repo.secrets.deploy`
|
|
10219
|
+
* lists anything. An app is classified by this, never by its name, so a new app needs no change here; an app with no
|
|
10220
|
+
* config declares nothing.
|
|
10221
|
+
*
|
|
10222
|
+
* @param config - The app's resolved config, if it has one.
|
|
10223
|
+
*/
|
|
10224
|
+
function appPlan(config) {
|
|
10225
|
+
const deployment = config?.providers.deployment;
|
|
10226
|
+
const workers = config?.providers.workers;
|
|
10227
|
+
const deploy = config?.repo?.secrets?.deploy;
|
|
10228
|
+
return {
|
|
10229
|
+
...deployment?.cardinality === "single" ? { deployment: deployment.tuple } : {},
|
|
10230
|
+
...workers?.cardinality === "single" ? { workers: workers.tuple } : {},
|
|
10231
|
+
deployKeys: (deploy?.length ?? 0) > 0
|
|
10232
|
+
};
|
|
10233
|
+
}
|
|
10234
|
+
// src/commands/app-deploy/app-deploy.ts
|
|
10235
|
+
/**
|
|
10236
|
+
* `holocron deploy <app> --env <env>`: builds the app, stages it and deploys the staged files to the project that takes
|
|
10237
|
+
* the app folder's name, once for each environment `--env` names (production, then preview). Before anything is written the
|
|
10238
|
+
* project must serve the app's configured `domain`. An app with no `deployment` provider has nothing to deploy and is
|
|
10239
|
+
* reported, not failed (Comlink's Worker is made by `setup notifications`; Council is installed by hand).
|
|
10240
|
+
*
|
|
10241
|
+
* @param input - The app, the environment, its loaded config and the seams tests replace.
|
|
10242
|
+
*/
|
|
10243
|
+
async function runAppDeploy(input) {
|
|
10244
|
+
const { app, env } = input;
|
|
10245
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
10246
|
+
const fail = (message) => {
|
|
10247
|
+
print(` ${style.fail(message)}`);
|
|
10248
|
+
return {
|
|
10249
|
+
status: "fail",
|
|
10250
|
+
message
|
|
10251
|
+
};
|
|
10252
|
+
};
|
|
10253
|
+
if (app.configError) return fail(`${app.name}: its holocron.config cannot be read: ${app.configError}`);
|
|
10254
|
+
const plan = appPlan(app.config);
|
|
10255
|
+
if (!plan.deployment) {
|
|
10256
|
+
const message = plan.workers ? `${app.name}: its Worker is deployed by \`holocron setup notifications\`, which has the channel webhooks it needs; nothing to do here` : `${app.name}: no deployment is configured; nothing to do`;
|
|
10257
|
+
print(` ${style.dim(message)}`);
|
|
10258
|
+
return {
|
|
10259
|
+
status: "nothing",
|
|
10260
|
+
message
|
|
10261
|
+
};
|
|
10262
|
+
}
|
|
10263
|
+
const { loaded, context, loader } = await input.load();
|
|
10264
|
+
const dryRun = Boolean(context.dryRun);
|
|
10265
|
+
print(style.header(`Holocron deploy ${app.name} → ${env.targets.join(" + ")}${dryRun ? " (dry-run)" : ""}`));
|
|
10266
|
+
await loader.load();
|
|
10267
|
+
if (!loader.has("deployment")) return fail(`${app.name}: the deployment provider did not load`);
|
|
10268
|
+
const domain = plan.deployment.options.domain;
|
|
10269
|
+
const checked = await checkProjectDomain(loader.get("deployment"), app.name, typeof domain === "string" ? domain : void 0);
|
|
10270
|
+
if (checked.status === "fail") return fail(checked.message);
|
|
10271
|
+
print(` ${style.dim(checked.message)}`);
|
|
10272
|
+
if (dryRun) {
|
|
10273
|
+
const message = `would: build and stage ${app.path}, then deploy it to ${app.name} (${env.targets.join(" + ")})`;
|
|
10274
|
+
print(` ${style.dim(`… ${message}`)}`);
|
|
10275
|
+
return {
|
|
10276
|
+
status: "dry-run",
|
|
10277
|
+
message
|
|
10278
|
+
};
|
|
10279
|
+
}
|
|
10280
|
+
const built = input.build(app.dir);
|
|
10281
|
+
if (built.status === "fail") return fail(built.message);
|
|
10282
|
+
const staged = input.stage({
|
|
10283
|
+
packageDir: app.dir,
|
|
10284
|
+
print
|
|
10285
|
+
});
|
|
10286
|
+
if (staged.status === "fail" || !staged.outDir) return fail(`stage: ${staged.message ?? "no payload was made"}`);
|
|
10287
|
+
for (const target of env.targets) {
|
|
10288
|
+
const report = await input.deployFiles({
|
|
10289
|
+
loaded,
|
|
10290
|
+
context,
|
|
10291
|
+
projectId: app.name,
|
|
10292
|
+
dir: staged.outDir,
|
|
10293
|
+
...target === "production" ? { target: "production" } : {},
|
|
10294
|
+
loader,
|
|
10207
10295
|
print
|
|
10208
|
-
})
|
|
10296
|
+
});
|
|
10297
|
+
if (report.status === "fail") return fail(`${target}: ${report.message ?? "the deployment failed"}`);
|
|
10209
10298
|
}
|
|
10210
|
-
|
|
10299
|
+
return {
|
|
10300
|
+
status: "ok",
|
|
10301
|
+
message: `${app.name} deployed to ${env.targets.join(" + ")}`
|
|
10302
|
+
};
|
|
10303
|
+
}
|
|
10304
|
+
// src/commands/app-env/app-env.ts
|
|
10305
|
+
/** The environments an app is deployed to, in the order they are written. */
|
|
10306
|
+
const APP_TARGETS = ["production", "preview"];
|
|
10307
|
+
/**
|
|
10308
|
+
* Reads the `--env` of `deploy <app>` and `sync <app>`: the standard environments of `@theholocron/env-utils`
|
|
10309
|
+
* (`environment.normalize()`, so `prod` is `production`), the flag repeated for more than one. An app is deployed to
|
|
10310
|
+
* `production` and `preview`; both take their secrets from the `prod` vault layer. Any other environment is refused with
|
|
10311
|
+
* the reason: `local`, `development` and `ci` are never synced or deployed to, and `test` has no deployment target.
|
|
10312
|
+
*
|
|
10313
|
+
* @param values - The `--env` (or `--environment`) values, one or several.
|
|
10314
|
+
* @throws {ConfigError} For no value, an unknown name or an environment an app is not deployed to.
|
|
10315
|
+
*/
|
|
10316
|
+
function parseAppEnv(values) {
|
|
10317
|
+
const given = (values === void 0 ? [] : [values].flat()).filter((value) => value !== "");
|
|
10318
|
+
if (given.length === 0) throw new ConfigError$1("pass --env production or --env preview (repeat the flag for both) to say where to write");
|
|
10319
|
+
const wanted = /* @__PURE__ */ new Set();
|
|
10320
|
+
for (const value of given) {
|
|
10321
|
+
const normalized = environment.normalize(value);
|
|
10322
|
+
if (normalized === void 0) throw new ConfigError$1(`unknown --env "${value}" (accepted: ${APP_TARGETS.join(", ")})`);
|
|
10323
|
+
if (normalized !== "production" && normalized !== "preview") throw new ConfigError$1(`--env ${value} is not an environment an app is deployed or synced to (accepted: ${APP_TARGETS.join(", ")}); \`sync secrets --env ci\` fills GitHub Actions`);
|
|
10324
|
+
wanted.add(normalized);
|
|
10325
|
+
}
|
|
10326
|
+
return {
|
|
10327
|
+
layer: "prod",
|
|
10328
|
+
targets: APP_TARGETS.filter((target) => wanted.has(target))
|
|
10329
|
+
};
|
|
10330
|
+
}
|
|
10331
|
+
// src/commands/build-app/build-app.ts
|
|
10332
|
+
/**
|
|
10333
|
+
* Runs the app's own `build` script (`pnpm run build`) in its folder, with output shown. An app with no `build` script
|
|
10334
|
+
* is not an error: there is nothing to build.
|
|
10335
|
+
*
|
|
10336
|
+
* @param dir - The app's absolute folder.
|
|
10337
|
+
*/
|
|
10338
|
+
function buildApp(dir) {
|
|
10339
|
+
const manifest = join(dir, "package.json");
|
|
10340
|
+
if (!existsSync(manifest)) return { status: "none" };
|
|
10341
|
+
if (!JSON.parse(readFileSync(manifest, "utf8")).scripts?.build) return { status: "none" };
|
|
10342
|
+
const run = spawnSync("pnpm", ["run", "build"], {
|
|
10343
|
+
cwd: dir,
|
|
10344
|
+
stdio: "inherit"
|
|
10345
|
+
});
|
|
10346
|
+
if (run.status === 0) return { status: "built" };
|
|
10347
|
+
return {
|
|
10348
|
+
status: "fail",
|
|
10349
|
+
message: `\`pnpm run build\` failed in ${dir}${run.error ? `: ${run.error.message}` : ` (exit ${run.status ?? "signal"})`}`
|
|
10350
|
+
};
|
|
10351
|
+
}
|
|
10352
|
+
// src/commands/workspace-configs/workspace-configs.ts
|
|
10353
|
+
/** The extensions a `holocron.config` can have. */
|
|
10354
|
+
const CONFIG_EXTENSIONS$1 = [
|
|
10355
|
+
"ts",
|
|
10356
|
+
"js",
|
|
10357
|
+
"mjs",
|
|
10358
|
+
"cjs",
|
|
10359
|
+
"json"
|
|
10360
|
+
];
|
|
10361
|
+
/**
|
|
10362
|
+
* The config of every workspace package that has a `holocron.config.*` of its own (`apps/sentinel`, `apps/comlink`), in
|
|
10363
|
+
* workspace order. A package whose config cannot be loaded is still listed, with the reason, so a caller decides whether
|
|
10364
|
+
* leaving it out is safe (`workspaceProviders()` does, `readWorkspaceMonitoring()` does not). Where the workspace itself
|
|
10365
|
+
* cannot be read (no `pnpm-workspace.yaml`, a bad one) there are none. Nothing is written and no provider is loaded.
|
|
10366
|
+
*/
|
|
10367
|
+
async function readWorkspaceConfigs(repoRoot) {
|
|
10368
|
+
let packages;
|
|
10369
|
+
try {
|
|
10370
|
+
packages = readWorkspacePackages(repoRoot);
|
|
10371
|
+
} catch {
|
|
10372
|
+
return [];
|
|
10373
|
+
}
|
|
10374
|
+
const found = [];
|
|
10375
|
+
for (const pkg of packages) {
|
|
10376
|
+
const path = pkg.path ?? `${pkg.dir}/${pkg.slug}`;
|
|
10377
|
+
const dir = join(repoRoot, path);
|
|
10378
|
+
if (!CONFIG_EXTENSIONS$1.some((ext) => existsSync(join(dir, `holocron.config.${ext}`)))) continue;
|
|
10379
|
+
try {
|
|
10380
|
+
found.push({
|
|
10381
|
+
path,
|
|
10382
|
+
dir,
|
|
10383
|
+
resolved: (await loadConfig(dir)).resolved
|
|
10384
|
+
});
|
|
10385
|
+
} catch (err) {
|
|
10386
|
+
found.push({
|
|
10387
|
+
path,
|
|
10388
|
+
dir,
|
|
10389
|
+
error: errorMessage(err)
|
|
10390
|
+
});
|
|
10391
|
+
}
|
|
10392
|
+
}
|
|
10393
|
+
return found;
|
|
10394
|
+
}
|
|
10395
|
+
// src/commands/resolve-app/resolve-app.ts
|
|
10396
|
+
/** The workspace group an app lives in. */
|
|
10397
|
+
const APPS_DIR = "apps";
|
|
10398
|
+
/**
|
|
10399
|
+
* Finds an app under the workspace: by `name` (the app folder's name), or, with no name, the app whose folder holds
|
|
10400
|
+
* `cwd`. It works from the repository root or from inside an app, because the workspace is found by walking up from
|
|
10401
|
+
* `cwd`. Nothing is written and no provider is loaded; an app with a `holocron.config` carries it, one that has none
|
|
10402
|
+
* (Council) carries none, and one whose config cannot be read carries the reason.
|
|
10403
|
+
*
|
|
10404
|
+
* @param name - The app's name, or `undefined` to use the app `cwd` is inside.
|
|
10405
|
+
* @param cwd - The folder the command runs in.
|
|
10406
|
+
*/
|
|
10407
|
+
async function resolveApp(name, cwd) {
|
|
10408
|
+
const repoRoot = findRootSync(cwd, "pnpm-workspace.yaml", { fallback: "start" });
|
|
10409
|
+
let packages;
|
|
10410
|
+
try {
|
|
10411
|
+
packages = readWorkspacePackages(repoRoot);
|
|
10412
|
+
} catch {
|
|
10413
|
+
packages = [];
|
|
10414
|
+
}
|
|
10415
|
+
const configs = new Map((await readWorkspaceConfigs(repoRoot)).map((c) => [c.path, c]));
|
|
10416
|
+
const apps = [];
|
|
10417
|
+
for (const pkg of packages) {
|
|
10418
|
+
const path = packageLocation(pkg);
|
|
10419
|
+
const [group, folder, ...deeper] = path.split("/");
|
|
10420
|
+
if (group !== APPS_DIR || !folder || deeper.length > 0) continue;
|
|
10421
|
+
const found = configs.get(path);
|
|
10422
|
+
apps.push({
|
|
10423
|
+
name: folder,
|
|
10424
|
+
path,
|
|
10425
|
+
dir: join(repoRoot, path),
|
|
10426
|
+
...found && "resolved" in found ? { config: found.resolved } : {},
|
|
10427
|
+
...found && "error" in found ? { configError: found.error } : {}
|
|
10428
|
+
});
|
|
10429
|
+
}
|
|
10430
|
+
const here = resolve(cwd);
|
|
10431
|
+
const app = name === void 0 ? apps.find((a) => here === a.dir || here.startsWith(a.dir + sep)) : apps.find((a) => a.name === name);
|
|
10432
|
+
return {
|
|
10433
|
+
repoRoot,
|
|
10434
|
+
...app ? { app } : {},
|
|
10435
|
+
names: apps.map((a) => a.name)
|
|
10436
|
+
};
|
|
10437
|
+
}
|
|
10211
10438
|
// src/commands/deploy/deploy.ts
|
|
10212
10439
|
/**
|
|
10213
10440
|
* `holocron deploy` — trigger a deployment via the configured
|
|
@@ -10474,6 +10701,106 @@ async function runDeployFromFiles(input) {
|
|
|
10474
10701
|
};
|
|
10475
10702
|
}
|
|
10476
10703
|
}
|
|
10704
|
+
// src/commands/deploy/deploy-app.ts
|
|
10705
|
+
/**
|
|
10706
|
+
* The `deploy <app> --env <env>` path of the `deploy` command (spec `tool-app-deploy-sync`). Returns `false` when the
|
|
10707
|
+
* arguments do not name an app (no `--env`, and the value is not an app's name), so the command goes on to deploy a
|
|
10708
|
+
* branch as it always has; `true` once it has handled the run, setting a failing exit code on an error.
|
|
10709
|
+
*
|
|
10710
|
+
* @param argv - The parsed arguments of `holocron deploy`.
|
|
10711
|
+
*/
|
|
10712
|
+
async function deployApp(argv) {
|
|
10713
|
+
const lookup = await resolveApp(argv.branch, argv.cwd);
|
|
10714
|
+
const { app } = lookup;
|
|
10715
|
+
if (!app && argv.env === void 0) return false;
|
|
10716
|
+
const fail = (message) => {
|
|
10717
|
+
reportError(`deploy: ${message}`);
|
|
10718
|
+
process.exitCode = 1;
|
|
10719
|
+
return true;
|
|
10720
|
+
};
|
|
10721
|
+
if (!app) {
|
|
10722
|
+
const names = lookup.names.length ? lookup.names.join(", ") : "none found";
|
|
10723
|
+
return fail(argv.branch ? `no app named "${argv.branch}" in this workspace (apps: ${names})` : `name an app, or run it from inside one (apps: ${names})`);
|
|
10724
|
+
}
|
|
10725
|
+
let env;
|
|
10726
|
+
try {
|
|
10727
|
+
env = parseAppEnv(argv.env);
|
|
10728
|
+
} catch (err) {
|
|
10729
|
+
return fail(errorMessage(err));
|
|
10730
|
+
}
|
|
10731
|
+
const tokens = tokenContext(argv.token);
|
|
10732
|
+
if (!tokens) return true;
|
|
10733
|
+
if ((await runAppDeploy({
|
|
10734
|
+
app,
|
|
10735
|
+
env,
|
|
10736
|
+
load: async () => {
|
|
10737
|
+
const loaded = await loadConfig(app.dir);
|
|
10738
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
10739
|
+
const context = {
|
|
10740
|
+
repoRoot: app.dir,
|
|
10741
|
+
dryRun: argv.dryRun,
|
|
10742
|
+
...tokens,
|
|
10743
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
10744
|
+
};
|
|
10745
|
+
return {
|
|
10746
|
+
loaded,
|
|
10747
|
+
context,
|
|
10748
|
+
loader: new PluginLoader(loaded.resolved, context)
|
|
10749
|
+
};
|
|
10750
|
+
},
|
|
10751
|
+
build: buildApp,
|
|
10752
|
+
stage: stageDeploy,
|
|
10753
|
+
deployFiles: runDeployFromFiles
|
|
10754
|
+
})).status === "fail") process.exitCode = 1;
|
|
10755
|
+
return true;
|
|
10756
|
+
}
|
|
10757
|
+
// src/commands/deploy/deploy-on-release.args.ts
|
|
10758
|
+
const deployOnReleaseArgs = (y) => y.option("channel", {
|
|
10759
|
+
type: "string",
|
|
10760
|
+
default: "",
|
|
10761
|
+
describe: "The release's channel: its prerelease identifier (`alpha`); empty or `main` for a stable release."
|
|
10762
|
+
}).option("from", {
|
|
10763
|
+
type: "string",
|
|
10764
|
+
describe: "The previous release's commit, to diff against. Omit when there is none."
|
|
10765
|
+
}).option("to", {
|
|
10766
|
+
type: "string",
|
|
10767
|
+
describe: "The release commit. Default HEAD."
|
|
10768
|
+
}).option("record-file", {
|
|
10769
|
+
type: "string",
|
|
10770
|
+
describe: "A file the deploy lists the packages it deployed in (and `--record` reads), so a later step tags them."
|
|
10771
|
+
}).option("record", {
|
|
10772
|
+
type: "boolean",
|
|
10773
|
+
default: false,
|
|
10774
|
+
describe: "Tag and push the `deployed/<package>` marker of each package in --record-file, using GITHUB_TOKEN. Deploys nothing."
|
|
10775
|
+
});
|
|
10776
|
+
// src/commands/deploy/deploy-on-release.command.ts
|
|
10777
|
+
const deployOnReleaseCommand = {
|
|
10778
|
+
command: "on-release",
|
|
10779
|
+
describe: "Deploy every workspace package whose delivery.deploy task is `on: release` — run by the delivery.publish workflow's deploy job",
|
|
10780
|
+
builder: deployOnReleaseArgs,
|
|
10781
|
+
handler: async (argv) => {
|
|
10782
|
+
const print = (line) => console.log(line);
|
|
10783
|
+
if (argv.record) {
|
|
10784
|
+
if (recordDeploys({
|
|
10785
|
+
cwd: argv.cwd,
|
|
10786
|
+
file: argv.recordFile ?? "",
|
|
10787
|
+
token: createEnvLookup().get("GITHUB_TOKEN"),
|
|
10788
|
+
dryRun: argv.dryRun,
|
|
10789
|
+
print
|
|
10790
|
+
}).status === "fail") process.exitCode = 1;
|
|
10791
|
+
return;
|
|
10792
|
+
}
|
|
10793
|
+
if ((await deployOnRelease({
|
|
10794
|
+
cwd: argv.cwd,
|
|
10795
|
+
channel: argv.channel,
|
|
10796
|
+
...argv.from ? { from: argv.from } : {},
|
|
10797
|
+
...argv.to ? { to: argv.to } : {},
|
|
10798
|
+
...argv.recordFile ? { recordFile: argv.recordFile } : {},
|
|
10799
|
+
dryRun: argv.dryRun,
|
|
10800
|
+
print
|
|
10801
|
+
})).status === "fail") process.exitCode = 1;
|
|
10802
|
+
}
|
|
10803
|
+
};
|
|
10477
10804
|
// src/commands/deploy/deploy.command.ts
|
|
10478
10805
|
const env$6 = createEnvLookup();
|
|
10479
10806
|
const deployCommand = {
|
|
@@ -10481,6 +10808,9 @@ const deployCommand = {
|
|
|
10481
10808
|
describe: "Trigger a deployment via the configured `deployment` capability",
|
|
10482
10809
|
builder: (y) => deployArgs(y).command(cleanupPreviewCommand).command(deployOnReleaseCommand).command(deployStageCommand),
|
|
10483
10810
|
handler: async (argv) => {
|
|
10811
|
+
if (!argv.files && !argv.projectId && (argv.env !== void 0 || argv.branch !== void 0)) {
|
|
10812
|
+
if (await deployApp(argv)) return;
|
|
10813
|
+
}
|
|
10484
10814
|
if (!argv.projectId) {
|
|
10485
10815
|
reportError("deploy: missing required argument --project-id");
|
|
10486
10816
|
process.exitCode = 1;
|
|
@@ -12635,49 +12965,6 @@ const doctorLogsCommand = {
|
|
|
12635
12965
|
})).status === "fail") process.exitCode = 1;
|
|
12636
12966
|
}
|
|
12637
12967
|
};
|
|
12638
|
-
// src/commands/workspace-configs/workspace-configs.ts
|
|
12639
|
-
/** The extensions a `holocron.config` can have. */
|
|
12640
|
-
const CONFIG_EXTENSIONS$1 = [
|
|
12641
|
-
"ts",
|
|
12642
|
-
"js",
|
|
12643
|
-
"mjs",
|
|
12644
|
-
"cjs",
|
|
12645
|
-
"json"
|
|
12646
|
-
];
|
|
12647
|
-
/**
|
|
12648
|
-
* The config of every workspace package that has a `holocron.config.*` of its own (`apps/sentinel`, `apps/comlink`), in
|
|
12649
|
-
* workspace order. A package whose config cannot be loaded is still listed, with the reason, so a caller decides whether
|
|
12650
|
-
* leaving it out is safe (`workspaceProviders()` does, `readWorkspaceMonitoring()` does not). Where the workspace itself
|
|
12651
|
-
* cannot be read (no `pnpm-workspace.yaml`, a bad one) there are none. Nothing is written and no provider is loaded.
|
|
12652
|
-
*/
|
|
12653
|
-
async function readWorkspaceConfigs(repoRoot) {
|
|
12654
|
-
let packages;
|
|
12655
|
-
try {
|
|
12656
|
-
packages = readWorkspacePackages(repoRoot);
|
|
12657
|
-
} catch {
|
|
12658
|
-
return [];
|
|
12659
|
-
}
|
|
12660
|
-
const found = [];
|
|
12661
|
-
for (const pkg of packages) {
|
|
12662
|
-
const path = pkg.path ?? `${pkg.dir}/${pkg.slug}`;
|
|
12663
|
-
const dir = join(repoRoot, path);
|
|
12664
|
-
if (!CONFIG_EXTENSIONS$1.some((ext) => existsSync(join(dir, `holocron.config.${ext}`)))) continue;
|
|
12665
|
-
try {
|
|
12666
|
-
found.push({
|
|
12667
|
-
path,
|
|
12668
|
-
dir,
|
|
12669
|
-
resolved: (await loadConfig(dir)).resolved
|
|
12670
|
-
});
|
|
12671
|
-
} catch (err) {
|
|
12672
|
-
found.push({
|
|
12673
|
-
path,
|
|
12674
|
-
dir,
|
|
12675
|
-
error: errorMessage(err)
|
|
12676
|
-
});
|
|
12677
|
-
}
|
|
12678
|
-
}
|
|
12679
|
-
return found;
|
|
12680
|
-
}
|
|
12681
12968
|
// src/commands/workspace-monitoring/workspace-monitoring.ts
|
|
12682
12969
|
/**
|
|
12683
12970
|
* The checks, dashboards and status pages the workspace packages' configs declare, read through the `monitoring`
|
|
@@ -37658,18 +37945,154 @@ async function readExistingWorkflowFile(repoRoot, filename) {
|
|
|
37658
37945
|
const syncArgs = (y) => y.positional("steps", {
|
|
37659
37946
|
type: "string",
|
|
37660
37947
|
array: true,
|
|
37661
|
-
describe: "Steps to run: labels, properties, teams, topics, keywords, description, homepage, readme, workflows, scripts, wiki (default: all)"
|
|
37948
|
+
describe: "Steps to run: labels, properties, teams, topics, keywords, description, homepage, readme, workflows, scripts, wiki (default: all); or a workspace app's name with --env"
|
|
37949
|
+
}).option("env", {
|
|
37950
|
+
type: "string",
|
|
37951
|
+
array: true,
|
|
37952
|
+
nargs: 1,
|
|
37953
|
+
alias: "environment",
|
|
37954
|
+
global: false,
|
|
37955
|
+
describe: "Sync a workspace app's secrets by name (`sync <app> --env production`): an environment to write to, `production` or `preview`; repeat the flag for both. From inside the app's folder the name may be left off."
|
|
37662
37956
|
}).option("repo", {
|
|
37663
37957
|
type: "string",
|
|
37664
37958
|
global: false,
|
|
37665
37959
|
describe: "Repo coords (\"owner/name\"). Defaults to plugin-specific resolution."
|
|
37666
37960
|
});
|
|
37961
|
+
// src/commands/app-sync/app-sync.ts
|
|
37962
|
+
/**
|
|
37963
|
+
* `holocron sync <app> --env <env>`: reads the app's vault Environment of the `prod` layer and sends the secrets
|
|
37964
|
+
* `repo.secrets.deploy` names to the app's destinations, the way `sync secrets --project-id <app> --target production`
|
|
37965
|
+
* or `--worker <app>` would: the Vercel project when the app has a `deployment` provider, the Worker script when it has
|
|
37966
|
+
* a `workers` provider, both named after the app folder. Before anything is written the project must serve the app's
|
|
37967
|
+
* configured `domain`. An app with neither destination has nothing to sync and is reported, not failed.
|
|
37968
|
+
*
|
|
37969
|
+
* @param input - The app, the environment, its loaded config and the seams tests replace.
|
|
37970
|
+
*/
|
|
37971
|
+
async function runAppSync(input) {
|
|
37972
|
+
const { app, env } = input;
|
|
37973
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
37974
|
+
const fail = (message) => {
|
|
37975
|
+
print(` ${style.fail(message)}`);
|
|
37976
|
+
return {
|
|
37977
|
+
status: "fail",
|
|
37978
|
+
message
|
|
37979
|
+
};
|
|
37980
|
+
};
|
|
37981
|
+
if (app.configError) return fail(`${app.name}: its holocron.config cannot be read: ${app.configError}`);
|
|
37982
|
+
const plan = appPlan(app.config);
|
|
37983
|
+
if (!plan.deployment && !plan.workers) {
|
|
37984
|
+
const message = `${app.name}: no deployment or Worker is configured, so there are no secrets to sync; nothing to do`;
|
|
37985
|
+
print(` ${style.dim(message)}`);
|
|
37986
|
+
return {
|
|
37987
|
+
status: "nothing",
|
|
37988
|
+
message
|
|
37989
|
+
};
|
|
37990
|
+
}
|
|
37991
|
+
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`);
|
|
37992
|
+
const { loaded, context, loader } = await input.load();
|
|
37993
|
+
const destinations = [plan.deployment ? `${app.name} (project)` : "", plan.workers ? `${app.name} (Worker)` : ""];
|
|
37994
|
+
print(style.header(`Holocron sync ${app.name} → ${destinations.filter(Boolean).join(" + ")}${context.dryRun ? " (dry-run)" : ""}`));
|
|
37995
|
+
if (plan.deployment) {
|
|
37996
|
+
await loader.load();
|
|
37997
|
+
if (!loader.has("deployment")) return fail(`${app.name}: the deployment provider did not load`);
|
|
37998
|
+
const domain = plan.deployment.options.domain;
|
|
37999
|
+
const checked = await checkProjectDomain(loader.get("deployment"), app.name, typeof domain === "string" ? domain : void 0);
|
|
38000
|
+
if (checked.status === "fail") return fail(checked.message);
|
|
38001
|
+
print(` ${style.dim(checked.message)}`);
|
|
38002
|
+
}
|
|
38003
|
+
const environment = await input.resolveEnvironment(env.layer);
|
|
38004
|
+
const resolved = loaded.resolved;
|
|
38005
|
+
const routes = secretRoutes(resolved.repo?.secrets?.sync, environment);
|
|
38006
|
+
const variables = variableRoutes(resolved.repo?.variables?.sync, environment);
|
|
38007
|
+
const variablesOnly = variables.length > 0 && routes.length === 0;
|
|
38008
|
+
const filter = deployFilter(resolved.repo?.secrets?.deploy, environment);
|
|
38009
|
+
const report = await input.syncSecrets({
|
|
38010
|
+
loaded,
|
|
38011
|
+
context,
|
|
38012
|
+
loader,
|
|
38013
|
+
environmentId: environment,
|
|
38014
|
+
...plan.deployment ? {
|
|
38015
|
+
projectId: app.name,
|
|
38016
|
+
targets: env.targets
|
|
38017
|
+
} : {},
|
|
38018
|
+
...plan.workers ? { workerScript: app.name } : {},
|
|
38019
|
+
...filter ? { deployFilter: filter } : {},
|
|
38020
|
+
...routes.length ? { secretRoutes: routes } : variablesOnly ? { secretRoutes: [] } : {},
|
|
38021
|
+
...variables.length ? { variableRoutes: variables } : {}
|
|
38022
|
+
});
|
|
38023
|
+
if (report.summary.fail > 0) return {
|
|
38024
|
+
status: "fail",
|
|
38025
|
+
message: `${app.name}: ${report.summary.fail} secret(s) did not sync`
|
|
38026
|
+
};
|
|
38027
|
+
return {
|
|
38028
|
+
status: "ok",
|
|
38029
|
+
message: `${app.name} synced (${report.summary.ok} written, ${report.summary.skip} skipped)`
|
|
38030
|
+
};
|
|
38031
|
+
}
|
|
38032
|
+
// src/commands/sync/sync-app.ts
|
|
38033
|
+
/**
|
|
38034
|
+
* The `sync <app> --env <env>` path of the `sync` command (spec `tool-app-deploy-sync`). The first step is the app's
|
|
38035
|
+
* name unless it is one of the sync steps. Returns `false` when the arguments do not name an app (no `--env`, and the
|
|
38036
|
+
* value is no app's name), so the command goes on to run its steps as it always has; `true` once it has handled the
|
|
38037
|
+
* run, setting a failing exit code on an error.
|
|
38038
|
+
*
|
|
38039
|
+
* @param argv - The parsed arguments of `holocron sync`.
|
|
38040
|
+
*/
|
|
38041
|
+
async function syncApp(argv) {
|
|
38042
|
+
const first = argv.steps?.[0];
|
|
38043
|
+
const name = first !== void 0 && !SYNC_STEPS.includes(first) ? first : void 0;
|
|
38044
|
+
const lookup = await resolveApp(name, argv.cwd);
|
|
38045
|
+
const { app } = lookup;
|
|
38046
|
+
if (!app && argv.env === void 0) return false;
|
|
38047
|
+
const fail = (message) => {
|
|
38048
|
+
reportError(`sync: ${message}`);
|
|
38049
|
+
process.exitCode = 1;
|
|
38050
|
+
return true;
|
|
38051
|
+
};
|
|
38052
|
+
if (!app) {
|
|
38053
|
+
const names = lookup.names.length ? lookup.names.join(", ") : "none found";
|
|
38054
|
+
return fail(name ? `no app named "${name}" in this workspace (apps: ${names})` : `name an app, or run it from inside one (apps: ${names})`);
|
|
38055
|
+
}
|
|
38056
|
+
let env;
|
|
38057
|
+
try {
|
|
38058
|
+
env = parseAppEnv(argv.env);
|
|
38059
|
+
} catch (err) {
|
|
38060
|
+
return fail(errorMessage(err));
|
|
38061
|
+
}
|
|
38062
|
+
const tokens = tokenContext(argv.token);
|
|
38063
|
+
if (!tokens) return true;
|
|
38064
|
+
if ((await runAppSync({
|
|
38065
|
+
app,
|
|
38066
|
+
env,
|
|
38067
|
+
load: async () => {
|
|
38068
|
+
const loaded = await loadConfig(app.dir);
|
|
38069
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
38070
|
+
const context = {
|
|
38071
|
+
repoRoot: app.dir,
|
|
38072
|
+
dryRun: argv.dryRun,
|
|
38073
|
+
...tokens,
|
|
38074
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
38075
|
+
};
|
|
38076
|
+
return {
|
|
38077
|
+
loaded,
|
|
38078
|
+
context,
|
|
38079
|
+
loader: new PluginLoader(loaded.resolved, context)
|
|
38080
|
+
};
|
|
38081
|
+
},
|
|
38082
|
+
resolveEnvironment: (layer) => resolveEnvironmentId(layer, { repoRoot: app.dir }),
|
|
38083
|
+
syncSecrets: runSecretsSync
|
|
38084
|
+
})).status === "fail") process.exitCode = 1;
|
|
38085
|
+
return true;
|
|
38086
|
+
}
|
|
37667
38087
|
// src/commands/sync/sync.command.ts
|
|
37668
38088
|
const syncCommand = {
|
|
37669
38089
|
command: "sync [steps..]",
|
|
37670
38090
|
describe: "Sync state from config to the provider and local files (labels, properties, teams, topics, keywords, description, homepage, readme, workflows, scripts, wiki)",
|
|
37671
38091
|
builder: (y) => syncArgs(y).command(syncGithubCommand).command(syncIssuesCommand).command(syncIncidentsCommand).command(syncReadmeCommand).command(ideasSyncCommand).command(syncToolingCommand).command(syncRequestsCommand).command(specsSyncCommand).command(secretsSyncCommand).command(notificationsSyncRolesCommand),
|
|
37672
38092
|
handler: async (argv) => {
|
|
38093
|
+
if (argv.env !== void 0 || argv.steps?.[0] !== void 0) {
|
|
38094
|
+
if (await syncApp(argv)) return;
|
|
38095
|
+
}
|
|
37673
38096
|
const tokens = tokenContext(argv.token);
|
|
37674
38097
|
if (!tokens) return;
|
|
37675
38098
|
const loaded = await loadConfig(argv.cwd);
|