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.
| Deployments: a preview for every pull request, production on g1t.page | 1 | import { ExternalLink, Globe, Rocket, RotateCw, Trash2 } from "lucide-react"; |
| 2 | import type { ReactNode } from "react"; | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 3 | import { Form, Link, useNavigation } from "react-router"; |
| Deployments: a preview for every pull request, production on g1t.page | 4 | |
| Projects: what a workspace builds and runs, first on every page | 5 | import type { Deployment, FeatureState } from "@g1t/contracts"; |
| Deployments: a preview for every pull request, production on g1t.page | 6 | |
| Projects: what a workspace builds and runs, first on every page | 7 | import { host, StatusDot } from "../../components/deploy"; |
| 8 | ||
| Deployments: a preview for every pull request, production on g1t.page | 9 | import type { Route } from "./+types/deployments"; |
| Social cards for every page: og.g1t.sh | 10 | import { page } from "../../lib/meta"; |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 11 | import { Button, ButtonLink, ComputeNote, EmptyState, ErrorText, TimeAgo } from "../../components/ui"; |
| 12 | import { computeNoteFor } from "../../lib/compute.server"; | |
| Deployments: a preview for every pull request, production on g1t.page | 13 | import { billing, deployments } from "../../lib/services.server"; |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 14 | import { assertSameOrigin, getViewer, requireUser, unwrap } from "../../lib/session.server"; |
| 15 | import { refusal, requireRepo } from "../../lib/access.server"; | |
| 16 | import { whyNot } from "../../lib/access"; | |
| Deployments: a preview for every pull request, production on g1t.page | 17 | |
| Social cards for every page: og.g1t.sh | 18 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 19 | return page(args, { title: `Deployments · ${params.owner}/${params.repo} · g1t` }); | |
| Deployments: a preview for every pull request, production on g1t.page | 20 | } |
| 21 | ||
| 22 | export async function loader({ params, context }: Route.LoaderArgs) { | |
| 23 | const viewer = getViewer(context); | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 24 | // Anyone who can read the repository: a public one's to anyone, a private one's to people with a role. |
| 25 | const { access } = await requireRepo(context, params, "read"); | |
| Projects: what a workspace builds and runs, first on every page | 26 | const ref = { workspace: params.owner, slug: params.repo }; |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 27 | const [settings, list, features, computeNote] = await Promise.all([ |
| Projects: what a workspace builds and runs, first on every page | 28 | deployments.settings(ref, viewer), |
| 29 | deployments.list(ref, viewer), | |
| Deployments: a preview for every pull request, production on g1t.page | 30 | billing.features(params.owner, viewer), |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 31 | // Builds are compute: said before a deploy is refused for it. |
| 32 | computeNoteFor(params.owner, "deploy"), | |
| Deployments: a preview for every pull request, production on g1t.page | 33 | ]); |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 34 | // Someone outside the workspace does not see its plans; the page works without. |
| 35 | const plan = features.ok ? (features.value.find((state) => state.plan.feature === "deployments") ?? null) : null; | |
| 36 | return { can: access.can, settings: unwrap(settings), ...unwrap(list), plan, computeNote }; | |
| Deployments: a preview for every pull request, production on g1t.page | 37 | } |
| 38 | ||
| 39 | export async function action({ request, params, context }: Route.ActionArgs) { | |
| 40 | assertSameOrigin(request); | |
| 41 | const user = requireUser(context, request); | |
| 42 | const form = await request.formData(); | |
| Projects: what a workspace builds and runs, first on every page | 43 | const ref = { workspace: params.owner, slug: params.repo }; |
| Deployments: a preview for every pull request, production on g1t.page | 44 | const intent = form.get("intent"); |
| Projects: what a workspace builds and runs, first on every page | 45 | const branch = form.get("branch") ? String(form.get("branch")) : null; |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 46 | // Deploying is compute (Write); turning deployments on or off is a deployment setting (Admin). |
| 47 | const refused = await refusal(context, params, intent === "enable" || intent === "disable" ? "manage_integrations" : "run"); | |
| 48 | if (refused) return { error: refused }; | |
| Deployments: a preview for every pull request, production on g1t.page | 49 | if (intent === "redeploy") { |
| Projects: what a workspace builds and runs, first on every page | 50 | const started = await deployments.redeploy(user, ref, branch); |
| Deployments: a preview for every pull request, production on g1t.page | 51 | return started.ok ? { notice: "Build started." } : { error: started.error.message }; |
| 52 | } | |
| 53 | if (intent === "take-down") { | |
| Projects: what a workspace builds and runs, first on every page | 54 | const done = await deployments.takeDown(user, ref, branch); |
| Deployments: a preview for every pull request, production on g1t.page | 55 | return done.ok ? { notice: "Taken down." } : { error: done.error.message }; |
| 56 | } | |
| 57 | if (intent === "enable" || intent === "disable") { | |
| Projects: what a workspace builds and runs, first on every page | 58 | const saved = await deployments.updateSettings(user, ref, { enabled: intent === "enable" }); |
| Deployments: a preview for every pull request, production on g1t.page | 59 | return saved.ok |
| 60 | ? { notice: intent === "enable" ? "Deployments are on. Production is building." : "Deployments are off, and every app is down." } | |
| 61 | : { error: saved.error.message }; | |
| 62 | } | |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 63 | return { error: "Unknown request." }; |
| Deployments: a preview for every pull request, production on g1t.page | 64 | } |
| 65 | ||
| 66 | export default function RepoDeployments({ loaderData, actionData, params }: Route.ComponentProps) { | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 67 | const { settings, deployments: builds, live, plan, can } = loaderData; |
| Deployments: a preview for every pull request, production on g1t.page | 68 | const busy = useNavigation().state === "submitting"; |
| 69 | const base = `/${params.owner}/${params.repo}`; | |
| 70 | const production = live.find((app) => app.kind === "production"); | |
| 71 | const previews = live.filter((app) => app.kind === "preview"); | |
| 72 | ||
| 73 | return ( | |
| 74 | <div className="mx-auto max-w-5xl"> | |
| 75 | <header className="flex flex-wrap items-start justify-between gap-4"> | |
| 76 | <div> | |
| 77 | <h1 className="flex items-center gap-2 text-xl font-semibold tracking-tight"> | |
| 78 | <Rocket size={18} className="text-accent" /> | |
| 79 | Deployments | |
| 80 | </h1> | |
| 81 | <p className="mt-1 max-w-2xl text-sm text-muted"> | |
| 82 | Every pull request gets a live preview on g1t.page, and the default branch goes to production on each push. | |
| 83 | Apps run on Cloudflare only while someone visits them.{" "} | |
| 84 | <a href="https://docs.g1t.sh/guides/deployments/" className="text-fg hover:underline"> | |
| 85 | How it works | |
| 86 | </a> | |
| 87 | </p> | |
| 88 | </div> | |
| 89 | {settings.enabled && ( | |
| 90 | <a | |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 91 | href={settings.primaryDomain ? `https://${settings.primaryDomain}` : settings.productionUrl} |
| Deployments: a preview for every pull request, production on g1t.page | 92 | className="inline-flex items-center gap-1.5 rounded-md border border-line px-3 py-1.5 font-mono text-xs text-muted hover:border-line-strong hover:text-fg" |
| 93 | > | |
| 94 | <Globe size={13} /> | |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 95 | {settings.primaryDomain ?? host(settings.productionUrl)} |
| Deployments: a preview for every pull request, production on g1t.page | 96 | </a> |
| 97 | )} | |
| 98 | </header> | |
| 99 | ||
| 100 | <div className="mt-4 min-h-6"> | |
| 101 | {actionData && "notice" in actionData && <p className="text-sm text-accent">{actionData.notice}</p>} | |
| 102 | <ErrorText>{actionData && "error" in actionData ? actionData.error : null}</ErrorText> | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 103 | {!actionData && <ComputeNote note={loaderData.computeNote} />} |
| Deployments: a preview for every pull request, production on g1t.page | 104 | </div> |
| 105 | ||
| 106 | {!plan?.on ? ( | |
| 107 | <PlanNeeded plan={plan} owner={params.owner} /> | |
| 108 | ) : !settings.enabled ? ( | |
| 109 | <section className="mt-2 rounded-xl border border-accent/30 bg-accent/5 p-6"> | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 110 | <h2 className="font-medium">Deployments are off</h2> |
| Deployments: a preview for every pull request, production on g1t.page | 111 | <p className="mt-1 max-w-2xl text-sm text-muted"> |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 112 | Each project turns deployments on for itself; until then nothing builds or runs. Once on, production goes |
| 113 | up at <span className="font-mono text-fg">{host(settings.productionUrl)}</span> and every open pull request | |
| 114 | gets its own preview. Workers projects (a <code className="font-mono text-fg">wrangler.jsonc</code>) and | |
| 115 | static sites deploy without configuration. | |
| Deployments: a preview for every pull request, production on g1t.page | 116 | </p> |
| 117 | <Form method="post" className="mt-4"> | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 118 | <Button variant="accent" type="submit" name="intent" value="enable" disabled={busy || !can.manage_integrations} title={whyNot(can, "manage_integrations")}> |
| Deployments: a preview for every pull request, production on g1t.page | 119 | <Rocket size={14} /> |
| 120 | Turn on deployments | |
| 121 | </Button> | |
| 122 | </Form> | |
| 123 | </section> | |
| 124 | ) : ( | |
| 125 | <> | |
| 126 | <section className="mt-2 grid gap-4 md:grid-cols-2"> | |
| 127 | <LiveCard | |
| 128 | title="Production" | |
| 129 | hint="The default branch, on every push." | |
| 130 | app={production} | |
| 131 | off={!settings.production} | |
| 132 | actions={ | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 133 | can.run ? <AppActions branch={null} up={!!production} busy={busy} /> : null |
| Deployments: a preview for every pull request, production on g1t.page | 134 | } |
| 135 | /> | |
| 136 | <div className="rounded-xl border border-line bg-surface p-5"> | |
| 137 | <h2 className="text-sm font-medium">Previews</h2> | |
| 138 | <p className="mt-0.5 text-xs text-faint"> | |
| 139 | {settings.previews | |
| Projects: what a workspace builds and runs, first on every page | 140 | ? `One per branch with an open pull request; down when it closes or after ${settings.idleDays} days without a visit.` |
| Deployments: a preview for every pull request, production on g1t.page | 141 | : "Off for this repository."} |
| 142 | </p> | |
| 143 | {previews.length === 0 ? ( | |
| 144 | <p className="mt-4 text-sm text-muted">No previews are up.</p> | |
| 145 | ) : ( | |
| 146 | <ul className="mt-3 divide-y divide-line"> | |
| 147 | {previews.map((app) => ( | |
| 148 | <li key={app.url} className="flex items-center gap-3 py-2 text-sm"> | |
| Projects: what a workspace builds and runs, first on every page | 149 | <span className="shrink-0"> |
| 150 | <span className="font-medium">{app.branch}</span> | |
| 151 | {app.number != null && ( | |
| 152 | <Link to={`${base}/pull/${app.number}`} className="ml-1.5 text-xs text-muted hover:underline"> | |
| 153 | #{app.number} | |
| 154 | </Link> | |
| 155 | )} | |
| 156 | </span> | |
| Deployments: a preview for every pull request, production on g1t.page | 157 | <a href={app.url} className="min-w-0 truncate font-mono text-xs text-muted hover:text-fg"> |
| Projects: what a workspace builds and runs, first on every page | 158 | {host(app.url)} |
| Deployments: a preview for every pull request, production on g1t.page | 159 | </a> |
| 160 | <span className="ml-auto shrink-0"> | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 161 | {can.run && <AppActions branch={app.branch} up busy={busy} compact />} |
| Deployments: a preview for every pull request, production on g1t.page | 162 | </span> |
| 163 | </li> | |
| 164 | ))} | |
| 165 | </ul> | |
| 166 | )} | |
| 167 | </div> | |
| 168 | </section> | |
| 169 | ||
| 170 | <h2 className="mt-10 text-sm font-medium text-muted">Recent builds</h2> | |
| 171 | <div className="mt-3"> | |
| 172 | {builds.length === 0 ? ( | |
| 173 | <EmptyState title="No builds yet">Push to the default branch or open a pull request.</EmptyState> | |
| 174 | ) : ( | |
| 175 | <ul className="divide-y divide-line overflow-hidden rounded-xl border border-line"> | |
| 176 | {builds.map((build) => ( | |
| 177 | <BuildRow key={build.id} build={build} base={base} /> | |
| 178 | ))} | |
| 179 | </ul> | |
| 180 | )} | |
| 181 | </div> | |
| 182 | ||
| Secrets and variables: one list, rows per environment, for workflows and deployments | 183 | <p className="mt-10 text-sm text-muted"> |
| 184 | Build command, output directory, idle days, and turning deployments off are under{" "} | |
| 185 | <Link to={`${base}/settings/deployments`} className="text-fg hover:underline"> | |
| 186 | Settings → Deployments | |
| 187 | </Link> | |
| 188 | . Secrets and config for builds and running apps are under{" "} | |
| 189 | <Link to={`${base}/settings/secrets`} className="text-fg hover:underline"> | |
| 190 | Settings → Secrets and variables | |
| 191 | </Link> | |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 192 | , and production's own domains under{" "} |
| 193 | <Link to={`${base}/settings/domains`} className="text-fg hover:underline"> | |
| 194 | Settings → Domains | |
| 195 | </Link> | |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 196 | . |
| 197 | </p> | |
| Deployments: a preview for every pull request, production on g1t.page | 198 | </> |
| 199 | )} | |
| 200 | </div> | |
| 201 | ); | |
| 202 | } | |
| 203 | ||
| 204 | function PlanNeeded({ plan, owner }: { plan: FeatureState | null; owner: string }) { | |
| 205 | return ( | |
| 206 | <section className="mt-2 rounded-xl border border-accent/30 bg-accent/5 p-6"> | |
| 207 | <h2 className="font-medium">Deployments are part of a paid plan</h2> | |
| 208 | <p className="mt-1 max-w-2xl text-sm text-muted"> | |
| Projects: what a workspace builds and runs, first on every page | 209 | Turn on Deployments for the {owner} workspace and every project in it can have a preview for each pull |
| Deployments: a preview for every pull request, production on g1t.page | 210 | request and production on g1t.page. |
| 211 | {plan && ` $${(plan.plan.monthlyCents / 100).toFixed(0)} a month, including:`} | |
| 212 | </p> | |
| 213 | {plan && ( | |
| 214 | <ul className="mt-3 grid gap-1.5 text-sm text-muted sm:grid-cols-2"> | |
| 215 | {plan.plan.includes.map((line) => ( | |
| 216 | <li key={line} className="flex gap-2"> | |
| 217 | <span className="text-accent">✓</span> | |
| 218 | {line} | |
| 219 | </li> | |
| 220 | ))} | |
| 221 | </ul> | |
| 222 | )} | |
| 223 | {plan && <p className="mt-3 text-xs text-faint">{plan.plan.overage}</p>} | |
| 224 | <div className="mt-4"> | |
| 225 | <ButtonLink variant="accent" to={`/${owner}/-/billing`}> | |
| 226 | See the plan under Billing | |
| 227 | </ButtonLink> | |
| 228 | </div> | |
| 229 | </section> | |
| 230 | ); | |
| 231 | } | |
| 232 | ||
| 233 | function LiveCard({ | |
| 234 | title, | |
| 235 | hint, | |
| 236 | app, | |
| 237 | off, | |
| 238 | actions, | |
| 239 | }: { | |
| 240 | title: string; | |
| 241 | hint: string; | |
| 242 | app: { url: string; commit: string; deployedAt: string } | undefined; | |
| 243 | off: boolean; | |
| 244 | actions: ReactNode; | |
| 245 | }) { | |
| 246 | return ( | |
| 247 | <div className="rounded-xl border border-line bg-surface p-5"> | |
| 248 | <h2 className="text-sm font-medium">{title}</h2> | |
| 249 | <p className="mt-0.5 text-xs text-faint">{off ? "Off for this repository." : hint}</p> | |
| 250 | {app ? ( | |
| 251 | <> | |
| 252 | <a href={app.url} className="mt-3 flex items-center gap-1.5 font-mono text-sm text-accent hover:underline"> | |
| Projects: what a workspace builds and runs, first on every page | 253 | {host(app.url)} |
| Deployments: a preview for every pull request, production on g1t.page | 254 | <ExternalLink size={12} /> |
| 255 | </a> | |
| 256 | <p className="mt-1 text-xs text-faint"> | |
| 257 | <span className="font-mono">{app.commit.slice(0, 8)}</span> · deployed <TimeAgo at={app.deployedAt} /> | |
| 258 | </p> | |
| 259 | </> | |
| 260 | ) : ( | |
| 261 | <p className="mt-4 text-sm text-muted">Not up.</p> | |
| 262 | )} | |
| 263 | {!off && <div className="mt-4">{actions}</div>} | |
| 264 | </div> | |
| 265 | ); | |
| 266 | } | |
| 267 | ||
| Projects: what a workspace builds and runs, first on every page | 268 | function AppActions({ branch, up, busy, compact }: { branch: string | null; up: boolean; busy: boolean; compact?: boolean }) { |
| Deployments: a preview for every pull request, production on g1t.page | 269 | return ( |
| 270 | <Form method="post" className="flex items-center gap-2"> | |
| Projects: what a workspace builds and runs, first on every page | 271 | {branch != null && <input type="hidden" name="branch" value={branch} />} |
| Deployments: a preview for every pull request, production on g1t.page | 272 | <Button variant="quiet" type="submit" name="intent" value="redeploy" disabled={busy} title="Build again from the current head"> |
| 273 | <RotateCw size={13} /> | |
| 274 | {!compact && "Redeploy"} | |
| 275 | </Button> | |
| 276 | {up && ( | |
| 277 | <Button variant="quiet" type="submit" name="intent" value="take-down" disabled={busy} title="Take it down now"> | |
| 278 | <Trash2 size={13} /> | |
| 279 | {!compact && "Take down"} | |
| 280 | </Button> | |
| 281 | )} | |
| 282 | </Form> | |
| 283 | ); | |
| 284 | } | |
| 285 | ||
| 286 | function BuildRow({ build, base }: { build: Deployment; base: string }) { | |
| 287 | return ( | |
| 288 | <li> | |
| 289 | <Link to={`${base}/deployments/${build.id}`} className="flex items-center gap-4 px-4 py-3 text-sm hover:bg-surface"> | |
| 290 | <span className="w-20 shrink-0"> | |
| 291 | <StatusDot status={build.status} /> | |
| 292 | </span> | |
| 293 | <span className="min-w-0 grow"> | |
| 294 | <span className="block truncate font-medium"> | |
| Projects: what a workspace builds and runs, first on every page | 295 | {build.kind === "production" ? "Production" : `Preview of ${build.branch}`} |
| Deployments: a preview for every pull request, production on g1t.page | 296 | <span className="ml-2 font-mono text-xs font-normal text-faint">{build.commit.slice(0, 8)}</span> |
| 297 | </span> | |
| 298 | {build.error && <span className="mt-0.5 block truncate text-xs text-muted">{build.error}</span>} | |
| 299 | </span> | |
| 300 | <span className="shrink-0 text-xs text-faint"> | |
| 301 | {build.buildSeconds != null && `${build.buildSeconds} s · `} | |
| 302 | <TimeAgo at={build.createdAt} /> | |
| 303 | </span> | |
| 304 | </Link> | |
| 305 | </li> | |
| 306 | ); | |
| 307 | } |