g1t/apps/web/app/routes/repo/actions-run.tsx

283 lines12,774 bytesCodeBlame

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