Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Merge branch 'worktree-agent-a985c01f43538af01' | 1 | import { Form, Link } from "react-router"; |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 2 | |
| 3 | import type { DetectedKind } from "@g1t/contracts"; | |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 4 | |
| 5 | import type { Route } from "./+types/settings-deployments"; | |
| Social cards for every page: og.g1t.sh | 6 | import { page } from "../../lib/meta"; |
| Project settings move into the sidebar, grouped, with a heading per page | 7 | import { RepoSettingsHeading } from "../../components/repo-settings-heading"; |
| Merge branch 'worktree-agent-a985c01f43538af01' | 8 | import { ErrorText, Field, Input, SubmitButton } from "../../components/ui"; |
| Workspace names and icons, and a component kit for every control | 9 | import { SwitchCard } from "../../components/ui/switch"; |
| A project is an app or a library: libraries show their package and how to ship a release, not production | 10 | import { deployments, projects } from "../../lib/services.server"; |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 11 | import { assertSameOrigin, getViewer, requireUser, unwrap } from "../../lib/session.server"; |
| 12 | import { requireCapability, requireInsider } from "../../lib/access.server"; | |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 13 | |
| Social cards for every page: og.g1t.sh | 14 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 15 | return page(args, { title: `Deployment settings · ${params.owner}/${params.repo} · g1t` }); | |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 16 | } |
| 17 | ||
| 18 | export async function loader({ params, context }: Route.LoaderArgs) { | |
| 19 | const viewer = getViewer(context); | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 20 | // Admins; to anyone without a role here the page does not exist. |
| 21 | await requireInsider(context, params, "manage_integrations"); | |
| A project is an app or a library: libraries show their package and how to ship a release, not production | 22 | const [settings, project] = await Promise.all([ |
| 23 | deployments.settings({ workspace: params.owner, slug: params.repo }, viewer), | |
| 24 | projects.get(params.owner, params.repo, viewer).catch(() => null), | |
| 25 | ]); | |
| 26 | // Set not to deploy in General settings: turning them on is refused until that changes. | |
| 27 | const notDeploying = project?.ok ? project.value.deploys === "no" : false; | |
| 28 | return { settings: unwrap(settings), notDeploying }; | |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 29 | } |
| 30 | ||
| 31 | export async function action({ request, params, context }: Route.ActionArgs) { | |
| 32 | assertSameOrigin(request); | |
| 33 | const user = requireUser(context, request); | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 34 | await requireCapability(context, params, "manage_integrations"); |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 35 | const form = await request.formData(); |
| Projects: what a workspace builds and runs, first on every page | 36 | const ref = { workspace: params.owner, slug: params.repo }; |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 37 | const intent = form.get("intent"); |
| 38 | if (intent === "enable" || intent === "disable") { | |
| Projects: what a workspace builds and runs, first on every page | 39 | const saved = await deployments.updateSettings(user, ref, { enabled: intent === "enable" }); |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 40 | return saved.ok |
| 41 | ? { notice: intent === "enable" ? "Deployments are on. Production is building." : "Deployments are off, and every app is down." } | |
| 42 | : { error: saved.error.message }; | |
| 43 | } | |
| 44 | const on = (name: string) => form.get(name) === "on"; | |
| Projects: what a workspace builds and runs, first on every page | 45 | const saved = await deployments.updateSettings(user, ref, { |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 46 | previews: on("previews"), |
| 47 | production: on("production"), | |
| 48 | buildCommand: String(form.get("buildCommand") ?? ""), | |
| 49 | outputDir: String(form.get("outputDir") ?? ""), | |
| 50 | idleDays: Number(form.get("idleDays")), | |
| 51 | }); | |
| 52 | return saved.ok ? { notice: "Saved." } : { error: saved.error.message }; | |
| 53 | } | |
| 54 | ||
| 55 | function Check({ name, on, title, children }: { name: string; on: boolean; title: string; children: string }) { | |
| 56 | return ( | |
| Workspace names and icons, and a component kit for every control | 57 | <SwitchCard name={name} defaultChecked={on} title={title}> |
| 58 | {children} | |
| 59 | </SwitchCard> | |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 60 | ); |
| 61 | } | |
| 62 | ||
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 63 | /** What each kind of project is called, and what running it costs, in a line. */ |
| 64 | const DETECTED: Record<DetectedKind, { label: string; cost: string }> = { | |
| 65 | static: { | |
| 66 | label: "Static site", | |
| 67 | cost: "Serving its files runs no code, so it adds no requests or CPU time. Builds are metered.", | |
| 68 | }, | |
| 69 | html: { | |
| 70 | label: "Plain HTML", | |
| 71 | cost: "Its files are served as they are and run no code, so serving adds no requests or CPU time. Builds are metered.", | |
| 72 | }, | |
| 73 | workers: { | |
| 74 | label: "Workers project", | |
| 75 | cost: "Its code runs on every request: requests and CPU time are metered, and so are builds.", | |
| 76 | }, | |
| 77 | }; | |
| 78 | ||
| 79 | /** What g1t found the project to be at its last build, and what that costs. */ | |
| 80 | function Detected({ kind }: { kind: DetectedKind | null }) { | |
| 81 | const found = kind ? DETECTED[kind] : null; | |
| 82 | return ( | |
| 83 | <section className="mb-6 rounded-xl border border-line bg-surface p-5"> | |
| 84 | <h2 className="text-sm font-medium">What g1t detected</h2> | |
| 85 | <p className="mt-1 text-sm"> | |
| 86 | {found ? found.label : <span className="text-muted">Detected at the first build</span>} | |
| 87 | </p> | |
| 88 | <p className="mt-1 text-xs text-muted"> | |
| 89 | {found | |
| 90 | ? found.cost | |
| 91 | : "A static site's files cost nothing to serve; a Workers project's requests and CPU time are metered. Builds are metered either way."} | |
| 92 | </p> | |
| 93 | </section> | |
| 94 | ); | |
| 95 | } | |
| 96 | ||
| Secrets and variables: one list, rows per environment, for workflows and deployments | 97 | export default function DeploymentSettings({ loaderData, actionData, params }: Route.ComponentProps) { |
| A project is an app or a library: libraries show their package and how to ship a release, not production | 98 | const { settings, notDeploying } = loaderData; |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 99 | const base = `/${params.owner}/${params.repo}`; |
| 100 | return ( | |
| 101 | <div className="max-w-4xl"> | |
| Project settings move into the sidebar, grouped, with a heading per page | 102 | <RepoSettingsHeading base={base} /> |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 103 | <div className="min-h-6"> |
| 104 | {actionData && "notice" in actionData && <p className="text-sm text-accent">{actionData.notice}</p>} | |
| 105 | <ErrorText>{actionData && "error" in actionData ? actionData.error : null}</ErrorText> | |
| 106 | </div> | |
| 107 | ||
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 108 | <Detected kind={settings.detected ?? null} /> |
| 109 | ||
| Secrets and variables: one list, rows per environment, for workflows and deployments | 110 | {!settings.enabled ? ( |
| 111 | <section className="rounded-xl border border-line bg-surface p-5"> | |
| 112 | <h2 className="font-medium">Deployments are off</h2> | |
| 113 | <p className="mt-1 text-sm text-muted"> | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 114 | Deployments are opt-in for each project, and nothing builds or runs until you turn them on. Then g1t builds |
| 115 | production at{" "} | |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 116 | <span className="font-mono text-fg">{settings.productionUrl.replace("https://", "")}</span> and a preview for |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 117 | every pull request. The workspace needs the g1t plan, under Billing. |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 118 | </p> |
| A project is an app or a library: libraries show their package and how to ship a release, not production | 119 | {notDeploying ? ( |
| 120 | <p className="mt-4 text-sm text-muted"> | |
| 121 | This project is set as one that doesn't deploy, a library or a tool. To deploy it, choose Deploys or Detect | |
| 122 | automatically under{" "} | |
| 123 | <Link to={`${base}/settings#deploys`} className="text-fg underline underline-offset-4"> | |
| 124 | General | |
| 125 | </Link>{" "} | |
| 126 | first. | |
| 127 | </p> | |
| 128 | ) : ( | |
| 129 | <Form method="post" className="mt-4"> | |
| Merge branch 'worktree-agent-a985c01f43538af01' | 130 | <SubmitButton variant="accent" name="intent" value="enable" pending="Turning on…"> |
| A project is an app or a library: libraries show their package and how to ship a release, not production | 131 | Turn on deployments |
| Merge branch 'worktree-agent-a985c01f43538af01' | 132 | </SubmitButton> |
| A project is an app or a library: libraries show their package and how to ship a release, not production | 133 | </Form> |
| 134 | )} | |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 135 | </section> |
| 136 | ) : ( | |
| 137 | <> | |
| 138 | <Form method="post" className="space-y-5"> | |
| 139 | <div className="grid gap-3 md:grid-cols-2"> | |
| 140 | <Check name="production" on={settings.production} title="Production"> | |
| 141 | Deploy the default branch on every push. | |
| 142 | </Check> | |
| 143 | <Check name="previews" on={settings.previews} title="Previews"> | |
| Projects: what a workspace builds and runs, first on every page | 144 | A preview for every branch with an open pull request, linked on it. |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 145 | </Check> |
| 146 | </div> | |
| 147 | <div className="grid gap-4 md:grid-cols-3"> | |
| 148 | <Field label="Build command" hint="Instead of the project's own build script."> | |
| 149 | <Input name="buildCommand" defaultValue={settings.buildCommand ?? ""} placeholder="npm run build" /> | |
| 150 | </Field> | |
| 151 | <Field label="Output directory" hint="For a static site; found by itself when empty."> | |
| 152 | <Input name="outputDir" defaultValue={settings.outputDir ?? ""} placeholder="dist" /> | |
| 153 | </Field> | |
| 154 | <Field label="Idle days" hint="A preview no one visits for this long comes down."> | |
| 155 | <Input name="idleDays" type="number" min={1} max={90} defaultValue={settings.idleDays} /> | |
| 156 | </Field> | |
| 157 | </div> | |
| 158 | <p className="text-sm text-muted"> | |
| 159 | Builds and running apps read the{" "} | |
| 160 | <Link to={`${base}/settings/secrets`} className="text-fg hover:underline"> | |
| 161 | secrets and variables | |
| 162 | </Link>{" "} | |
| 163 | available to Deployments: each row for Production or Preview, or for all environments. | |
| 164 | </p> | |
| Merge branch 'worktree-agent-a985c01f43538af01' | 165 | <SubmitButton name="intent" value="save" pending="Saving…"> |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 166 | Save |
| Merge branch 'worktree-agent-a985c01f43538af01' | 167 | </SubmitButton> |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 168 | </Form> |
| 169 | ||
| 170 | <section className="mt-10 rounded-xl border border-danger/30 p-5"> | |
| 171 | <h2 className="text-sm font-medium">Turn off deployments</h2> | |
| 172 | <p className="mt-1 text-sm text-muted"> | |
| Projects: what a workspace builds and runs, first on every page | 173 | Takes production and every preview down now, and stops building. Nothing of this project's keeps |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 174 | running or costing anything. The workspace's plan stays on; turn it off under Billing. |
| 175 | </p> | |
| 176 | <Form method="post" className="mt-3"> | |
| Merge branch 'worktree-agent-a985c01f43538af01' | 177 | <SubmitButton variant="quiet" name="intent" value="disable" pending="Turning off…"> |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 178 | Turn off deployments |
| Merge branch 'worktree-agent-a985c01f43538af01' | 179 | </SubmitButton> |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 180 | </Form> |
| 181 | </section> | |
| 182 | </> | |
| 183 | )} | |
| 184 | </div> | |
| 185 | ); | |
| 186 | } |
This file's history is long; its oldest lines are credited to the oldest commit read.