@sixb/cli 0.2.6 → 0.2.7

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.
@@ -1,8 +1,6 @@
1
- import { mkdir } from "node:fs/promises"
2
- import { dirname, join, relative } from "node:path"
1
+ import { relative } from "node:path"
3
2
  import { writeJson } from "@sixb/cli-core"
4
3
  import type {
5
- DeployAccessKey,
6
4
  DeployCheck,
7
5
  DeployConfig,
8
6
  DeployControlAction,
@@ -16,30 +14,14 @@ import {
16
14
  deployer,
17
15
  packSource,
18
16
  projectPathOf,
19
- repoRootOf,
20
17
  resolveBunVersion,
18
+ usesChromium,
21
19
  } from "../lib/deploy-source"
22
20
  import { ENV_CONFIG_FILE, loadEnvConfig } from "../lib/env-config"
23
21
  import { SixbCliError } from "../lib/errors"
24
- import {
25
- bunVersionFile,
26
- CI_ENVIRONMENT,
27
- currentRepo,
28
- ensureEnvironment,
29
- hasSecret,
30
- isPrivate,
31
- readSubmodules,
32
- renderWorkflow,
33
- SUBMODULE_TOKEN_SECRET,
34
- secretName,
35
- setSecret,
36
- workflowPath,
37
- } from "../lib/github-ci"
38
22
  import {
39
23
  cliErrorView,
40
- deployAccessView,
41
24
  deployChecksView,
42
- deployCiView,
43
25
  deployCompleteView,
44
26
  deployReleaseView,
45
27
  deployStatusView,
@@ -60,7 +42,8 @@ export interface DeployOptions {
60
42
  export async function runDeploy(options: DeployOptions = {}): Promise<void> {
61
43
  const cwd = options.cwd ?? process.cwd()
62
44
  const { path, config } = await loadDeployConfig(cwd)
63
- const envFromSource = Boolean((await loadEnvConfig(cwd))?.source)
45
+ const envSource = (await loadEnvConfig(cwd))?.source
46
+ const envFromSource = Boolean(envSource)
64
47
 
65
48
  if (options.dryRun) {
66
49
  const release = buildDeployRelease(config, {
@@ -91,6 +74,8 @@ export async function runDeploy(options: DeployOptions = {}): Promise<void> {
91
74
  const checks = await config.target.check(release, {
92
75
  name: config.name,
93
76
  projectPath: source.projectPath,
77
+ chromium: await usesChromium(cwd),
78
+ envToken: envSource?.serverNeedsToken !== false,
94
79
  })
95
80
  return { source, release, checks }
96
81
  })
@@ -132,13 +117,19 @@ export async function runDeploy(options: DeployOptions = {}): Promise<void> {
132
117
  export async function runDeployCheck(options: { readonly json?: boolean; readonly cwd?: string }) {
133
118
  const cwd = options.cwd ?? process.cwd()
134
119
  const { config } = await loadDeployConfig(cwd)
120
+ const envSource = (await loadEnvConfig(cwd))?.source
135
121
  const release = buildDeployRelease(config, {
136
122
  bunVersion: await resolveBunVersion(cwd),
137
- envFromSource: Boolean((await loadEnvConfig(cwd))?.source),
123
+ envFromSource: Boolean(envSource),
138
124
  })
139
- const projectPath = await projectPathOf(cwd)
125
+ const context = {
126
+ name: config.name,
127
+ projectPath: await projectPathOf(cwd),
128
+ chromium: await usesChromium(cwd),
129
+ envToken: envSource?.serverNeedsToken !== false,
130
+ }
140
131
  const targetChecks = await withTask("deploy check", `Checking ${location(config)}`, () =>
141
- config.target.check(release, { name: config.name, projectPath })
132
+ config.target.check(release, context)
142
133
  )
143
134
  const checks = [...targetChecks, ...lakeWorkChecks(config)]
144
135
  if (options.json) writeJson(checks)
@@ -147,173 +138,12 @@ export async function runDeployCheck(options: { readonly json?: boolean; readonl
147
138
  if (checks.some(blocksDeploy)) process.exitCode = 1
148
139
  }
149
140
 
150
- export async function runDeploySetup(options: {
151
- readonly admin?: string
152
- readonly key?: string
153
- readonly cwd?: string
154
- }) {
155
- const cwd = options.cwd ?? process.cwd()
156
- const { config } = await loadDeployConfig(cwd)
157
- const source = (await loadEnvConfig(cwd))?.source
158
- const release = buildDeployRelease(config, {
159
- bunVersion: await resolveBunVersion(cwd),
160
- envFromSource: Boolean(source),
161
- })
162
- const context = { name: config.name, projectPath: await projectPathOf(cwd) }
163
-
164
- if (!config.target.setup) {
165
- console.log(`A ${config.target.kind} target needs no setup.`)
166
- } else {
167
- await config.target.setup(release, {
168
- ...context,
169
- ...(options.admin ? { admin: options.admin } : {}),
170
- ...(options.key ? { key: options.key } : {}),
171
- ...(source
172
- ? {
173
- createEnvToken: () =>
174
- source.createServerToken("prod", `sixb-${config.name}-${new Date().toISOString()}`),
175
- }
176
- : {}),
177
- write: (line) => console.log(line),
178
- })
179
- }
180
- const checks = await config.target.check(release, context)
181
- await renderStatic(deployChecksView({ name: config.name, location: location(config), checks }))
182
- }
183
-
184
- export async function runDeployAccess(options: {
185
- readonly action: "list" | "add" | "remove"
186
- readonly value?: string
187
- readonly json?: boolean
188
- readonly cwd?: string
189
- }) {
190
- const { config } = await loadDeployConfig(options.cwd)
191
- const access = config.target.access
192
- if (!access) {
193
- throw new SixbCliError(`[SixbDeploy] A ${config.target.kind} target has no keys to manage.`)
194
- }
195
- const context = { name: config.name }
196
-
197
- if (options.action === "list") {
198
- const keys = await access.list(context)
199
- if (options.json) return writeJson(keys)
200
- return renderStatic(deployAccessView({ title: `Keys for ${location(config)}`, keys }))
201
- }
202
- if (options.action === "add") {
203
- const added: DeployAccessKey[] = []
204
- for (const key of await publicKeys(options.value ?? ""))
205
- added.push(await access.add(key, context))
206
- return renderStatic(deployAccessView({ title: "Authorized", keys: added }))
207
- }
208
- const removed = await access.remove(options.value ?? "", context)
209
- return renderStatic(deployAccessView({ title: "Revoked", keys: removed }))
210
- }
211
-
212
- /**
213
- * Sets up deploys from GitHub Actions: a key for the job, authorized on the target and stored as
214
- * secrets of the repository's `production` environment, and the workflow that uses it. Running it
215
- * again rotates the key: the new one is stored before the old one is revoked.
216
- */
217
- export async function runDeployCi(options: { readonly branch?: string; readonly cwd?: string }) {
218
- const cwd = options.cwd ?? process.cwd()
219
- const { config } = await loadDeployConfig(cwd)
220
- const ci = config.target.ci
221
- if (!ci) {
222
- throw new SixbCliError(`[SixbDeploy] A ${config.target.kind} target cannot deploy from CI.`)
223
- }
224
-
225
- const repo = await currentRepo(cwd)
226
- const projectPath = await projectPathOf(cwd)
227
- const repoRoot = await repoRootOf(cwd)
228
- const submodules = await readSubmodules(repoRoot, repo)
229
- const privateSubmodules = []
230
- for (const submodule of submodules) {
231
- if (!submodule.repo || (await isPrivate(submodule.repo))) privateSubmodules.push(submodule)
232
- }
233
-
234
- const credential = await ci.create(`github:${repo.name}`, { name: config.name })
235
- const secrets = Object.fromEntries(
236
- Object.keys(credential.secrets).map((variable) => [variable, secretName(config.name, variable)])
237
- )
238
- try {
239
- await ensureEnvironment(repo)
240
- for (const [variable, value] of Object.entries(credential.secrets)) {
241
- await setSecret(repo, secrets[variable] ?? variable, value)
242
- }
243
- } catch (error) {
244
- // CI never got the new key, so it must not stay authorized.
245
- await credential.revoke()
246
- throw error
247
- }
248
- const retired = await credential.retireOthers()
249
-
250
- const branch = options.branch ?? repo.defaultBranch
251
- const workflow = renderWorkflow({
252
- name: config.name,
253
- branch,
254
- projectPath,
255
- bunVersionFile: await bunVersionFile(join(repoRoot, projectPath), repoRoot),
256
- secrets,
257
- install: credential.install,
258
- submodules:
259
- privateSubmodules.length > 0 ? "private" : submodules.length > 0 ? "public" : "none",
260
- })
261
- const path = workflowPath(config.name)
262
- const file = Bun.file(join(repoRoot, path))
263
- // A workflow already there may have been edited, and rotating the key must not undo that.
264
- const existing = (await file.exists()) ? await file.text() : null
265
- if (existing === null) {
266
- await mkdir(dirname(join(repoRoot, path)), { recursive: true })
267
- await Bun.write(file, workflow)
268
- }
269
-
270
- await renderStatic(
271
- deployCiView({
272
- name: config.name,
273
- repo: repo.name,
274
- environment: CI_ENVIRONMENT,
275
- branch,
276
- credential: credential.description,
277
- secrets: Object.values(secrets),
278
- retired,
279
- workflow: {
280
- path,
281
- state: existing === null ? "written" : existing === workflow ? "unchanged" : "kept",
282
- },
283
- token:
284
- privateSubmodules.length > 0 && !(await hasSecret(repo, SUBMODULE_TOKEN_SECRET))
285
- ? { name: SUBMODULE_TOKEN_SECRET, submodules: privateSubmodules }
286
- : null,
287
- })
288
- )
289
- }
290
-
291
- /**
292
- * The public keys a value names: `github:<user>` for the keys on that GitHub account, a path to a
293
- * `.pub` file, or the key's own text.
294
- */
295
- async function publicKeys(value: string): Promise<string[]> {
296
- if (value.startsWith("github:")) {
297
- const user = value.slice("github:".length)
298
- const response = await fetch(`https://github.com/${encodeURIComponent(user)}.keys`)
299
- if (!response.ok) {
300
- throw new SixbCliError(`[SixbDeploy] GitHub has no public keys for '${user}'.`)
301
- }
302
- const keys = (await response.text()).split("\n").filter((line) => line.trim())
303
- if (keys.length === 0) throw new SixbCliError(`[SixbDeploy] '${user}' has no keys on GitHub.`)
304
- return keys.map((key) => `${key.trim()} ${user}@github`)
305
- }
306
- const file = Bun.file(value)
307
- if (await file.exists()) return [(await file.text()).trim()]
308
- return [value]
309
- }
310
-
311
141
  function configWarnings(config: DeployConfig): readonly string[] {
312
142
  return lakeWorkChecks(config).map((check) => `${check.label}: ${check.detail} ${check.remedy}`)
313
143
  }
314
144
 
315
145
  function blocksDeploy(check: DeployCheck): boolean {
316
- return check.status === "fixable" || check.status === "manual"
146
+ return check.status === "fail"
317
147
  }
318
148
 
319
149
  function location(config: DeployConfig): string {
@@ -65,12 +65,18 @@ export async function runEnvPull(options: {
65
65
  }
66
66
 
67
67
  const { config, source } = await requireSource(cwd)
68
- const token = options.tokenFile === undefined ? undefined : await readToken(options.tokenFile)
68
+ // A server: it reads with its token file, unless the source reads with the server's identity.
69
+ const server = options.tokenFile !== undefined
70
+ const token =
71
+ options.tokenFile !== undefined && source.serverNeedsToken !== false
72
+ ? await readToken(options.tokenFile)
73
+ : undefined
69
74
  const pulled = await pullEnv({
70
75
  cwd,
71
76
  config,
72
77
  source,
73
78
  env,
79
+ server,
74
80
  ...(token === undefined ? {} : { token }),
75
81
  force: options.force === true,
76
82
  })
@@ -91,19 +97,23 @@ async function pullEnv(input: {
91
97
  readonly config: EnvConfig
92
98
  readonly source: EnvSource
93
99
  readonly env: EnvName
100
+ readonly server: boolean
94
101
  readonly token?: string
95
102
  readonly force?: boolean
96
103
  }): Promise<PullResult> {
97
- const { config, source, env, token } = input
104
+ const { config, source, env, server, token } = input
98
105
  const path = join(input.cwd, ".env")
99
106
 
100
107
  let values: Readonly<Record<string, string>>
101
108
  try {
102
- values = await source.read(env, token === undefined ? {} : { token })
109
+ values = await source.read(
110
+ env,
111
+ server ? { server, ...(token === undefined ? {} : { token }) } : {}
112
+ )
103
113
  } catch (error) {
104
114
  // A server riding out an outage, so it can still take a hotfix. A refusal never reaches this:
105
115
  // a revoked token must stop the deploy.
106
- const riding = token !== undefined && error instanceof EnvSourceUnreachableError
116
+ const riding = server && error instanceof EnvSourceUnreachableError
107
117
  if (riding && (await isCompleteGeneratedEnv(path, config, env))) {
108
118
  return { kept: true, reason: errorMessage(error) }
109
119
  }
@@ -192,7 +202,7 @@ export async function pullIntoThisProcess(
192
202
  config: EnvConfig,
193
203
  source: EnvSource
194
204
  ): Promise<void> {
195
- const pulled = await pullEnv({ cwd, config, source, env: "dev" })
205
+ const pulled = await pullEnv({ cwd, config, source, env: "dev", server: false })
196
206
  if (pulled.kept) return
197
207
 
198
208
  const localPath = join(cwd, ".env.local")
package/src/index.tsx CHANGED
@@ -333,7 +333,11 @@ async function main(): Promise<void> {
333
333
 
334
334
  case "check": {
335
335
  const { runCheck } = await import("./commands/check")
336
- await runCheck({ entry: getFlag("entry") })
336
+ await runCheck({
337
+ entry: getFlag("entry"),
338
+ migrate: hasFlag("migrate"),
339
+ lake: hasFlag("lake"),
340
+ })
337
341
  break
338
342
  }
339
343
 
@@ -445,7 +449,11 @@ async function main(): Promise<void> {
445
449
 
446
450
  case "deploy": {
447
451
  const { runDeploy } = await import("./commands/deploy")
448
- await runDeploy({ dryRun: hasFlag("dry-run"), json: hasFlag("json"), ref: getFlag("ref") })
452
+ await runDeploy({
453
+ dryRun: hasFlag("dry-run"),
454
+ json: hasFlag("json"),
455
+ ref: getFlag("ref"),
456
+ })
449
457
  break
450
458
  }
451
459
 
@@ -465,36 +473,12 @@ async function main(): Promise<void> {
465
473
  break
466
474
  }
467
475
 
468
- case "deploy:setup": {
469
- const { runDeploySetup } = await import("./commands/deploy")
470
- await runDeploySetup({ admin: getFlag("admin"), key: getFlag("key") })
471
- break
472
- }
473
-
474
476
  case "deploy:check": {
475
477
  const { runDeployCheck } = await import("./commands/deploy")
476
478
  await runDeployCheck({ json: hasFlag("json") })
477
479
  break
478
480
  }
479
481
 
480
- case "deploy:ci": {
481
- const { runDeployCi } = await import("./commands/deploy")
482
- await runDeployCi({ branch: getFlag("branch") })
483
- break
484
- }
485
-
486
- case "deploy:access:list":
487
- case "deploy:access:add":
488
- case "deploy:access:remove": {
489
- const { runDeployAccess } = await import("./commands/deploy")
490
- await runDeployAccess({
491
- action: parsed.id.slice("deploy:access:".length) as "list" | "add" | "remove",
492
- value: positionals[0],
493
- json: hasFlag("json"),
494
- })
495
- break
496
- }
497
-
498
482
  case "deploy:restart":
499
483
  case "deploy:start":
500
484
  case "deploy:stop": {
@@ -140,6 +140,16 @@ export const CLI_OPTION_DEFINITIONS = {
140
140
  summary: "Branch, tag, or commit to deploy (default: HEAD)",
141
141
  kind: "string",
142
142
  },
143
+ migrate: {
144
+ syntax: "--migrate",
145
+ summary: "Bring the storage schema up to date first, as a deploy does",
146
+ kind: "boolean",
147
+ },
148
+ lake: {
149
+ syntax: "--lake",
150
+ summary: "Check the lake's dataset definitions too",
151
+ kind: "boolean",
152
+ },
143
153
  follow: { syntax: "--follow", summary: "Keep printing new log lines", kind: "boolean" },
144
154
  env: {
145
155
  syntax: "--env <dev|prod>",
@@ -166,21 +176,6 @@ export const CLI_OPTION_DEFINITIONS = {
166
176
  summary: "Replace a hand-written .env, losing what the source doesn't have",
167
177
  kind: "boolean",
168
178
  },
169
- admin: {
170
- syntax: "--admin <login>",
171
- summary: "Login with sudo that prepares the server (default: root)",
172
- kind: "string",
173
- },
174
- key: {
175
- syntax: "--key <path>",
176
- summary: "Public key to authorize for deploys (default: the one SSH uses)",
177
- kind: "string",
178
- },
179
- branch: {
180
- syntax: "--branch <name>",
181
- summary: "Branch whose pushes deploy (default: the repository's default branch)",
182
- kind: "string",
183
- },
184
179
  tail: {
185
180
  syntax: "--tail <lines>",
186
181
  summary: "Recent log lines to print (default: 100)",
@@ -257,12 +252,7 @@ export type LocalCommandId =
257
252
  | "deploy:restart"
258
253
  | "deploy:start"
259
254
  | "deploy:stop"
260
- | "deploy:setup"
261
255
  | "deploy:check"
262
- | "deploy:ci"
263
- | "deploy:access:list"
264
- | "deploy:access:add"
265
- | "deploy:access:remove"
266
256
  | "env:init"
267
257
  | "env:pull"
268
258
  | "env:set"
@@ -547,7 +537,9 @@ const commandTree: readonly CommandNode[] = [
547
537
  maximumPositionals: Number.POSITIVE_INFINITY,
548
538
  rootHelpLabel: "worker-group [types...]",
549
539
  }),
550
- command("check", "Validate project configuration and health", { options: ["entry"] }),
540
+ command("check", "Validate project configuration and health", {
541
+ options: ["entry", "migrate", "lake"],
542
+ }),
551
543
  command("run", "Run a script against the project, here or in production", {
552
544
  usage: "sixb run [--deployed] [--yes] [--entry <path>] <script> [args...]",
553
545
  options: ["entry", "deployed", "yes"],
@@ -622,18 +614,10 @@ const commandTree: readonly CommandNode[] = [
622
614
  rootHelpLabel: "deploy ...",
623
615
  }),
624
616
  children: [
625
- command("deploy:setup", "Prepare the server and project for deploys", {
626
- path: ["deploy", "setup"],
627
- options: ["admin", "key"],
628
- }),
629
617
  command("deploy:check", "Check what stands between you and a working deploy", {
630
618
  path: ["deploy", "check"],
631
619
  options: ["json"],
632
620
  }),
633
- command("deploy:ci", "Deploy from GitHub Actions on every push", {
634
- path: ["deploy", "ci"],
635
- options: ["branch"],
636
- }),
637
621
  command("deploy:status", "Show what the deployment runs, and which commit", {
638
622
  path: ["deploy", "status"],
639
623
  options: ["json"],
@@ -651,29 +635,6 @@ const commandTree: readonly CommandNode[] = [
651
635
  maximumPositionals: 1,
652
636
  })
653
637
  ),
654
- {
655
- name: "access",
656
- summary: "Manage the keys that may deploy and operate the deployment",
657
- usage: "sixb deploy access <list|add|remove>",
658
- children: [
659
- command("deploy:access:list", "List the authorized keys", {
660
- path: ["deploy", "access", "list"],
661
- options: ["json"],
662
- }),
663
- command("deploy:access:add", "Authorize a key: a .pub file, its text, or github:<user>", {
664
- path: ["deploy", "access", "add"],
665
- usage: "sixb deploy access add <key>",
666
- minimumPositionals: 1,
667
- maximumPositionals: 1,
668
- }),
669
- command("deploy:access:remove", "Revoke the keys with this fingerprint or comment", {
670
- path: ["deploy", "access", "remove"],
671
- usage: "sixb deploy access remove <fingerprint|comment>",
672
- minimumPositionals: 1,
673
- maximumPositionals: 1,
674
- }),
675
- ],
676
- },
677
638
  ],
678
639
  },
679
640
  {
@@ -101,10 +101,9 @@ export function buildDeployRelease(
101
101
  steps: {
102
102
  ...(options.envFromSource ? { env: sixb("env", "pull", "--env", "prod") } : {}),
103
103
  build: [sixb("build")],
104
- // The order `docs/deployment` gives. `check` probes every provider, so a broker or queue
105
- // the services cannot reach fails the deploy instead of passing for healthy; it needs the
106
- // schema migrated first.
107
- beforeStart: [sixb("db", "migrate"), sixb("check"), sixb("lake", "check")],
104
+ // One project load: migrate, then probe every provider, so a broker or queue the services
105
+ // cannot reach fails the deploy instead of passing for healthy, then the lake's datasets.
106
+ beforeStart: [sixb("check", "--migrate", "--lake")],
108
107
  },
109
108
  services: [
110
109
  ...enabled.map((service) => sixbService(config, service, env, http)),
@@ -48,6 +48,21 @@ export async function packSource(projectDir: string, ref = "HEAD"): Promise<Pack
48
48
  }
49
49
  }
50
50
 
51
+ /** The packages a project prints with Chromium through. */
52
+ const CHROMIUM_PACKAGES = ["playwright", "playwright-core"]
53
+
54
+ /** Whether the project depends on Playwright, so its server needs Chromium's libraries. */
55
+ export async function usesChromium(projectDir: string): Promise<boolean> {
56
+ const manifest = (await Bun.file(join(projectDir, "package.json"))
57
+ .json()
58
+ .catch(() => null)) as {
59
+ readonly dependencies?: Readonly<Record<string, string>>
60
+ readonly optionalDependencies?: Readonly<Record<string, string>>
61
+ } | null
62
+ const dependencies = { ...manifest?.dependencies, ...manifest?.optionalDependencies }
63
+ return CHROMIUM_PACKAGES.some((name) => name in dependencies)
64
+ }
65
+
51
66
  /**
52
67
  * The Bun version the project pins with `packageManager` (`"bun@1.4.2"`) in its `package.json` or
53
68
  * the nearest one above it, up to the repository root; else the Bun running this CLI. Read from the
@@ -50,9 +50,7 @@ function validateEnvConfig(value: unknown): EnvConfig {
50
50
 
51
51
  function isEnvSource(value: unknown): boolean {
52
52
  const candidate = value as Record<string, unknown> | null
53
- return ["names", "read", "write", "createServerToken"].every(
54
- (method) => typeof candidate?.[method] === "function"
55
- )
53
+ return ["names", "read", "write"].every((method) => typeof candidate?.[method] === "function")
56
54
  }
57
55
 
58
56
  /** The names `env` must have a value for and doesn't. An empty value counts as none. */
@@ -1,10 +1,4 @@
1
- import type {
2
- DeployAccessKey,
3
- DeployCheck,
4
- DeployCommand,
5
- DeployRelease,
6
- DeployStatus,
7
- } from "@sixb/core/deploy"
1
+ import type { DeployCheck, DeployCommand, DeployRelease, DeployStatus } from "@sixb/core/deploy"
8
2
  import {
9
3
  commands,
10
4
  header,
@@ -196,8 +190,7 @@ export function deployStatusView({
196
190
 
197
191
  const CHECK_STATUS = {
198
192
  ok: "ok",
199
- fixable: "warn",
200
- manual: "idle",
193
+ fail: "idle",
201
194
  warning: "warn",
202
195
  } as const satisfies Record<DeployCheck["status"], Status>
203
196
 
@@ -210,13 +203,15 @@ export function deployChecksView({
210
203
  location: string
211
204
  checks: readonly DeployCheck[]
212
205
  }): string {
213
- const blocking = checks.filter((check) => check.status === "fixable" || check.status === "manual")
206
+ const blocking = checks.filter((check) => check.status === "fail")
214
207
  const warnings = checks.filter((check) => check.status === "warning")
215
- const next = blocking.some((check) => check.status === "fixable")
216
- ? "sixb deploy setup"
217
- : blocking.length > 0
218
- ? "the steps above, then sixb deploy check"
219
- : "sixb deploy"
208
+ const next = blocking.length > 0 ? "the steps above, then sixb deploy check" : "sixb deploy"
209
+ // Unwrapped and together, so they paste into a root shell on the server as they are.
210
+ const fixes = [
211
+ ...new Set(
212
+ checks.filter((check) => check.status !== "ok").flatMap((check) => check.commands ?? [])
213
+ ),
214
+ ]
220
215
 
221
216
  return screen(
222
217
  header("deploy check", location),
@@ -237,107 +232,11 @@ export function deployChecksView({
237
232
  `${name} is ready to deploy`,
238
233
  warnings.length > 0 ? `${warnings.length} to look at` : undefined
239
234
  ),
235
+ fixes.length > 0 ? section("Run once on the server, as root", commands(fixes)) : undefined,
240
236
  nextStep(next)
241
237
  )
242
238
  }
243
239
 
244
- export function deployCiView({
245
- name,
246
- repo,
247
- environment,
248
- branch,
249
- credential,
250
- secrets,
251
- retired,
252
- workflow,
253
- token,
254
- }: {
255
- name: string
256
- repo: string
257
- environment: string
258
- branch: string
259
- credential: string
260
- secrets: readonly string[]
261
- retired: readonly DeployAccessKey[]
262
- workflow: { readonly path: string; readonly state: "written" | "unchanged" | "kept" }
263
- token: {
264
- readonly name: string
265
- readonly submodules: readonly {
266
- readonly path: string
267
- readonly url: string
268
- readonly repo: string | null
269
- }[]
270
- } | null
271
- }): string {
272
- const items: Row[] = [
273
- { label: "Key", status: "ok", value: credential },
274
- { label: "Secrets", status: "ok", value: secrets.join(", ") },
275
- {
276
- label: "Older keys",
277
- status: "ok",
278
- value:
279
- retired.length === 0
280
- ? "none to revoke"
281
- : `revoked ${retired.map((key) => key.fingerprint).join(", ")}`,
282
- },
283
- {
284
- label: "Workflow",
285
- status: "ok",
286
- value: {
287
- written: workflow.path,
288
- unchanged: `${workflow.path} (unchanged)`,
289
- kept: `${workflow.path} (yours, kept: it differs from what this command writes; delete it and run again to start over)`,
290
- }[workflow.state],
291
- },
292
- ...(token
293
- ? [
294
- {
295
- label: "Token",
296
- status: "idle" as const,
297
- value: `${token.submodules.map((submodule) => submodule.path).join(", ")} ${token.submodules.length === 1 ? "is" : "are"} private, and CI cannot read ${token.submodules.length === 1 ? "it" : "them"} with its own token.`,
298
- remedy: `Create a fine-grained token with Contents: read on ${token.submodules.map((submodule) => submodule.repo ?? submodule.url).join(", ")}, then run \`gh secret set ${token.name} --env ${environment} --repo ${repo}\`.`,
299
- },
300
- ]
301
- : []),
302
- ]
303
- const next =
304
- workflow.state === "written"
305
- ? `commit ${workflow.path} and push to ${branch}.`
306
- : `push to ${branch} to deploy.`
307
-
308
- return screen(
309
- stack(header("deploy ci", repo), tone.muted(`environment ${environment}`)),
310
- rows(items),
311
- headline(
312
- token ? "warn" : "ok",
313
- `${name} deploys from GitHub Actions on every push to ${branch}`
314
- ),
315
- nextStep(next)
316
- )
317
- }
318
-
319
- export function deployAccessView({
320
- title,
321
- keys,
322
- }: {
323
- title: string
324
- keys: readonly DeployAccessKey[]
325
- }): string {
326
- // Two lines a key: a fingerprint and a long comment do not fit side by side in 80 columns.
327
- const list =
328
- keys.length === 0
329
- ? tone.muted("No keys.")
330
- : keys
331
- .map((key) =>
332
- stack(
333
- `${key.comment || "(no comment)"}${key.restricted ? tone.warn(" restricted") : ""}`,
334
- tone.muted(`${key.type} ${key.fingerprint}`)
335
- )
336
- )
337
- .join("\n")
338
- return screen(header(), list, headline("ok", title))
339
- }
340
-
341
240
  /** The one thing to do next: a command to run, or what to do in words. */
342
241
  function nextStep(next: string): string {
343
242
  return section("Next steps", next.startsWith("sixb ") ? commands([next]) : remedy(next))