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