g1t/apps/web/app/routes/repo/actions-run.tsx
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.
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 1 | import { AlertTriangle, ChevronRight, Download, GitBranch, GitCommitHorizontal, Info, Package, RotateCw, Square, XCircle } from "lucide-react"; |
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 2 | import { type ReactNode, useEffect } from "react"; |
| 3 | import { Form, Link, useNavigation, useRevalidator, useSearchParams } from "react-router"; | |
| 4 | ||
| 5 | import type { Annotation, Job, StepState } from "@g1t/contracts"; | |
| 6 | ||
| 7 | import type { Route } from "./+types/actions-run"; | |
| Social cards for every page: og.g1t.sh | 8 | import { page } from "../../lib/meta"; |
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 9 | import { LogText, Notes, StatusIcon, duration, shortRef, standingWord, useJobLog } from "../../components/actions"; |
| 10 | import { Button, ErrorText, TimeAgo } from "../../components/ui"; | |
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 11 | import { listArtifacts } from "../../lib/artifacts.server"; |
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 12 | import { actions } from "../../lib/services.server"; |
| 13 | import { assertSameOrigin, getViewer, requireUser, roleIn, unwrap } from "../../lib/session.server"; | |
| 14 | ||
| Social cards for every page: og.g1t.sh | 15 | export function meta({ loaderData, params, ...args }: Route.MetaArgs) { |
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 16 | const run = loaderData?.detail.run; |
| Social cards for every page: og.g1t.sh | 17 | return page(args, { title: `${run ? `${run.title || run.name} #${run.number}` : "Run"} · ${params.owner}/${params.repo} · g1t` }); |
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 18 | } |
| 19 | ||
| 20 | export async function loader({ params, context }: Route.LoaderArgs) { | |
| 21 | const viewer = getViewer(context); | |
| 22 | const detail = unwrap(await actions.run({ namespace: params.owner, name: params.repo }, viewer, params.id)); | |
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 23 | const artifacts = await listArtifacts(params.id).catch(() => []); |
| 24 | return { detail, artifacts, member: roleIn(viewer, params.owner) != null }; | |
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 25 | } |
| 26 | ||
| 27 | export async function action({ request, params, context }: Route.ActionArgs) { | |
| 28 | assertSameOrigin(request); | |
| 29 | const user = requireUser(context, request); | |
| 30 | const repo = { namespace: params.owner, name: params.repo }; | |
| 31 | const intent = String((await request.formData()).get("intent")); | |
| 32 | const done = | |
| 33 | intent === "cancel" | |
| 34 | ? await actions.cancel(user, repo, params.id) | |
| 35 | : await actions.rerun(user, repo, params.id, intent === "rerun-failed"); | |
| 36 | return done.ok ? {} : { error: done.error.message }; | |
| 37 | } | |
| 38 | ||
| 39 | const ANNOTATION_ICON: Record<Annotation["level"], ReactNode> = { | |
| 40 | error: <XCircle size={14} className="mt-0.5 shrink-0 text-danger" />, | |
| 41 | warning: <AlertTriangle size={14} className="mt-0.5 shrink-0 text-warn" />, | |
| 42 | notice: <Info size={14} className="mt-0.5 shrink-0 text-muted" />, | |
| 43 | }; | |
| 44 | ||
| 45 | function StepRow({ step, text, defaultOpen }: { step: StepState; text: string | undefined; defaultOpen: boolean }) { | |
| 46 | return ( | |
| 47 | <details className="group border-t border-line first:border-t-0" open={defaultOpen}> | |
| 48 | <summary className="flex cursor-pointer list-none items-center gap-2.5 px-4 py-2 text-sm hover:bg-raised/40"> | |
| 49 | <ChevronRight size={14} className="shrink-0 text-faint transition-transform group-open:rotate-90" /> | |
| 50 | <StatusIcon status={step.status} conclusion={step.conclusion} size={14} /> | |
| 51 | <span className={`min-w-0 truncate ${step.conclusion === "skipped" ? "text-faint" : ""}`}>{step.name}</span> | |
| 52 | <span className="ml-auto shrink-0 font-mono text-xs text-faint">{duration(step.startedAt, step.finishedAt)}</span> | |
| 53 | </summary> | |
| 54 | <div className="border-t border-line bg-bg/60"> | |
| 55 | {text === undefined ? ( | |
| 56 | <p className="px-4 py-2 text-xs text-faint">{step.status === "queued" ? "Not started." : step.conclusion === "skipped" ? "Skipped." : "No output yet."}</p> | |
| 57 | ) : ( | |
| 58 | <LogText text={text} /> | |
| 59 | )} | |
| 60 | </div> | |
| 61 | </details> | |
| 62 | ); | |
| 63 | } | |
| 64 | ||
| New workspaces are told to connect a model, before anything fails | 65 | /** Why a job did not run as asked, with "Integrations" linked where it says so. */ |
| 66 | function Reason({ text, workspace }: { text: string; workspace: string }) { | |
| 67 | const [before, after] = text.split("Integrations"); | |
| 68 | return ( | |
| 69 | <p className="rounded-lg bg-raised px-3 py-2 text-sm text-muted"> | |
| 70 | {after === undefined ? ( | |
| 71 | text | |
| 72 | ) : ( | |
| 73 | <> | |
| 74 | {before} | |
| 75 | <Link to={`/${workspace}/-/integrations`} className="text-accent hover:underline"> | |
| 76 | Integrations | |
| 77 | </Link> | |
| 78 | {after} | |
| 79 | </> | |
| 80 | )} | |
| 81 | </p> | |
| 82 | ); | |
| 83 | } | |
| 84 | ||
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 85 | function JobView({ job, base }: { job: Job; base: string }) { |
| 86 | const live = job.status !== "completed"; | |
| 87 | const log = useJobLog(`${base}/actions/jobs/${job.id}/log`, live); | |
| 88 | const failed = job.steps.find((s) => s.conclusion === "failure"); | |
| 89 | const running = job.steps.find((s) => s.status === "in_progress"); | |
| 90 | return ( | |
| 91 | <section className="min-w-0 space-y-4"> | |
| 92 | <div className="flex flex-wrap items-center gap-3"> | |
| 93 | <StatusIcon status={job.status} conclusion={job.conclusion} size={18} /> | |
| 94 | <h3 className="text-base font-semibold">{job.name}</h3> | |
| 95 | <span className="text-sm text-muted"> | |
| 96 | {standingWord(job)} | |
| 97 | {job.startedAt && ` · ${duration(job.startedAt, job.finishedAt)}`} | |
| 98 | </span> | |
| 99 | </div> | |
| New workspaces are told to connect a model, before anything fails | 100 | {job.reason && <Reason text={job.reason} workspace={base.split("/")[1]} />} |
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 101 | {job.annotations.length > 0 && ( |
| 102 | <ul className="space-y-2 rounded-xl border border-line bg-surface p-4 text-sm"> | |
| 103 | {job.annotations.map((note, index) => ( | |
| 104 | <li key={index} className="flex gap-2"> | |
| 105 | {ANNOTATION_ICON[note.level]} | |
| 106 | <span className="min-w-0"> | |
| 107 | {note.title && <span className="font-medium">{note.title}: </span>} | |
| 108 | <span className="whitespace-pre-wrap">{note.message}</span> | |
| 109 | {note.file && ( | |
| 110 | <span className="block font-mono text-xs text-faint"> | |
| 111 | {note.file} | |
| 112 | {note.line != null && `:${note.line}`} | |
| 113 | </span> | |
| 114 | )} | |
| 115 | </span> | |
| 116 | </li> | |
| 117 | ))} | |
| 118 | </ul> | |
| 119 | )} | |
| 120 | <div className="overflow-hidden rounded-xl border border-line bg-surface"> | |
| 121 | <StepRow | |
| 122 | step={{ number: 0, name: "Set up job", status: job.startedAt ? "completed" : "queued", conclusion: job.startedAt ? "success" : null, startedAt: job.startedAt, finishedAt: job.startedAt }} | |
| 123 | text={log.get(0)} | |
| 124 | defaultOpen={false} | |
| 125 | /> | |
| 126 | {job.steps.map((step) => ( | |
| 127 | <StepRow | |
| 128 | key={step.number} | |
| 129 | step={step} | |
| 130 | text={log.get(step.number)} | |
| 131 | defaultOpen={step.number === (failed ?? running)?.number} | |
| 132 | /> | |
| 133 | ))} | |
| 134 | </div> | |
| 135 | </section> | |
| 136 | ); | |
| 137 | } | |
| 138 | ||
| 139 | export default function ActionsRun({ loaderData, actionData, params }: Route.ComponentProps) { | |
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 140 | const { detail, artifacts, member } = loaderData; |
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 141 | const { run, jobs, notes } = detail; |
| 142 | const base = `/${params.owner}/${params.repo}`; | |
| 143 | const [search] = useSearchParams(); | |
| 144 | const busy = useNavigation().state === "submitting"; | |
| 145 | const revalidator = useRevalidator(); | |
| 146 | const live = run.status !== "completed"; | |
| 147 | useEffect(() => { | |
| 148 | if (!live) return; | |
| 149 | const timer = setInterval(() => { | |
| 150 | if (revalidator.state === "idle" && document.visibilityState === "visible") revalidator.revalidate(); | |
| 151 | }, 2500); | |
| 152 | return () => clearInterval(timer); | |
| 153 | }, [live, revalidator]); | |
| 154 | ||
| 155 | // The job asked for, else one that failed, is running, or the first. | |
| 156 | const selected = | |
| 157 | jobs.find((job) => job.id === search.get("job")) ?? | |
| 158 | jobs.find((job) => job.conclusion === "failure" && job.steps.length > 0) ?? | |
| 159 | jobs.find((job) => job.status === "in_progress") ?? | |
| 160 | jobs[0]; | |
| 161 | const anyFailed = jobs.some((job) => job.conclusion === "failure" || job.conclusion === "cancelled"); | |
| 162 | ||
| 163 | return ( | |
| 164 | <div className="max-w-6xl space-y-6"> | |
| 165 | <header className="space-y-3"> | |
| 166 | <Link to={`${base}/actions?workflow=${run.workflowId}`} className="text-sm text-muted hover:text-fg"> | |
| 167 | {run.name} | |
| 168 | </Link> | |
| 169 | <div className="flex flex-wrap items-start justify-between gap-4"> | |
| 170 | <h2 className="flex min-w-0 items-center gap-2.5 text-xl font-semibold tracking-tight"> | |
| 171 | <StatusIcon status={run.status} conclusion={run.conclusion} size={20} /> | |
| 172 | <span className="min-w-0 truncate">{run.title || run.name}</span> | |
| 173 | <span className="font-normal text-muted">#{run.number}</span> | |
| 174 | </h2> | |
| 175 | {member && !run.error && ( | |
| 176 | <Form method="post" className="flex gap-2"> | |
| 177 | {live ? ( | |
| 178 | <Button type="submit" name="intent" value="cancel" variant="quiet" disabled={busy}> | |
| 179 | <Square size={13} /> | |
| 180 | Cancel run | |
| 181 | </Button> | |
| 182 | ) : ( | |
| 183 | <> | |
| 184 | {anyFailed && ( | |
| 185 | <Button type="submit" name="intent" value="rerun-failed" variant="quiet" disabled={busy}> | |
| 186 | <RotateCw size={13} /> | |
| 187 | Re-run failed jobs | |
| 188 | </Button> | |
| 189 | )} | |
| 190 | <Button type="submit" name="intent" value="rerun" variant="quiet" disabled={busy}> | |
| 191 | <RotateCw size={13} /> | |
| 192 | Re-run all jobs | |
| 193 | </Button> | |
| 194 | </> | |
| 195 | )} | |
| 196 | </Form> | |
| 197 | )} | |
| 198 | </div> | |
| 199 | <p className="flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted"> | |
| 200 | <span>{standingWord(run)}</span> | |
| 201 | <span className="inline-flex items-center gap-1 font-mono text-xs"> | |
| 202 | <GitBranch size={12} /> | |
| 203 | {shortRef(run.ref)} | |
| 204 | </span> | |
| 205 | <Link to={`${base}/commit/${run.sha}`} className="inline-flex items-center gap-1 font-mono text-xs hover:text-fg"> | |
| 206 | <GitCommitHorizontal size={12} /> | |
| 207 | {run.sha.slice(0, 7)} | |
| 208 | </Link> | |
| 209 | {run.pull != null && ( | |
| 210 | <Link to={`${base}/pull/${run.pull}`} className="hover:text-fg"> | |
| 211 | #{run.pull} | |
| 212 | </Link> | |
| 213 | )} | |
| 214 | <span> | |
| 215 | {run.event} | |
| 216 | {run.actor && ` by ${run.actor}`} · <TimeAgo at={run.createdAt} /> | |
| 217 | </span> | |
| 218 | {run.startedAt && <span className="font-mono text-xs">{duration(run.startedAt, run.finishedAt)}</span>} | |
| 219 | {run.attempt > 1 && <span>Attempt {run.attempt}</span>} | |
| 220 | </p> | |
| 221 | </header> | |
| 222 | ||
| 223 | <ErrorText>{actionData && "error" in actionData ? actionData.error : null}</ErrorText> | |
| 224 | {run.error && ( | |
| 225 | <div className="rounded-xl border border-danger/30 bg-danger/5 p-4 text-sm"> | |
| 226 | <p className="font-medium text-danger">The workflow file could not be used</p> | |
| 227 | <p className="mt-1 whitespace-pre-wrap text-fg/85">{run.error}</p> | |
| 228 | </div> | |
| 229 | )} | |
| 230 | <Notes notes={notes} /> | |
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 231 | {artifacts.length > 0 && ( |
| 232 | <section className="rounded-xl border border-line bg-surface p-4"> | |
| 233 | <h3 className="flex items-center gap-2 text-sm font-medium"> | |
| 234 | <Package size={14} className="text-muted" /> | |
| 235 | Artifacts | |
| 236 | <span className="font-normal text-faint">· kept for 14 days</span> | |
| 237 | </h3> | |
| 238 | <ul className="mt-3 divide-y divide-line text-sm"> | |
| 239 | {artifacts.map((artifact) => ( | |
| 240 | <li key={artifact.name} className="flex items-center gap-3 py-2"> | |
| 241 | <span className="min-w-0 grow truncate font-mono text-[0.8125rem]">{artifact.name}</span> | |
| 242 | <span className="shrink-0 text-xs text-faint">{Math.max(1, Math.round(artifact.size / 1024))} KB</span> | |
| 243 | <a | |
| 244 | href={`${base}/actions/runs/${run.id}/artifacts/${encodeURIComponent(artifact.name)}`} | |
| 245 | className="inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs text-muted ring-1 ring-line hover:text-fg" | |
| 246 | > | |
| 247 | <Download size={12} /> | |
| 248 | Download | |
| 249 | </a> | |
| 250 | </li> | |
| 251 | ))} | |
| 252 | </ul> | |
| 253 | </section> | |
| 254 | )} | |
| GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs | 255 | |
| 256 | {jobs.length > 0 && ( | |
| 257 | <div className="grid gap-6 lg:grid-cols-[15rem_1fr]"> | |
| 258 | <nav aria-label="Jobs" className="space-y-0.5 text-sm"> | |
| 259 | {jobs.map((job) => ( | |
| 260 | <Link | |
| 261 | key={job.id} | |
| 262 | to={`?job=${job.id}`} | |
| 263 | preventScrollReset | |
| 264 | className={`flex items-center gap-2 rounded-md px-2.5 py-1.5 ${ | |
| 265 | job.id === selected?.id ? "bg-raised text-fg" : "text-muted hover:bg-raised/60 hover:text-fg" | |
| 266 | }`} | |
| 267 | > | |
| 268 | <StatusIcon status={job.status} conclusion={job.conclusion} size={14} /> | |
| 269 | <span className="min-w-0 truncate">{job.name}</span> | |
| 270 | <span className="ml-auto shrink-0 font-mono text-xs text-faint">{duration(job.startedAt, job.finishedAt)}</span> | |
| 271 | </Link> | |
| 272 | ))} | |
| 273 | </nav> | |
| 274 | {selected && <JobView key={selected.id} job={selected} base={base} />} | |
| 275 | </div> | |
| 276 | )} | |
| 277 | </div> | |
| 278 | ); | |
| 279 | } |