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

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