Skip to content
417 linesCodeBlameRaw

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.

GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs1import type { User, Viewer } from "./identity";
2import type { RepoPath } from "./repos";
3import type { Result } from "./result";
4
5/**
6 * GitHub Actions workflows, run on g1t as they are. Mirrors
7 * `crates/contracts/src/actions.rs`.
8 */
9
10export type WorkflowNote = {
11 severity: "info" | "warning" | "unsupported";
12 job: string | null;
13 message: string;
14};
15
16/** One `workflow_dispatch` input, as written in the workflow. */
17export type DispatchInput = {
18 description?: string;
19 required?: boolean;
20 default?: string | number | boolean;
21 type?: "string" | "boolean" | "number" | "choice" | "environment";
22 options?: string[];
23};
24
Merge branch 'worktree-agent-a3abfcce648e87dca'25/**
26 * `action_required`: a pull request's run from outside, waiting for someone
27 * with the Write role to approve it. `waiting`: its jobs are held by an
28 * environment's protection rules (a run's detail says so; lists do not).
29 */
30export type RunStatus = "pending" | "action_required" | "queued" | "in_progress" | "waiting" | "completed";
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs31export type Conclusion = "success" | "failure" | "cancelled" | "skipped";
32
33export type WorkflowRun = {
34 id: string;
35 workflowId: string;
36 path: string;
37 name: string;
38 title: string;
39 number: number;
40 attempt: number;
41 event: string;
42 ref: string;
43 sha: string;
44 pull: number | null;
45 status: RunStatus;
46 conclusion: Conclusion | null;
47 error: string | null;
48 actor: string | null;
49 createdAt: string;
50 startedAt: string | null;
51 finishedAt: string | null;
52};
53
54export type Workflow = {
55 id: string;
56 path: string;
57 name: string;
58 events: string[];
59 state: "active" | "disabled";
60 error: string | null;
61 notes: WorkflowNote[];
62 dispatch: Record<string, DispatchInput> | null;
63 lastRun: WorkflowRun | null;
64};
65
66export type StepState = {
67 number: number;
68 name: string;
69 status: "queued" | "in_progress" | "completed";
70 conclusion: Conclusion | null;
71 startedAt: string | null;
72 finishedAt: string | null;
73};
74
75export type Annotation = {
76 level: "error" | "warning" | "notice";
77 message: string;
78 title: string | null;
79 file: string | null;
80 line: number | null;
81};
82
83export type Job = {
84 id: string;
85 runId: string;
86 key: string;
87 name: string;
88 needs: string[];
Merge branch 'worktree-agent-a3abfcce648e87dca'89 /**
90 * `calling`: running the reusable workflow it calls, whose jobs follow it.
91 * `pending`: held by its environment's protection rules; `reason` says for what.
92 */
93 status: "waiting" | "pending" | "queued" | "in_progress" | "calling" | "completed";
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs94 conclusion: Conclusion | null;
95 steps: StepState[];
96 annotations: Annotation[];
97 reason: string | null;
98 startedAt: string | null;
99 finishedAt: string | null;
Merge branch 'worktree-agent-a3abfcce648e87dca'100 /** The environment it names, once its needs are done. */
101 environment?: string | null;
Fast pages, required checks on the branch, self-hosted runners, honest incidents102 /** Its `runs-on` names self-hosted runners. */
103 selfHosted?: boolean;
104 /** The self-hosted runner that took it, by name. */
105 runner?: string | null;
Run page: job summaries, attempts, re-run a job, debug, log search and downloads106 /** Cancelled, and running its `if: always()` and `cancelled()` steps and post steps before it ends. */
107 cancelling?: boolean;
108};
109
110/** One attempt of a run: the first, or a re-run. */
111export type RunAttempt = {
112 attempt: number;
113 status: RunStatus;
114 conclusion: Conclusion | null;
115 /** Who started it: whoever caused the run, then whoever re-ran it. */
116 actor: string | null;
117 /** It ran with debug logging. */
118 debug: boolean;
119 startedAt: string | null;
120 finishedAt: string | null;
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs121};
122
Run page: job summaries, attempts, re-run a job, debug, log search and downloads123/** What a job's steps wrote to `$GITHUB_STEP_SUMMARY`, in Markdown, masked. */
124export type JobSummary = { jobId: string; name: string; steps: { step: number; markdown: string }[] };
125
126/** A job's whole log, to download. `omitted`: left out of a run's logs that grew too large. */
127export type JobLogText = {
128 jobId: string;
129 name: string;
130 steps: StepState[];
131 chunks: LogChunk[];
132 done: boolean;
133 omitted?: boolean;
134};
135
Merge branch 'worktree-agent-a3abfcce648e87dca'136export type RunDetail = {
137 run: WorkflowRun;
138 jobs: Job[];
139 notes: WorkflowNote[];
140 /** For a pull request's run from outside: whether it waits for, or had, approval. */
141 approval?: RunApproval | null;
142 /** The environments whose protection rules hold its jobs, this attempt. */
143 pendingDeployments?: PendingDeployment[];
Run page: job summaries, attempts, re-run a job, debug, log search and downloads144 /** Every attempt, oldest first, the one shown (`run.attempt`) included. */
145 attempts?: RunAttempt[];
Merge branch 'worktree-agent-a3abfcce648e87dca'146};
147
148export type RunApproval = {
149 state: "required" | "approved";
150 /** Why it waits, in words. */
151 reason: string;
152 approvedBy: string | null;
153};
154
155/** One person or team who may approve an environment's jobs. */
156export type EnvironmentReviewer = { type: "user" | "team"; name: string };
157
158/** A branch or tag pattern an environment takes deployments from. */
159export type BranchPattern = { name: string; type: "branch" | "tag" };
160
161/** The most reviewers an environment may have. */
162export const MAX_ENVIRONMENT_REVIEWERS = 6;
163/** The longest wait timer, in minutes (30 days). */
164export const MAX_WAIT_MINUTES = 43_200;
165
166/**
167 * An environment and its protection rules. Jobs naming it with
168 * `environment:` wait until the rules let them through, and only then get
169 * its secrets.
170 */
171export type Environment = {
172 /** Lowercase. */
173 name: string;
174 reviewers: EnvironmentReviewer[];
175 preventSelfReview: boolean;
176 waitMinutes: number;
177 /** `protected`: branches the rules protect; `selected`: `branchPatterns`. */
178 branchPolicy: "all" | "protected" | "selected";
179 branchPatterns: BranchPattern[];
180 adminsBypass: boolean;
181 /** Whether it has rules saved; false for one only named by a workflow or a secret. */
182 protected: boolean;
183 updatedAt: string | null;
184 updatedBy: string | null;
185};
186
187/** What changes an environment's rules; left out is unchanged. */
188export type EnvironmentChange = Partial<
189 Pick<Environment, "reviewers" | "preventSelfReview" | "waitMinutes" | "branchPolicy" | "branchPatterns" | "adminsBypass">
190>;
191
192/** An environment holding a run's jobs, and where its rules stand. */
193export type PendingDeployment = {
194 environment: string;
195 state: "waiting" | "approved" | "rejected";
196 needsReview: boolean;
197 /** When its wait timer lets its jobs start. */
198 waitUntil: string | null;
199 reviewers: EnvironmentReviewer[];
200 /** The jobs it holds, by name. */
201 jobs: string[];
202 /** Whether the viewer may approve or reject it now. */
203 canReview: boolean;
204 reviewedBy: string | null;
205 comment: string | null;
206 reviewedAt: string | null;
207};
208
209/** Which pull requests' runs wait for approval, least strict first. */
210export const APPROVAL_POLICIES = ["first_time_contributors", "outside_contributors", "all_external_contributors"] as const;
211export type ApprovalPolicy = (typeof APPROVAL_POLICIES)[number];
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs212
Merge branch 'worktree-agent-a3abfcce648e87dca'213/** A repository's choices for its workflows. */
214export type ActionsSettings = {
215 /**
216 * What a workflow without `permissions:` gets. Unchosen, a repository made
217 * before restricted tokens keeps `write`; a newer one takes its
218 * workspace's default. Never more than `maxPermissions`.
219 */
220 defaultPermissions: "read" | "write";
221 /** Whether the repository chose it. */
222 defaultChosen: boolean;
223 /** The most the workspace lets a repository's default be. */
224 maxPermissions: "read" | "write";
225 approvalPolicy: ApprovalPolicy;
226 /** "Allow g1t Actions to create and approve pull requests". */
227 canApprovePullRequests: boolean;
228 /** Whether the workspace lets its repositories turn that on. */
229 workspaceAllowsPullRequests: boolean;
230};
231
232/** What changes a repository's choices; `inherit` unchooses its default. */
233export type ActionsSettingsChange = {
234 defaultPermissions?: "read" | "write" | "inherit";
235 approvalPolicy?: ApprovalPolicy;
236 canApprovePullRequests?: boolean;
237};
238
239/** A workspace's policy for its repositories' job tokens. */
240export type WorkspaceActionsSettings = {
241 /** What a repository made from now on gets by default. */
242 defaultPermissions: "read" | "write";
243 /** The most any repository's default may be. */
244 maxPermissions: "read" | "write";
245 canApprovePullRequests: boolean;
246};
247
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs248export type LogChunk = { seq: number; step: number; text: string };
249export type JobLog = { chunks: LogChunk[]; done: boolean };
250
Secrets and variables: one list, rows per environment, for workflows and deployments251/**
252 * Who may read a secret or variable: `workflows` (`secrets.*`, `vars.*` in
253 * GitHub Actions) and `deployments` (a deploy build's environment and the
254 * running app's bindings). Agents, checks and the merge queue never read
255 * any.
256 */
257export type SettingReader = "workflows" | "deployments";
258
259/**
260 * One row of secrets and variables, as Vercel lists environment variables:
261 * a key, its type, the environments it applies to and who reads it. A key
262 * may have one row per environment. Secrets' values are never returned.
263 */
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs264export type Setting = {
Secrets and variables: one list, rows per environment, for workflows and deployments265 id: string;
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs266 name: string;
Secrets and variables: one list, rows per environment, for workflows and deployments267 /** `variable` is shown as Config. Config may become a secret, never back. */
268 kind: SettingKind;
269 /** A variable's value. */
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs270 value: string | null;
Projects: what a workspace builds and runs, first on every page271 /** A project's (a repository's belong to its project) or the workspace's. */
272 scope: "project" | "workspace";
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs273 updatedAt: string;
Secrets and variables: one list, rows per environment, for workflows and deployments274 availableTo: SettingReader[];
275 /** The environments it applies to; empty is every environment. */
276 environments: string[];
Projects: what a workspace builds and runs, first on every page277 /** A workspace's row: the projects it reaches, by slug; empty is every one. */
278 projects: string[];
Secrets and variables: one list, rows per environment, for workflows and deployments279 /** Where to rotate it, or who to ask. */
280 note: string | null;
281 updatedBy: string | null;
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs282};
283
Secrets and variables: one list, rows per environment, for workflows and deployments284/** What saving a row sets beyond its value; left out is unchanged. */
285export type SettingOptions = {
286 /** The row to change; left out, the key's row for every environment. */
287 id?: string;
288 availableTo?: SettingReader[];
289 environments?: string[];
Projects: what a workspace builds and runs, first on every page290 /** A workspace's row: project slugs; empty for every one. */
291 projects?: string[];
Secrets and variables: one list, rows per environment, for workflows and deployments292 note?: string;
293};
294
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs295export type SettingsOwner = { repo: RepoPath } | { workspace: string };
296export type SettingKind = "secret" | "variable";
Secrets and variables: one list, rows per environment, for workflows and deployments297/** `all` lists both. */
298export type SettingKindFilter = SettingKind | "all";
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs299
300export type RunsFilter = {
301 workflow?: string;
302 branch?: string;
303 event?: string;
304 pull?: number;
305 sha?: string;
306 limit?: number;
307};
308
309export interface ActionsApi {
310 workflows(repo: RepoPath, viewer: Viewer): Promise<Result<Workflow[]>>;
311 runs(repo: RepoPath, viewer: Viewer, filter?: RunsFilter): Promise<Result<WorkflowRun[]>>;
Run page: job summaries, attempts, re-run a job, debug, log search and downloads312 /** The latest attempt, or an earlier one. */
313 run(repo: RepoPath, viewer: Viewer, id: string, attempt?: number): Promise<Result<RunDetail>>;
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs314 logs(repo: RepoPath, viewer: Viewer, job: string, after?: number): Promise<Result<JobLog>>;
Run page: job summaries, attempts, re-run a job, debug, log search and downloads315 /** The job summaries of an attempt (the latest by default), jobs without one left out. */
316 summaries(repo: RepoPath, viewer: Viewer, id: string, attempt?: number): Promise<Result<JobSummary[]>>;
317 /** A job's whole log, any attempt's, by the id the run gave the job. */
318 jobLogText(repo: RepoPath, viewer: Viewer, job: string): Promise<Result<JobLogText>>;
319 /** Every job's whole log for an attempt, to download as one archive. */
320 runLogs(repo: RepoPath, viewer: Viewer, id: string, attempt?: number): Promise<Result<JobLogText[]>>;
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs321 dispatch(
322 actor: User,
323 repo: RepoPath,
324 workflow: string,
325 ref: string | undefined,
326 inputs: Record<string, unknown>,
327 ): Promise<Result<WorkflowRun>>;
Run page: job summaries, attempts, re-run a job, debug, log search and downloads328 /** Running jobs clean up first; `force` (or cancelling a run that is cancelling) stops them outright. */
329 cancel(actor: User, repo: RepoPath, id: string, force?: boolean): Promise<Result<WorkflowRun>>;
330 /** A new attempt: every job, the failed ones, or `job` and what needs it; `debug` for debug logging. */
331 rerun(
332 actor: User,
333 repo: RepoPath,
334 id: string,
335 failedOnly?: boolean,
336 options?: { job?: string; debug?: boolean },
337 ): Promise<Result<WorkflowRun>>;
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs338 setWorkflowEnabled(actor: User, repo: RepoPath, workflow: string, enabled: boolean): Promise<Result<Workflow>>;
Secrets and variables: one list, rows per environment, for workflows and deployments339 settings(actor: User, owner: SettingsOwner, kind: SettingKindFilter): Promise<Result<Setting[]>>;
340 /** `value` null keeps an existing entry's default value. */
341 setSetting(
342 actor: User,
343 owner: SettingsOwner,
344 kind: SettingKind,
345 name: string,
346 value: string | null,
347 options?: SettingOptions,
348 ): Promise<Result<Setting>>;
349 /** One row by `id`, or every row of the key. */
350 deleteSetting(actor: User, owner: SettingsOwner, kind: SettingKindFilter, name: string, id?: string): Promise<Result<boolean>>;
Merge branch 'worktree-agent-a3abfcce648e87dca'351 /** Lets a pull request's run from outside start. Write role. */
352 approveRun(actor: User, repo: RepoPath, id: string): Promise<Result<WorkflowRun>>;
353 pendingDeployments(repo: RepoPath, viewer: Viewer, id: string): Promise<Result<PendingDeployment[]>>;
354 /** Approves or rejects the jobs `environments` hold (every waiting one when empty). */
355 reviewDeployments(
356 actor: User,
357 repo: RepoPath,
358 id: string,
359 state: "approved" | "rejected",
360 environments?: string[],
361 comment?: string,
362 ): Promise<Result<PendingDeployment[]>>;
363 actionsSettings(repo: RepoPath, viewer: Viewer): Promise<Result<ActionsSettings>>;
364 /** Admin role. Left out is unchanged. */
365 setActionsSettings(actor: User, repo: RepoPath, change: ActionsSettingsChange): Promise<Result<ActionsSettings>>;
366 /** Members. */
367 workspaceActionsSettings(workspace: string, viewer: Viewer): Promise<Result<WorkspaceActionsSettings>>;
368 /** Owners. Left out is unchanged. */
369 setWorkspaceActionsSettings(
370 actor: User,
371 workspace: string,
372 change: Partial<WorkspaceActionsSettings>,
373 ): Promise<Result<WorkspaceActionsSettings>>;
374 /** Every environment the repository's rules, secrets, workflows or jobs name. */
375 environments(repo: RepoPath, viewer: Viewer): Promise<Result<Environment[]>>;
376 /** Admin role. */
377 setEnvironment(actor: User, repo: RepoPath, name: string, change: EnvironmentChange): Promise<Result<Environment>>;
378 deleteEnvironment(actor: User, repo: RepoPath, name: string): Promise<Result<boolean>>;
Actions: OIDC tokens, the toolkit's cache and artifact services, and artifacts in R2379 /** A repository's artifacts, newest first, or one run's. */
380 artifacts(repo: RepoPath, viewer: Viewer, filter?: { run?: string; name?: string; page?: number; per_page?: number }): Promise<Result<ArtifactList>>;
381 /** One artifact by id, or by run and name, with a token to download it for a few minutes. */
382 artifactDownload(repo: RepoPath, viewer: Viewer, by: { id?: number; run?: string; name?: string }): Promise<Result<ArtifactBlob>>;
383 /** Needs the Write role. */
384 deleteArtifact(actor: User, repo: RepoPath, id: number): Promise<Result<Artifact>>;
385 /** How long the repository keeps artifacts; with `days`, sets it (Maintain). */
386 artifactRetention(repo: RepoPath, viewer: Viewer, days?: number): Promise<Result<ArtifactRetention>>;
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs387}
Actions: OIDC tokens, the toolkit's cache and artifact services, and artifacts in R2388
389/**
390 * A workflow run's artifact, kept in R2 for its retention days. Mirrors
391 * `g1t_contracts::actions::Artifact` (which travels in `snake_case`).
392 */
393export type Artifact = {
394 id: number;
395 name: string;
396 size: number;
397 /** `sha256:<hex>`, when the uploader said. */
398 digest: string | null;
399 /** `zip`, or `tgz` for one an older runner sent. */
400 format: string;
401 run_id: string;
402 job_id: string;
403 repo_id: string;
404 expired: boolean;
405 created_at: string;
406 updated_at: string;
407 expires_at: string;
408 head_branch?: string | null;
409 head_sha?: string | null;
410};
411
412export type ArtifactList = { total_count: number; artifacts: Artifact[] };
413
414/** An artifact, where it is, and a signed token for the API's `/actions/toolkit/blobs/{blob}`. */
415export type ArtifactBlob = { artifact: Artifact; object: string; blob: string };
416
417export type ArtifactRetention = { days: number; maximum_allowed_days: number };

This file's history is long; its oldest lines are credited to the oldest commit read.