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.
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1 | import { Form, Link, useNavigation } from "react-router"; |
| 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"; |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 8 | import { Button, ErrorText, Field, Input } 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 busy = useNavigation().state === "submitting"; |
| 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"> |
| 105 | {actionData && "notice" in actionData && <p className="text-sm text-accent">{actionData.notice}</p>} | |
| 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"> | |
| 122 | This project is set as one that doesn't deploy, a library or a tool. To deploy it, choose Deploys or Detect | |
| 123 | automatically under{" "} | |
| 124 | <Link to={`${base}/settings#deploys`} className="text-fg underline underline-offset-4"> | |
| 125 | General | |
| 126 | </Link>{" "} | |
| 127 | first. | |
| 128 | </p> | |
| 129 | ) : ( | |
| 130 | <Form method="post" className="mt-4"> | |
| 131 | <Button variant="accent" type="submit" name="intent" value="enable" disabled={busy}> | |
| 132 | Turn on deployments | |
| 133 | </Button> | |
| 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> | |
| 166 | <Button type="submit" disabled={busy}> | |
| 167 | Save | |
| 168 | </Button> | |
| 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"> | |
| 178 | <Button variant="quiet" type="submit" name="intent" value="disable" disabled={busy}> | |
| 179 | Turn off deployments | |
| 180 | </Button> | |
| 181 | </Form> | |
| 182 | </section> | |
| 183 | </> | |
| 184 | )} | |
| 185 | </div> | |
| 186 | ); | |
| 187 | } |