Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
1,813 linesCodeBlameRaw
1//! The actions service: GitHub Actions workflows, run on g1t as they are.
2//!
3//! A repository's `.g1t/workflows/*.yml`, in GitHub's format, are read
4//! from the commit an
5//! event is about (the default branch for issues, schedules and manual
6//! runs). Each workflow an event starts becomes a run; each job of the run
7//! (one per matrix combination) runs in a sandbox once the jobs it needs
8//! have finished. Jobs report their steps and logs back as they go, and a
9//! run on a pull request's head is a status on that pull request.
10//!
11//! Secrets and variables belong to a repository or to its workspace; a
12//! repository's override its workspace's of the same name. Secret values
13//! are sealed at rest and never returned.
14//!
15//! Mirrors `packages/contracts/src/actions.ts`.
16
17use serde::{Deserialize, Serialize};
18use serde_json::Value;
19
20use crate::repos::RepoPath;
21use crate::{User, Viewer};
22
23/// A note on something in a workflow that runs differently on g1t.
24#[derive(Clone, Debug, Serialize, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub struct WorkflowNote {
27 /// `info`, `warning` or `unsupported`.
28 pub severity: String,
29 pub job: Option<String>,
30 pub message: String,
31}
32
33#[derive(Clone, Debug, Serialize, Deserialize)]
34#[serde(rename_all = "camelCase")]
35pub struct Workflow {
36 pub id: String,
37 /// `.g1t/workflows/ci.yml`.
38 pub path: String,
39 pub name: String,
40 /// The events that start it, such as `push` and `pull_request`.
41 pub events: Vec<String>,
42 /// `active`, or `disabled` when a member turned it off.
43 pub state: String,
44 /// Why the file cannot be used, if it cannot.
45 pub error: Option<String>,
46 pub notes: Vec<WorkflowNote>,
47 /// `on.workflow_dispatch.inputs` as written, when it can be run by hand.
48 pub dispatch: Option<Value>,
49 pub last_run: Option<WorkflowRun>,
50 /// For a managed workflow (`managed/<name>.yml`): what installed it.
51 #[serde(default)]
52 pub managed_by: Option<ManagedBy>,
53}
54
55/// What installed a managed workflow in a repository.
56#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
57#[serde(rename_all = "camelCase")]
58pub struct ManagedBy {
59 /// `g1t` for one g1t's services installed (such as a project's deploy
60 /// workflow), or the workspace's name for one its owners added.
61 pub origin: String,
62 /// The workspace's: `required` or `default`. Empty for g1t's.
63 #[serde(default)]
64 pub mode: String,
65 /// The workspace's: the file it was copied from, as
66 /// `owner/repo/path@ref`.
67 #[serde(default)]
68 pub source: Option<String>,
69}
70
71#[derive(Clone, Debug, Serialize, Deserialize)]
72#[serde(rename_all = "camelCase")]
73pub struct WorkflowRun {
74 pub id: String,
75 pub workflow_id: String,
76 pub path: String,
77 /// The workflow's name.
78 pub name: String,
79 /// `run-name`, or what started it: a commit's subject, a pull request's title.
80 pub title: String,
81 /// Counts the workflow's runs: 1, 2, 3…
82 pub number: u64,
83 pub attempt: u64,
84 /// The GitHub event: `push`, `pull_request`, `schedule`…
85 pub event: String,
86 #[serde(rename = "ref")]
87 pub git_ref: String,
88 pub sha: String,
89 /// The pull request it ran for, if any.
90 pub pull: Option<u32>,
91 /// `queued`, `in_progress` or `completed`.
92 pub status: String,
93 /// When completed: `success`, `failure`, `cancelled` or `skipped`.
94 pub conclusion: Option<String>,
95 /// Why it could not start, such as a workflow file that does not read.
96 pub error: Option<String>,
97 /// Username of whoever caused it.
98 pub actor: Option<String>,
99 pub created_at: String,
100 pub started_at: Option<String>,
101 pub finished_at: Option<String>,
102}
103
104#[derive(Clone, Debug, Default, Serialize, Deserialize)]
105#[serde(rename_all = "camelCase")]
106pub struct StepState {
107 /// From 1.
108 pub number: u32,
109 pub name: String,
110 /// `queued`, `in_progress` or `completed`.
111 pub status: String,
112 /// `success`, `failure`, `cancelled` or `skipped`.
113 pub conclusion: Option<String>,
114 pub started_at: Option<String>,
115 pub finished_at: Option<String>,
116}
117
118/// A message a step left with `::error::`, `::warning::` or `::notice::`.
119#[derive(Clone, Debug, Default, Serialize, Deserialize)]
120#[serde(rename_all = "camelCase")]
121pub struct Annotation {
122 /// `error`, `warning` or `notice`.
123 pub level: String,
124 pub message: String,
125 pub title: Option<String>,
126 pub file: Option<String>,
127 pub line: Option<u32>,
128}
129
130#[derive(Clone, Debug, Serialize, Deserialize)]
131#[serde(rename_all = "camelCase")]
132pub struct Job {
133 pub id: String,
134 pub run_id: String,
135 /// Its key under `jobs:`.
136 pub key: String,
137 /// With its matrix combination: `test (ubuntu-latest, 20)`.
138 pub name: String,
139 pub needs: Vec<String>,
140 /// `queued`, `waiting` (for the jobs it needs), `in_progress` or `completed`.
141 pub status: String,
142 pub conclusion: Option<String>,
143 pub steps: Vec<StepState>,
144 pub annotations: Vec<Annotation>,
145 /// Why it did not run, what stopped it, or what it waits for.
146 pub reason: Option<String>,
147 pub started_at: Option<String>,
148 pub finished_at: Option<String>,
149 /// The environment it names, once its needs are done (an expression
150 /// read by then). A job held by the environment's protection rules is
151 /// `pending` until they let it through.
152 #[serde(default)]
153 pub environment: Option<String>,
154 /// Its `runs-on` names self-hosted runners (see `runners`).
155 #[serde(default)]
156 pub self_hosted: bool,
157 /// The self-hosted runner that took it, by name.
158 #[serde(default)]
159 pub runner: Option<String>,
160 /// It was cancelled and is running its `if: always()` and `cancelled()`
161 /// steps and its post steps before it ends.
162 #[serde(default)]
163 pub cancelling: bool,
164 /// Where its deployment is (`environment.url`), for a job that deploys
165 /// and says; the current attempt's only.
166 #[serde(default, skip_serializing_if = "Option::is_none")]
167 pub environment_url: Option<String>,
168 /// For a job that calls a reusable workflow: that workflow's file. Its
169 /// jobs' keys start with this job's key and a `/`.
170 #[serde(default, skip_serializing_if = "Option::is_none")]
171 pub uses: Option<String>,
172}
173
174#[derive(Clone, Debug, Serialize, Deserialize)]
175#[serde(rename_all = "camelCase")]
176pub struct RunDetail {
177 pub run: WorkflowRun,
178 pub jobs: Vec<Job>,
179 /// The workflow's notes, as of the run's commit.
180 pub notes: Vec<WorkflowNote>,
181 /// For a run of a pull request from outside: whether it waits for, or
182 /// had, someone's approval (`status` is `action_required` while it waits).
183 #[serde(default)]
184 pub approval: Option<RunApproval>,
185 /// The environments whose protection rules hold its jobs, this attempt.
186 #[serde(default)]
187 pub pending_deployments: Vec<PendingDeployment>,
188 /// Every attempt of the run, oldest first, the one shown included.
189 /// `run.attempt` says which one `jobs` belong to.
190 #[serde(default)]
191 pub attempts: Vec<RunAttempt>,
192}
193
194/// One attempt of a run: the first, or a re-run.
195#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
196#[serde(rename_all = "camelCase")]
197pub struct RunAttempt {
198 /// From 1.
199 pub attempt: u64,
200 /// `queued`, `in_progress` or `completed`; earlier attempts are completed.
201 pub status: String,
202 pub conclusion: Option<String>,
203 /// Who started it: whoever caused the run for the first, whoever re-ran
204 /// it for the rest.
205 pub actor: Option<String>,
206 /// It ran with debug logging (`RUNNER_DEBUG=1`).
207 pub debug: bool,
208 pub started_at: Option<String>,
209 pub finished_at: Option<String>,
210}
211
212/// One job's summary: what its steps wrote to `$GITHUB_STEP_SUMMARY`, in
213/// Markdown, masked.
214#[derive(Clone, Debug, Serialize, Deserialize)]
215#[serde(rename_all = "camelCase")]
216pub struct JobSummary {
217 /// The job's id, as `RunDetail.jobs` gives it for the attempt.
218 pub job_id: String,
219 pub name: String,
220 pub steps: Vec<StepSummary>,
221}
222
223#[derive(Clone, Debug, Serialize, Deserialize)]
224#[serde(rename_all = "camelCase")]
225pub struct StepSummary {
226 /// The step, from 1 (post steps follow the job's own).
227 pub step: u32,
228 pub markdown: String,
229}
230
231/// A job's whole log, for downloading: its steps, to split the text by.
232#[derive(Clone, Debug, Serialize, Deserialize)]
233#[serde(rename_all = "camelCase")]
234pub struct JobLogText {
235 pub job_id: String,
236 pub name: String,
237 pub steps: Vec<StepState>,
238 pub chunks: Vec<LogChunk>,
239 /// Whether the job has finished.
240 pub done: bool,
241 /// Its log was left out: the run's logs reached `MAX_RUN_LOG_BYTES`.
242 #[serde(default)]
243 pub omitted: bool,
244}
245
246/// A run that needed approval before it started.
247#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
248#[serde(rename_all = "camelCase")]
249pub struct RunApproval {
250 /// `required` while it waits, then `approved`.
251 pub state: String,
252 /// Why it waits, in words.
253 pub reason: String,
254 /// Who approved it.
255 pub approved_by: Option<String>,
256}
257
258/// One person or team who may approve a job's deployment to an
259/// environment.
260#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
261pub struct EnvironmentReviewer {
262 /// `user` or `team`.
263 #[serde(rename = "type")]
264 pub kind: String,
265 /// A username, or a team's slug in the repository's workspace.
266 pub name: String,
267}
268
269/// A branch or tag pattern an environment lets deploy.
270#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
271pub struct BranchPattern {
272 /// fnmatch-style, as branch filters are: `main`, `release/*`, `v*`.
273 pub name: String,
274 /// `branch` or `tag`.
275 #[serde(rename = "type", default = "branch_kind")]
276 pub kind: String,
277}
278
279fn branch_kind() -> String {
280 "branch".to_owned()
281}
282
283/// The most reviewers an environment may have, as on GitHub.
284pub const MAX_ENVIRONMENT_REVIEWERS: usize = 6;
285/// The longest wait timer, in minutes: 30 days.
286pub const MAX_WAIT_MINUTES: u32 = 43_200;
287
288/// An environment and its protection rules. Jobs that name it with
289/// `environment:` wait until the rules let them through; only then does the
290/// job get the environment's secrets.
291#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
292#[serde(rename_all = "camelCase")]
293pub struct Environment {
294 /// Lowercase.
295 pub name: String,
296 /// Who may approve its jobs; none means no review is needed.
297 pub reviewers: Vec<EnvironmentReviewer>,
298 /// Whoever started a run may not approve its jobs, even as a reviewer.
299 pub prevent_self_review: bool,
300 /// Minutes each job waits before it may start.
301 pub wait_minutes: u32,
302 /// Which refs may deploy: `all`, `protected` (branches the rules
303 /// protect, the default branch included) or `selected` (`branch_patterns`).
304 pub branch_policy: String,
305 pub branch_patterns: Vec<BranchPattern>,
306 /// Admins may approve without being reviewers, which also skips the wait.
307 pub admins_bypass: bool,
308 /// Whether it has rules saved; false for one only named by a workflow,
309 /// a secret or a deployment.
310 pub protected: bool,
311 pub updated_at: Option<String>,
312 pub updated_by: Option<String>,
313}
314
315/// An environment holding a run's jobs, and where its rules stand.
316#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
317#[serde(rename_all = "camelCase")]
318pub struct PendingDeployment {
319 pub environment: String,
320 /// `waiting`, `approved` or `rejected`.
321 pub state: String,
322 /// Whether a reviewer must approve it before its jobs start.
323 pub needs_review: bool,
324 /// When its wait timer lets its jobs start, if it has one.
325 pub wait_until: Option<String>,
326 pub reviewers: Vec<EnvironmentReviewer>,
327 /// The jobs it holds, by name.
328 pub jobs: Vec<String>,
329 /// Whether the viewer may approve or reject it now.
330 #[serde(default)]
331 pub can_review: bool,
332 pub reviewed_by: Option<String>,
333 pub comment: Option<String>,
334 pub reviewed_at: Option<String>,
335}
336
337/// A repository's choices for its workflows.
338#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
339#[serde(rename_all = "camelCase")]
340pub struct ActionsSettings {
341 /// What a workflow without `permissions:` gets: `read` (contents and
342 /// packages read) or `write` (every permission). Unchosen, a repository
343 /// made before restricted tokens keeps `write`; a newer one takes its
344 /// workspace's default. Never more than the workspace's maximum.
345 pub default_permissions: String,
346 /// Whether the repository chose it, rather than taking it as above.
347 #[serde(default)]
348 pub default_chosen: bool,
349 /// The most the workspace lets a repository's default be.
350 #[serde(default = "write")]
351 pub max_permissions: String,
352 /// Which pull requests' runs wait for approval: `first_time_contributors`,
353 /// `outside_contributors` (the default) or `all_external_contributors`.
354 pub approval_policy: String,
355 /// Whether a job's token may open pull requests and approve them. Off
356 /// unless the repository turns it on, and only where the workspace
357 /// allows it.
358 #[serde(default)]
359 pub can_approve_pull_requests: bool,
360 /// Whether the workspace lets its repositories turn that on.
361 #[serde(default)]
362 pub workspace_allows_pull_requests: bool,
363 /// Who may use this repository's actions and reusable workflows from
364 /// their workflows, when it is private: `none` (only itself, the
365 /// default) or `organization` (private repositories of its workspace).
366 /// A public repository's are anyone's. See [`ACCESS_LEVELS`].
367 #[serde(default = "no_access")]
368 pub access_level: String,
369}
370
371fn no_access() -> String {
372 "none".to_owned()
373}
374
375/// The values of `access_level`. `user` is read as `organization`: a
376/// personal account's repositories are its own workspace's.
377pub const ACCESS_LEVELS: [&str; 2] = ["none", "organization"];
378
379/// `access_level` as given, as one of [`ACCESS_LEVELS`]; None when it is
380/// not one.
381pub fn access_level(given: &str) -> Option<&'static str> {
382 match given.trim().to_ascii_lowercase().as_str() {
383 "none" | "" => Some("none"),
384 "organization" | "user" | "workspace" => Some("organization"),
385 _ => None,
386 }
387}
388
389fn write() -> String {
390 "write".to_owned()
391}
392
393/// A workspace's policy for its repositories' tokens.
394#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
395#[serde(rename_all = "camelCase")]
396pub struct WorkspaceActionsSettings {
397 /// What a repository made from now on gets by default: `read` (the
398 /// default) or `write`.
399 pub default_permissions: String,
400 /// The most any repository's default may be: `write` (the default) or
401 /// `read`, which holds every repository to read-only.
402 pub max_permissions: String,
403 /// Whether its repositories may let jobs open and approve pull
404 /// requests. Off by default.
405 pub can_approve_pull_requests: bool,
406}
407
408/// `workspace_actions_settings`: members only. Returns
409/// `Outcome<WorkspaceActionsSettings>`.
410#[derive(Debug, Serialize, Deserialize)]
411pub struct WorkspaceActionsSettingsArgs {
412 pub viewer: Viewer,
413 pub workspace: String,
414}
415
416/// `set_workspace_actions_settings`: owners only. Fields left out stay as
417/// they are. Returns `Outcome<WorkspaceActionsSettings>`.
418#[derive(Debug, Serialize, Deserialize)]
419#[serde(rename_all = "camelCase")]
420pub struct SetWorkspaceActionsSettingsArgs {
421 pub actor: User,
422 pub workspace: String,
423 #[serde(default)]
424 pub default_permissions: Option<String>,
425 #[serde(default)]
426 pub max_permissions: Option<String>,
427 #[serde(default)]
428 pub can_approve_pull_requests: Option<bool>,
429}
430
431/// The approval policies, least strict first.
432pub const APPROVAL_POLICIES: [&str; 3] = ["first_time_contributors", "outside_contributors", "all_external_contributors"];
433
434/// `actions_settings`. Returns `Outcome<ActionsSettings>`; anyone who can
435/// read the repository may see them.
436#[derive(Debug, Serialize, Deserialize)]
437pub struct ActionsSettingsArgs {
438 pub viewer: Viewer,
439 pub repo: RepoPath,
440}
441
442/// `set_actions_settings`: Admins only. Fields left out stay as they are.
443/// Returns `Outcome<ActionsSettings>`.
444#[derive(Debug, Serialize, Deserialize)]
445#[serde(rename_all = "camelCase")]
446pub struct SetActionsSettingsArgs {
447 pub actor: User,
448 pub repo: RepoPath,
449 /// `read` or `write`; `inherit` goes back to the workspace's (or, for a
450 /// repository made before restricted tokens, `write`).
451 #[serde(default)]
452 pub default_permissions: Option<String>,
453 #[serde(default)]
454 pub approval_policy: Option<String>,
455 #[serde(default)]
456 pub can_approve_pull_requests: Option<bool>,
457 /// `none`, or `organization` (`user` reads the same). See
458 /// [`ActionsSettings::access_level`].
459 #[serde(default)]
460 pub access_level: Option<String>,
461}
462
463/// `environments`: every environment a repository's workflows, secrets,
464/// deployments or rules name, with its rules. `environment`: one, by
465/// `name`. Returns `Outcome<Vec<Environment>>` and `Outcome<Environment>`.
466#[derive(Debug, Serialize, Deserialize)]
467pub struct EnvironmentsArgs {
468 pub viewer: Viewer,
469 pub repo: RepoPath,
470 #[serde(default)]
471 pub name: Option<String>,
472}
473
474/// `set_environment`: create an environment's rules or change them. Fields
475/// left out stay as they are (none, for a new one). Admins only. Returns
476/// `Outcome<Environment>`.
477#[derive(Debug, Serialize, Deserialize)]
478#[serde(rename_all = "camelCase")]
479pub struct SetEnvironmentArgs {
480 pub actor: User,
481 pub repo: RepoPath,
482 pub name: String,
483 #[serde(default)]
484 pub reviewers: Option<Vec<EnvironmentReviewer>>,
485 #[serde(default)]
486 pub prevent_self_review: Option<bool>,
487 #[serde(default)]
488 pub wait_minutes: Option<u32>,
489 #[serde(default)]
490 pub branch_policy: Option<String>,
491 #[serde(default)]
492 pub branch_patterns: Option<Vec<BranchPattern>>,
493 #[serde(default)]
494 pub admins_bypass: Option<bool>,
495}
496
497/// `delete_environment`: its rules go; jobs naming it run without them.
498/// Its secrets' rows stay. Admins only. Returns `Outcome<bool>`.
499#[derive(Debug, Serialize, Deserialize)]
500pub struct DeleteEnvironmentArgs {
501 pub actor: User,
502 pub repo: RepoPath,
503 pub name: String,
504}
505
506/// `pending_deployments`: the environments holding a run's jobs. Returns
507/// `Outcome<Vec<PendingDeployment>>`.
508#[derive(Debug, Serialize, Deserialize)]
509pub struct PendingDeploymentsArgs {
510 pub viewer: Viewer,
511 pub repo: RepoPath,
512 pub id: String,
513}
514
515/// `review_deployments`: approve or reject a run's jobs for `environments`
516/// (every one waiting, if empty). Returns `Outcome<Vec<PendingDeployment>>`.
517#[derive(Debug, Serialize, Deserialize)]
518pub struct ReviewDeploymentsArgs {
519 pub actor: User,
520 pub repo: RepoPath,
521 pub id: String,
522 #[serde(default)]
523 pub environments: Vec<String>,
524 /// `approved` or `rejected`.
525 pub state: String,
526 #[serde(default)]
527 pub comment: Option<String>,
528}
529
530/// `repository_dispatch`: start the default branch's workflows that run
531/// `on: repository_dispatch` for `event_type`. Needs the Write role (a
532/// token's `code:write`). Returns `Outcome<u32>`: how many started.
533#[derive(Debug, Serialize, Deserialize)]
534#[serde(rename_all = "camelCase")]
535pub struct RepositoryDispatchArgs {
536 pub actor: User,
537 pub repo: RepoPath,
538 pub event_type: String,
539 #[serde(default)]
540 pub client_payload: Value,
541}
542
543#[derive(Clone, Debug, Serialize, Deserialize)]
544#[serde(rename_all = "camelCase")]
545pub struct LogChunk {
546 pub seq: u64,
547 /// The step it belongs to, from 1; 0 for the job's setup.
548 pub step: u32,
549 pub text: String,
550}
551
552#[derive(Clone, Debug, Serialize, Deserialize)]
553#[serde(rename_all = "camelCase")]
554pub struct JobLog {
555 pub chunks: Vec<LogChunk>,
556 /// Whether the job has finished, so no more will come.
557 pub done: bool,
558}
559
560/// Who may read a secret or variable: workflows (`secrets.*` and `vars.*`
561/// in GitHub Actions) and deployments (a deploy build's environment and the
562/// running app's bindings). Agents, checks and the merge queue read none.
563pub const CONSUMERS: [&str; 2] = ["workflows", "deployments"];
564
565/// One row of a repository's or workspace's secrets and variables, as
566/// Vercel lists environment variables: a key, its type, the environments
567/// it applies to and who reads it. A key may have one row per environment.
568/// Secrets' values are never returned.
569#[derive(Clone, Debug, Serialize, Deserialize)]
570#[serde(rename_all = "camelCase")]
571pub struct Setting {
572 #[serde(default)]
573 pub id: String,
574 pub name: String,
575 /// `secret`, or `variable` (shown as Config).
576 #[serde(default)]
577 pub kind: String,
578 /// A variable's value; secrets' are never returned.
579 pub value: Option<String>,
580 /// `project` (a repository's, which belong to its project) or
581 /// `workspace`.
582 pub scope: String,
583 pub updated_at: String,
584 /// `workflows` and/or `deployments`.
585 #[serde(default)]
586 pub available_to: Vec<String>,
587 /// The environments it applies to; empty is every environment.
588 #[serde(default)]
589 pub environments: Vec<String>,
590 /// A workspace's row: the projects it reaches, by slug; empty is every
591 /// project.
592 #[serde(default)]
593 pub projects: Vec<String>,
594 #[serde(default)]
595 pub note: Option<String>,
596 #[serde(default)]
597 pub updated_by: Option<String>,
598 /// A brokered secret's hosts: a job gets a stand-in for it, and g1t
599 /// puts the real value on the job's requests to these hosts as they
600 /// leave its sandbox. Empty for a secret that is not brokered, and for
601 /// config.
602 #[serde(default)]
603 pub brokered_hosts: Vec<String>,
604}
605
606/// How a brokered secret's stand-in starts. The rest is 48 random hex
607/// characters, so the whole is shaped like a token and tools take it.
608pub const STAND_IN_PREFIX: &str = "g1tsec_";
609
610/// A stand-in a running job was given for a brokered secret, as the runner
611/// Worker asks for them (`brokered_secrets`) to fill in the real value on
612/// the job's requests to `hosts`.
613#[derive(Clone, Debug, Serialize, Deserialize)]
614#[serde(rename_all = "camelCase")]
615pub struct BrokeredSecret {
616 pub stand_in: String,
617 /// The secret's key, for the job's log.
618 pub name: String,
619 pub value: String,
620 pub hosts: Vec<String>,
621}
622
623// --- Methods ---------------------------------------------------------------
624
625/// `workflows`. Returns `Outcome<Vec<Workflow>>`.
626#[derive(Debug, Serialize, Deserialize)]
627pub struct WorkflowsArgs {
628 pub repo: RepoPath,
629 pub viewer: Viewer,
630}
631
632/// `workflow`: one workflow, named by its id (`wfl_…`), its file name
633/// (`ci.yml`), its path or its name, with its file as of `ref` (the
634/// default branch when absent). Returns `Outcome<WorkflowDetail>`.
635#[derive(Debug, Serialize, Deserialize)]
636pub struct WorkflowArgs {
637 pub repo: RepoPath,
638 pub viewer: Viewer,
639 pub workflow: String,
640 #[serde(default, rename = "ref")]
641 pub git_ref: Option<String>,
642}
643
644/// A workflow with its file.
645#[derive(Clone, Debug, Serialize, Deserialize)]
646#[serde(rename_all = "camelCase")]
647pub struct WorkflowDetail {
648 #[serde(flatten)]
649 pub workflow: Workflow,
650 /// The branch or tag the file was read from.
651 #[serde(rename = "ref")]
652 pub git_ref: String,
653 /// The file, as written on `ref`.
654 pub source: String,
655}
656
657/// `runs`: newest first. Returns `Outcome<Vec<WorkflowRun>>`.
658#[derive(Debug, Serialize, Deserialize)]
659pub struct RunsArgs {
660 pub repo: RepoPath,
661 pub viewer: Viewer,
662 /// A workflow's id or file name.
663 #[serde(default)]
664 pub workflow: Option<String>,
665 #[serde(default)]
666 pub branch: Option<String>,
667 #[serde(default)]
668 pub event: Option<String>,
669 /// The pull request's number.
670 #[serde(default)]
671 pub pull: Option<u32>,
672 #[serde(default)]
673 pub sha: Option<String>,
674 /// GitHub's `status` filter: a status (`queued`, `in_progress`,
675 /// `waiting`, `completed`) or a conclusion (`success`, `failure`,
676 /// `cancelled`, `skipped`, `timed_out`, `neutral`, `action_required`).
677 #[serde(default)]
678 pub status: Option<String>,
679 #[serde(default)]
680 pub limit: Option<u32>,
681}
682
683/// `run`. Returns `Outcome<RunDetail>`.
684#[derive(Debug, Serialize, Deserialize)]
685pub struct RunArgs {
686 pub repo: RepoPath,
687 pub viewer: Viewer,
688 pub id: String,
689 /// An earlier attempt; the latest when absent.
690 #[serde(default)]
691 pub attempt: Option<u64>,
692}
693
694/// `summaries`: the job summaries of a run's attempt (the latest when
695/// `attempt` is absent), jobs in the run's order, those with none left
696/// out. Returns `Outcome<Vec<JobSummary>>`.
697#[derive(Debug, Serialize, Deserialize)]
698pub struct SummariesArgs {
699 pub repo: RepoPath,
700 pub viewer: Viewer,
701 pub id: String,
702 #[serde(default)]
703 pub attempt: Option<u64>,
704}
705
706/// `job_log_text`: one job's whole log, any attempt's (by the id the run
707/// gave the job). Returns `Outcome<JobLogText>`.
708#[derive(Debug, Serialize, Deserialize)]
709pub struct JobLogTextArgs {
710 pub repo: RepoPath,
711 pub viewer: Viewer,
712 pub job: String,
713}
714
715/// `run_logs`: every job's whole log for an attempt of a run (the latest
716/// when `attempt` is absent), until they add up to `MAX_RUN_LOG_BYTES`;
717/// jobs past it come `omitted`, with no chunks. Returns
718/// `Outcome<Vec<JobLogText>>`.
719#[derive(Debug, Serialize, Deserialize)]
720pub struct RunLogsArgs {
721 pub repo: RepoPath,
722 pub viewer: Viewer,
723 pub id: String,
724 #[serde(default)]
725 pub attempt: Option<u64>,
726}
727
728/// The most log `run_logs` returns at once, in bytes.
729pub const MAX_RUN_LOG_BYTES: usize = 24 * 1024 * 1024;
730
731/// `logs`: a job's log after `after`, or with `tail` its last chunks.
732/// Returns `Outcome<JobLog>`.
733#[derive(Debug, Serialize, Deserialize)]
734pub struct LogsArgs {
735 pub repo: RepoPath,
736 pub viewer: Viewer,
737 pub job: String,
738 #[serde(default)]
739 pub after: u64,
740 /// The last this many chunks (at most [`MAX_LOG_PAGE`]) instead: where
741 /// a failed job says why. `after` is ignored with it.
742 #[serde(default, skip_serializing_if = "Option::is_none")]
743 pub tail: Option<u32>,
744}
745
746/// The most chunks of a log one `logs` call returns.
747pub const MAX_LOG_PAGE: u32 = 500;
748
749/// `dispatch`: run a workflow that has `workflow_dispatch`. Members only.
750/// Returns `Outcome<WorkflowRun>`.
751#[derive(Debug, Serialize, Deserialize)]
752pub struct DispatchArgs {
753 pub actor: User,
754 pub repo: RepoPath,
755 /// A workflow's id or file name.
756 pub workflow: String,
757 /// A branch or tag; the default branch when absent.
758 #[serde(default, rename = "ref")]
759 pub git_ref: Option<String>,
760 #[serde(default)]
761 pub inputs: serde_json::Map<String, Value>,
762}
763
764/// `cancel` and `rerun`: every job, with `failed_only` the ones that did
765/// not succeed, or with `job` that one job (by its id in the run's latest
766/// attempt); each with the jobs that need them. `debug` runs the new
767/// attempt with debug logging. Members only. Returns `Outcome<WorkflowRun>`.
768#[derive(Debug, Serialize, Deserialize)]
769pub struct RunActionArgs {
770 pub actor: User,
771 pub repo: RepoPath,
772 pub id: String,
773 #[serde(default)]
774 pub failed_only: bool,
775 #[serde(default)]
776 pub job: Option<String>,
777 #[serde(default)]
778 pub debug: bool,
779 /// `cancel`: stop running jobs outright, without their cleanup steps.
780 #[serde(default)]
781 pub force: bool,
782}
783
784/// `set_workflow_enabled`. Members only. Returns `Outcome<Workflow>`.
785#[derive(Debug, Serialize, Deserialize)]
786pub struct SetWorkflowEnabledArgs {
787 pub actor: User,
788 pub repo: RepoPath,
789 pub workflow: String,
790 pub enabled: bool,
791}
792
793/// Whose secrets or variables: a repository's, or with only `workspace`,
794/// a workspace's.
795#[derive(Clone, Debug, Serialize, Deserialize)]
796pub struct SettingsOwner {
797 #[serde(default)]
798 pub repo: Option<RepoPath>,
799 #[serde(default)]
800 pub workspace: Option<String>,
801}
802
803/// `settings`: the secrets (`kind: secret`) or variables (`kind: variable`)
804/// of a repository, with its workspace's, or of a workspace. Members only.
805/// Returns `Outcome<Vec<Setting>>`.
806#[derive(Debug, Serialize, Deserialize)]
807pub struct SettingsArgs {
808 pub actor: User,
809 #[serde(flatten)]
810 pub owner: SettingsOwner,
811 pub kind: String,
812}
813
814/// `set_setting`: add or replace one. A repository's need a member; a
815/// workspace's an owner. Returns `Outcome<Setting>`.
816#[derive(Debug, Serialize, Deserialize)]
817pub struct SetSettingArgs {
818 pub actor: User,
819 #[serde(flatten)]
820 pub owner: SettingsOwner,
821 /// `secret` or `variable`. Changing a variable's row to `secret` seals
822 /// it; a secret cannot become a variable.
823 pub kind: String,
824 pub name: String,
825 /// The row to change. Left out, the key's row for every environment, as
826 /// GitHub's API addresses a secret by name alone.
827 #[serde(default)]
828 pub id: Option<String>,
829 /// Needed for a new row; left out, an existing row keeps its value.
830 #[serde(default)]
831 pub value: Option<String>,
832 /// `workflows` and/or `deployments`; left out, unchanged (both, for a
833 /// new row).
834 // Named as callers send it: an `alias` is not honoured beside the
835 // flattened owner in the Worker's build.
836 #[serde(default, rename = "availableTo")]
837 pub available_to: Option<Vec<String>>,
838 /// The environments it applies to; empty is every one. Left out,
839 /// unchanged.
840 #[serde(default)]
841 pub environments: Option<Vec<String>>,
842 /// A workspace's row: project slugs; empty for every one.
843 #[serde(default)]
844 pub projects: Option<Vec<String>>,
845 #[serde(default)]
846 pub note: Option<String>,
847 /// A secret's brokered hosts (`Setting::brokered_hosts`); empty stops
848 /// brokering it. Left out, unchanged.
849 #[serde(default, rename = "brokeredHosts")]
850 pub brokered_hosts: Option<Vec<String>>,
851}
852
853/// `set_managed_workflow`: installs, or replaces, a managed workflow in a
854/// repository (`g1t_actions::managed`): one that runs as if it were in
855/// `.g1t/workflows/` without being committed there, under the path
856/// `managed/<name>.yml`. For g1t's own services; never reached from the API.
857/// Refused when `source` is not a workflow g1t can read. Returns `bool`.
858#[derive(Debug, Serialize, Deserialize)]
859#[serde(rename_all = "camelCase")]
860pub struct SetManagedWorkflowArgs {
861 pub repo_id: String,
862 /// Letters, digits and hyphens: the file name its path ends with.
863 pub name: String,
864 pub source: String,
865 /// What keeps it: `deployments`, or a workspace's id.
866 pub origin: String,
867}
868
869/// `set_managed_deploy`: installs, replaces or removes the deploy workflow
870/// a project's deployments run through (`g1t_actions::managed`), named
871/// `deploy-<project>`, from the project's settings. Nothing deploys (both
872/// `previews` and `production` off) removes it. For the deployments
873/// service only. Returns `bool`, whether one is installed now.
874#[derive(Debug, Serialize, Deserialize)]
875#[serde(rename_all = "camelCase")]
876pub struct SetManagedDeployArgs {
877 pub repo_id: String,
878 pub project: String,
879 pub production_branch: String,
880 #[serde(default)]
881 pub root_dir: String,
882 #[serde(default)]
883 pub build_command: String,
884 #[serde(default)]
885 pub output_dir: String,
886 pub previews: bool,
887 pub production: bool,
888}
889
890/// A workflow a workspace's owners added to its repositories
891/// (`g1t_actions::managed::Target`): it runs in each repository it targets
892/// as that repository's own, with its token and secrets, under the path
893/// `managed/<name>.yml`, from a copy of its source taken when it was saved.
894#[derive(Clone, Debug, Serialize, Deserialize)]
895#[serde(rename_all = "camelCase")]
896pub struct WorkspaceManagedWorkflow {
897 /// Lowercase letters, digits and hyphens: its path is
898 /// `managed/<name>.yml`.
899 pub name: String,
900 pub path: String,
901 /// Its `name:`, as repositories list it; a repository's workflow of
902 /// this name takes a default one's place.
903 pub workflow_name: String,
904 /// Where it was copied from: `owner/repo/path@ref`, a repository of the
905 /// same workspace.
906 pub source: String,
907 /// The commit it was copied at.
908 pub source_sha: Option<String>,
909 /// Whether the source repository is private, so the workflow runs in
910 /// private repositories only.
911 pub source_private: bool,
912 /// `required` or `default`.
913 pub mode: String,
914 /// Names and patterns of the repositories it runs in; empty is every one.
915 pub repositories: Vec<String>,
916 /// `all`, `public` or `private`.
917 pub visibility: String,
918 /// The copy that runs.
919 pub content: String,
920 pub created_at: String,
921 pub updated_at: String,
922 pub updated_by: String,
923}
924
925/// `workspace_managed_workflows`: owners only. Returns
926/// `Outcome<Vec<WorkspaceManagedWorkflow>>`.
927#[derive(Debug, Serialize, Deserialize)]
928pub struct WorkspaceManagedWorkflowsArgs {
929 pub viewer: Viewer,
930 pub workspace: String,
931}
932
933/// `set_workspace_managed_workflow`: owners only. Adds one (`create`, which
934/// needs `source` and `mode`) or changes one; fields left out stay as they
935/// are. The source is copied again when it is given or `refresh` is set.
936/// Refused when the source is not a workflow file in a repository of the
937/// workspace, or is private while the workflow could run in a public
938/// repository. Returns `Outcome<WorkspaceManagedWorkflow>`.
939#[derive(Debug, Serialize, Deserialize)]
940#[serde(rename_all = "camelCase")]
941pub struct SetWorkspaceManagedWorkflowArgs {
942 pub actor: User,
943 pub workspace: String,
944 pub name: String,
945 #[serde(default)]
946 pub create: bool,
947 /// `owner/repo/.g1t/workflows/file.yml@ref`.
948 #[serde(default)]
949 pub source: Option<String>,
950 #[serde(default)]
951 pub mode: Option<String>,
952 #[serde(default)]
953 pub repositories: Option<Vec<String>>,
954 #[serde(default)]
955 pub visibility: Option<String>,
956 #[serde(default)]
957 pub refresh: bool,
958}
959
960/// `remove_workspace_managed_workflow`: owners only. Its runs stay.
961/// Returns `Outcome<bool>`, whether there was one.
962#[derive(Debug, Serialize, Deserialize)]
963pub struct RemoveWorkspaceManagedWorkflowArgs {
964 pub actor: User,
965 pub workspace: String,
966 pub name: String,
967}
968
969/// `remove_managed_workflow`: takes a managed workflow out of a repository.
970/// Its runs stay. Returns `bool`, whether there was one.
971#[derive(Debug, Serialize, Deserialize)]
972#[serde(rename_all = "camelCase")]
973pub struct RemoveManagedWorkflowArgs {
974 pub repo_id: String,
975 pub name: String,
976}
977
978/// `resolve_settings`: the secrets and variables one reader gets, for the
979/// services that hand them out (the deployments service). Returns
980/// `ResolvedSettings`.
981#[derive(Debug, Serialize, Deserialize)]
982#[serde(rename_all = "camelCase")]
983pub struct ResolveSettingsArgs {
984 pub repo_id: String,
985 pub repo: RepoPath,
986 /// The project being read for; its repository's primary project if left
987 /// out.
988 #[serde(default)]
989 pub project_id: Option<String>,
990 #[serde(default)]
991 pub project_slug: Option<String>,
992 /// `workflows` or `deployments`.
993 pub consumer: String,
994 /// The environment being read for, such as `production` or `preview`.
995 #[serde(default)]
996 pub environment: Option<String>,
997 /// Whether the run is trusted; an untrusted one gets no secrets.
998 pub trusted: bool,
999}
1000
1001#[derive(Debug, Default, Serialize, Deserialize)]
1002pub struct ResolvedSettings {
1003 pub secrets: serde_json::Map<String, serde_json::Value>,
1004 pub variables: serde_json::Map<String, serde_json::Value>,
1005}
1006
1007/// `delete_setting`. Returns `Outcome<bool>`.
1008#[derive(Debug, Serialize, Deserialize)]
1009pub struct DeleteSettingArgs {
1010 pub actor: User,
1011 #[serde(flatten)]
1012 pub owner: SettingsOwner,
1013 pub kind: String,
1014 pub name: String,
1015 /// One row; left out, every row of the key.
1016 #[serde(default)]
1017 pub id: Option<String>,
1018}
1019
1020/// `job_spec` and `job_report`: the sandbox running a job, with the job's
1021/// own token. `report` is one of:
1022/// `{"kind": "step", "number", "status", "conclusion"}`,
1023/// `{"kind": "log", "step", "text"}`,
1024/// `{"kind": "annotation", "level", "message", "title", "file", "line"}`,
1025/// `{"kind": "done", "conclusion", "outputs", "reason"}`.
1026#[derive(Debug, Serialize, Deserialize)]
1027pub struct JobCallArgs {
1028 pub job: String,
1029 pub token: String,
1030 #[serde(default)]
1031 pub report: Value,
1032 /// `job_spec` only: the harness takes a new token with the spec, and
1033 /// the one it asked with stops working, so a copy of it left on the
1034 /// runner's computer cannot fetch the job's secrets again. Harnesses
1035 /// that predate it never ask, and keep their token.
1036 #[serde(default)]
1037 pub rotate: bool,
1038 /// `job_spec` only: the harness on a self-hosted runner can pass the
1039 /// job's requests to a brokered secret's hosts through g1t
1040 /// (`POST /actions/jobs/{job}/broker`), so its spec lists each
1041 /// stand-in's hosts, never a value. Harnesses that predate it never
1042 /// ask, and their job's log says the stand-ins will not be filled in.
1043 #[serde(default)]
1044 pub broker: bool,
1045}
1046
1047/// What the runner needs to start a job's sandbox.
1048#[derive(Debug, Serialize, Deserialize)]
1049#[serde(rename_all = "camelCase")]
1050pub struct StartJobArgs {
1051 pub job: String,
1052 pub token: String,
1053 pub repo: RepoPath,
1054 /// Minutes before the job is stopped.
1055 pub timeout_minutes: u32,
1056 /// The machine its `runs-on` asked for, by label (`instance_for`):
1057 /// `g1t-2core` or `g1t-4core`; absent, the standard one.
1058 #[serde(default)]
1059 pub instance: Option<String>,
1060 /// Whether the job may be given brokered secrets, so the runner sends
1061 /// its HTTP and HTTPS through the Worker, which fills them in.
1062 #[serde(default)]
1063 pub brokered: bool,
1064}
1065
1066// ── The machine catalogue ─────────────────────────────────────────────────
1067//
1068// `INSTANCE_TYPES` is the one table of g1t's hosted machines: each row is a
1069// `runs-on` label, the machine it bills as, the runner's Container class
1070// that runs it, the Cloudflare Containers instance type behind that class,
1071// its size, and its price a minute. Its TypeScript mirror is
1072// packages/contracts/src/instances.ts, and services/runner/wrangler.jsonc
1073// gives each class its instance type; tests hold the three together.
1074// Adding a size, renaming a label or pointing a label at another instance
1075// type is a row here and in the mirror, and a class in wrangler.jsonc
1076// (CONTRIBUTING.md, "Adding a machine size").
1077
1078/// A label a workflow job can ask for in `runs-on`, and the machine g1t
1079/// runs it on. Each machine is a named Cloudflare Containers instance type
1080/// (no custom types): the standard machine is standard-3 (2 vCPU, 8 GiB,
1081/// 16 GB of disk), `g1t-2core` is kept as a name of it so workflows that
1082/// ask for it keep working, and `g1t-4core` is standard-4 (4 vCPU, 12 GiB,
1083/// 20 GB).
1084#[derive(Clone, Copy, Debug, PartialEq)]
1085pub struct InstanceType {
1086 /// The `runs-on` label, or `standard` for the default.
1087 pub label: &'static str,
1088 /// The machine, as it is billed and reported: runner minutes are
1089 /// counted by machine (`2-core`), so a label renamed or pointed at
1090 /// another machine leaves the history where it was. Never reused for a
1091 /// different machine.
1092 pub machine: &'static str,
1093 /// The runner's Durable Object class that runs it, one per label (a
1094 /// class has one instance type and its own `max_instances`).
1095 pub class: &'static str,
1096 /// The named Containers instance type its class runs on.
1097 pub container: &'static str,
1098 pub vcpu: f64,
1099 pub memory_gib: f64,
1100 pub disk_gb: f64,
1101 /// What a minute of it is charged, in millionths of a dollar: a job is
1102 /// charged its minutes, rounded up, at this rate (`runner_minutes`).
1103 /// The machine's cost a minute at Cloudflare's list prices with half
1104 /// its vCPUs busy, plus the 20% margin, rounded up to a tenth of a cent,
1105 /// and never under its cost with every vCPU busy (Cloudflare bills
1106 /// memory, disk and the Durable Object for every second, CPU as used).
1107 pub micros_per_minute: i64,
1108}
1109
1110impl InstanceType {
1111 /// Its price as a multiple of the standard machine's.
1112 pub fn price_scale(&self) -> f64 {
1113 self.micros_per_minute as f64 / STANDARD_INSTANCE.micros_per_minute as f64
1114 }
1115
1116 /// `2 vCPU, 8 GiB, 16 GB`.
1117 pub fn size(&self) -> String {
1118 format!("{} vCPU, {} GiB, {} GB", self.vcpu, self.memory_gib, self.disk_gb)
1119 }
1120}
1121
1122/// The default: what `ubuntu-latest` and every other hosted label get.
1123pub const STANDARD_INSTANCE: InstanceType = InstanceType {
1124 label: "standard",
1125 machine: "2-core",
1126 class: "AttemptSandbox",
1127 container: "standard-3",
1128 vcpu: 2.0,
1129 memory_gib: 8.0,
1130 disk_gb: 16.0,
1131 micros_per_minute: 4_000,
1132};
1133
1134/// Every label a workflow job can ask for, the default first.
1135pub const INSTANCE_TYPES: [InstanceType; 3] = [
1136 STANDARD_INSTANCE,
1137 // The standard machine under the name it had when it was larger.
1138 InstanceType { label: "g1t-2core", class: "Sandbox2Core", ..STANDARD_INSTANCE },
1139 InstanceType {
1140 label: "g1t-4core",
1141 machine: "4-core",
1142 class: "Sandbox4Core",
1143 container: "standard-4",
1144 vcpu: 4.0,
1145 memory_gib: 12.0,
1146 disk_gb: 20.0,
1147 micros_per_minute: 7_000,
1148 },
1149];
1150
1151/// The machines, once each, in the catalogue's order: the first row of
1152/// each.
1153pub fn machines() -> Vec<InstanceType> {
1154 let mut seen: Vec<InstanceType> = Vec::new();
1155 for instance in INSTANCE_TYPES {
1156 if !seen.iter().any(|m| m.machine == instance.machine) {
1157 seen.push(instance);
1158 }
1159 }
1160 seen
1161}
1162
1163/// A machine by its key (`2-core`), if it is one.
1164pub fn machine_named(machine: &str) -> Option<InstanceType> {
1165 INSTANCE_TYPES.iter().find(|instance| instance.machine == machine).copied()
1166}
1167
1168/// The minutes a job on g1t's machines is charged for: its time rounded up
1169/// to the whole minute, so 61 seconds is 2 minutes and any job that ran is
1170/// at least 1. Nothing for a job that never ran.
1171pub fn runner_minutes(seconds: i64) -> i64 {
1172 if seconds <= 0 { 0 } else { (seconds + 59) / 60 }
1173}
1174
1175/// The machine a job's `runs-on` labels ask for: the dearest named (the
1176/// later row when two cost the same), or the standard one. Labels compare
1177/// without regard to case.
1178pub fn instance_for(labels: &[String]) -> InstanceType {
1179 INSTANCE_TYPES
1180 .iter()
1181 .filter(|instance| instance.label != STANDARD_INSTANCE.label && labels.iter().any(|label| label.trim().eq_ignore_ascii_case(instance.label)))
1182 .max_by_key(|instance| instance.micros_per_minute)
1183 .copied()
1184 .unwrap_or(STANDARD_INSTANCE)
1185}
1186
1187/// An instance type by its label, if it is one.
1188pub fn instance_named(label: &str) -> Option<InstanceType> {
1189 INSTANCE_TYPES.iter().find(|instance| instance.label.eq_ignore_ascii_case(label.trim())).copied()
1190}
1191
1192// ── The cache (actions/cache) ─────────────────────────────────────────────
1193//
1194// Entries are kept in R2 by the API (the ACTIONS_CACHE bucket) and listed
1195// here, by the actions service, which decides what is found, what fits and
1196// what is evicted. A sandbox reaches these through the API with its job's
1197// token: `/actions/jobs/{job}/cache` (see apps/api/src/blobs.rs).
1198
1199/// The largest one cache entry may be, compressed.
1200pub const CACHE_MAX_ENTRY_BYTES: u64 = 2 * 1024 * 1024 * 1024;
1201/// What one repository's entries may hold together. Saving past it evicts
1202/// the entries restored longest ago.
1203pub const CACHE_REPO_QUOTA_BYTES: u64 = 10 * 1024 * 1024 * 1024;
1204/// An entry not restored for this long is deleted.
1205pub const CACHE_UNUSED_DAYS: u64 = 7;
1206/// An entry is deleted this long after it was saved, however often it is
1207/// restored (the bucket's own lifecycle rule deletes objects at 30 days).
1208pub const CACHE_MAX_AGE_DAYS: u64 = 28;
1209/// An upload is sent in parts of this size (the last may be smaller).
1210pub const CACHE_PART_BYTES: u64 = 32 * 1024 * 1024;
1211/// What R2 charges g1t to store a GB for a month, in millionths of a
1212/// dollar ($0.015): what the cache's storage is charged at, plus the margin.
1213pub const CACHE_MICROS_PER_GB_MONTH: i64 = 15_000;
1214
1215/// `cache_lookup`: the entry a job restores: its key exactly, else the
1216/// newest whose key starts with one of `restore`, in order.
1217/// Returns `Outcome<Option<CacheHit>>`.
1218#[derive(Debug, Serialize, Deserialize)]
1219pub struct CacheLookupArgs {
1220 pub job: String,
1221 pub token: String,
1222 pub key: String,
1223 #[serde(default)]
1224 pub restore: Vec<String>,
1225 /// The entry's version, a hash of its paths and compression, as the
1226 /// toolkit's client and g1t's runner both send it: only an entry of the
1227 /// same version is found. `None` from runners that send none, whose
1228 /// entries have none.
1229 #[serde(default)]
1230 pub version: Option<String>,
1231}
1232
1233#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1234pub struct CacheHit {
1235 pub key: String,
1236 pub object: String,
1237 pub size: u64,
1238 /// When it was saved, RFC 3339.
1239 #[serde(default)]
1240 pub created_at: String,
1241 /// A signed token for downloading it through the toolkit's blob
1242 /// endpoint, when the lookup came with a version.
1243 #[serde(default)]
1244 pub blob: Option<String>,
1245}
1246
1247/// `cache_reserve`: a job about to save `size` bytes under `key`. Refused
1248/// when the key is taken (`conflict`: keys are written once) or the entry
1249/// is too large. Returns `Outcome<CacheReservation>`.
1250#[derive(Debug, Serialize, Deserialize)]
1251pub struct CacheReserveArgs {
1252 pub job: String,
1253 pub token: String,
1254 pub key: String,
1255 /// Its size, when known before it is sent (the toolkit's newer client
1256 /// says only when it finishes: 0 then).
1257 pub size: u64,
1258 /// As in `CacheLookupArgs`.
1259 #[serde(default)]
1260 pub version: Option<String>,
1261}
1262
1263#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1264pub struct CacheReservation {
1265 pub id: String,
1266 /// Where the API puts it in R2.
1267 pub object: String,
1268 /// The entry's number, which the toolkit's older protocol names it by.
1269 #[serde(default)]
1270 pub number: u64,
1271 /// Its R2 upload, once one is started.
1272 #[serde(default)]
1273 pub upload: Option<String>,
1274 /// A signed token for sending its parts through the toolkit's blob
1275 /// endpoint, once its upload is started.
1276 #[serde(default)]
1277 pub blob: Option<String>,
1278}
1279
1280/// `cache_upload`: an entry a job is still uploading, by its number or by
1281/// key and version. Returns `Outcome<CacheReservation>`, with `upload` and
1282/// `blob` set once its upload has been started.
1283#[derive(Debug, Serialize, Deserialize)]
1284pub struct CacheUploadArgs {
1285 pub job: String,
1286 pub token: String,
1287 #[serde(default)]
1288 pub number: Option<u64>,
1289 #[serde(default)]
1290 pub key: Option<String>,
1291 #[serde(default)]
1292 pub version: Option<String>,
1293}
1294
1295/// `cache_commit`: the upload of `id` is complete, at `size` bytes. Returns
1296/// `Outcome<CacheCommitted>`: the objects of entries it evicted, which the
1297/// API deletes from R2.
1298#[derive(Debug, Serialize, Deserialize)]
1299pub struct CacheCommitArgs {
1300 pub job: String,
1301 pub token: String,
1302 pub id: String,
1303 pub size: u64,
1304}
1305
1306#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1307pub struct CacheCommitted {
1308 pub evicted: Vec<String>,
1309}
1310
1311/// `cache_abort`: an upload that will not finish; its reservation goes.
1312/// Returns `Outcome<bool>`.
1313#[derive(Debug, Serialize, Deserialize)]
1314pub struct CacheAbortArgs {
1315 pub job: String,
1316 pub token: String,
1317 pub id: String,
1318}
1319
1320/// A cache entry as people see it, in GitHub's shape: `id` is a number,
1321/// `git_ref` the ref whose run saved it (sent as `ref`; a pull request from
1322/// outside the repository saves under `untrusted:<ref>`), `version` the
1323/// hash of its paths and compression (empty for one g1t's own
1324/// `actions/cache` saved).
1325#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1326pub struct CacheEntry {
1327 pub id: u64,
1328 pub key: String,
1329 #[serde(rename = "ref")]
1330 pub git_ref: String,
1331 pub version: String,
1332 pub size_in_bytes: u64,
1333 pub created_at: String,
1334 pub last_accessed_at: String,
1335}
1336
1337/// A page of cache entries, in GitHub's shape.
1338#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1339pub struct CacheList {
1340 pub total_count: u64,
1341 pub actions_caches: Vec<CacheEntry>,
1342}
1343
1344/// How a list of cache entries is ordered: GitHub's `sort` names.
1345pub const CACHE_SORTS: [&str; 3] = ["last_accessed_at", "created_at", "size_in_bytes"];
1346
1347/// `caches`: a repository's saved cache entries, narrowed to keys starting
1348/// with `key` and to one `git_ref`, ordered by `sort` (one of
1349/// `CACHE_SORTS`, `last_accessed_at` by default) in `direction` (`asc` or
1350/// `desc`, the default), a page at a time (30 by default, at most 100).
1351/// Anyone who can see the repository. Returns `Outcome<CacheList>`.
1352#[derive(Debug, Serialize, Deserialize)]
1353pub struct CachesArgs {
1354 pub repo: RepoPath,
1355 pub viewer: Viewer,
1356 #[serde(default)]
1357 pub key: Option<String>,
1358 #[serde(default)]
1359 pub git_ref: Option<String>,
1360 #[serde(default)]
1361 pub sort: Option<String>,
1362 #[serde(default)]
1363 pub direction: Option<String>,
1364 #[serde(default)]
1365 pub page: Option<u32>,
1366 #[serde(default)]
1367 pub per_page: Option<u32>,
1368}
1369
1370/// `cache_usage`: what a repository's saved entries hold together, against
1371/// `CACHE_REPO_QUOTA_BYTES`. Anyone who can see the repository. Returns
1372/// `Outcome<CacheUsage>`.
1373#[derive(Debug, Serialize, Deserialize)]
1374pub struct CacheUsageArgs {
1375 pub repo: RepoPath,
1376 pub viewer: Viewer,
1377}
1378
1379/// GitHub's shape, with the most the repository may hold.
1380#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1381pub struct CacheUsage {
1382 pub active_caches_size_in_bytes: u64,
1383 pub active_caches_count: u64,
1384 pub quota_bytes: u64,
1385}
1386
1387/// `delete_caches`: deletes one entry by `id`, or every entry whose key is
1388/// exactly `key` (only `git_ref`'s, when given). Needs the Write role.
1389/// Returns the entries deleted: `Outcome<CacheList>`.
1390#[derive(Debug, Serialize, Deserialize)]
1391pub struct DeleteCachesArgs {
1392 pub actor: User,
1393 pub repo: RepoPath,
1394 #[serde(default)]
1395 pub id: Option<u64>,
1396 #[serde(default)]
1397 pub key: Option<String>,
1398 #[serde(default)]
1399 pub git_ref: Option<String>,
1400}
1401
1402// ── Artifacts (actions/upload-artifact) ───────────────────────────────────
1403//
1404// Kept in R2 by the API (the ACTIONS_CACHE bucket, under `a/`) and listed
1405// here, by the actions service, which decides names, sizes and how long
1406// each is kept. A sandbox reaches them with its job's token
1407// (`/actions/jobs/{job}/artifacts…`) or, through the toolkit's protocol,
1408// with its runtime token (`ACTIONS_RUNTIME_TOKEN`); people through the
1409// REST API and the run's page.
1410
1411/// The largest one artifact may be.
1412pub const ARTIFACT_MAX_BYTES: u64 = 5 * 1024 * 1024 * 1024;
1413/// What one run's artifacts may hold together.
1414pub const RUN_ARTIFACTS_MAX_BYTES: u64 = 10 * 1024 * 1024 * 1024;
1415/// How long artifacts are kept unless a repository says otherwise.
1416pub const ARTIFACT_RETENTION_DEFAULT_DAYS: u32 = 14;
1417/// The longest a repository may keep them.
1418pub const ARTIFACT_RETENTION_MAX_DAYS: u32 = 90;
1419/// A native upload is sent in parts of this size (the last may be smaller).
1420pub const ARTIFACT_PART_BYTES: u64 = 32 * 1024 * 1024;
1421
1422/// An artifact, as the API and the site show it.
1423#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1424pub struct Artifact {
1425 pub id: u64,
1426 pub name: String,
1427 pub size: u64,
1428 /// `sha256:<hex>`, when the uploader said.
1429 pub digest: Option<String>,
1430 /// `zip`, or `tgz` for one an older runner sent.
1431 pub format: String,
1432 pub run_id: String,
1433 pub job_id: String,
1434 pub repo_id: String,
1435 /// Whether it has expired or been deleted (its bytes are gone).
1436 pub expired: bool,
1437 pub created_at: String,
1438 pub updated_at: String,
1439 pub expires_at: String,
1440 /// The run's branch and commit, for the REST shape.
1441 #[serde(default)]
1442 pub head_branch: Option<String>,
1443 #[serde(default)]
1444 pub head_sha: Option<String>,
1445}
1446
1447/// An artifact with where its bytes are, and a signed token for them.
1448#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1449pub struct ArtifactBlob {
1450 pub artifact: Artifact,
1451 pub object: String,
1452 /// For the toolkit's blob endpoint (`/actions/toolkit/blobs/{blob}`).
1453 pub blob: String,
1454}
1455
1456/// A page of artifacts, in GitHub's shape.
1457#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1458pub struct ArtifactList {
1459 pub total_count: u64,
1460 pub artifacts: Vec<Artifact>,
1461}
1462
1463/// `artifact_reserve`: a job about to upload an artifact. Refused when its
1464/// run has one of that name and `overwrite` is not set (`conflict`), or it
1465/// is too large. Returns `Outcome<ArtifactReservation>`.
1466#[derive(Debug, Default, Serialize, Deserialize)]
1467pub struct ArtifactReserveArgs {
1468 pub job: String,
1469 /// The job's token, or its runtime token.
1470 pub token: String,
1471 pub name: String,
1472 /// Its size, when known before it is sent (0 otherwise).
1473 #[serde(default)]
1474 pub size: u64,
1475 /// Days to keep it: 0 for the repository's default; at most the
1476 /// repository's setting.
1477 #[serde(default)]
1478 pub retention_days: u32,
1479 /// When to expire it, RFC 3339, as the toolkit says it (in place of
1480 /// `retention_days`).
1481 #[serde(default)]
1482 pub expires_at: Option<String>,
1483 #[serde(default)]
1484 pub overwrite: bool,
1485 /// `zip` (the default) or `tgz`.
1486 #[serde(default)]
1487 pub format: Option<String>,
1488}
1489
1490#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1491pub struct ArtifactReservation {
1492 pub id: u64,
1493 /// Where the API puts it in R2.
1494 pub object: String,
1495 /// The days it will be kept, and until when.
1496 pub retention_days: u32,
1497 pub expires_at: String,
1498}
1499
1500/// `artifact_commit`: its upload is complete, at `size` bytes. The artifact
1501/// is named by `id`, or by `name` in the job's run (the toolkit's way).
1502/// Returns `Outcome<Artifact>`.
1503#[derive(Debug, Default, Serialize, Deserialize)]
1504pub struct ArtifactCommitArgs {
1505 pub job: String,
1506 pub token: String,
1507 #[serde(default)]
1508 pub id: Option<u64>,
1509 #[serde(default)]
1510 pub name: Option<String>,
1511 pub size: u64,
1512 #[serde(default)]
1513 pub digest: Option<String>,
1514}
1515
1516/// `job_artifacts`: a running job listing the artifacts of its own run, or
1517/// of another run of its repository (`run_id`), narrowed by `name` or
1518/// `id`: `Outcome<Vec<Artifact>>`. `job_artifact` gives the one named, with
1519/// a token to download it: `Outcome<ArtifactBlob>`. `job_delete_artifact`
1520/// deletes one of its own run's: `Outcome<Artifact>`. `artifact_abort`
1521/// gives up an upload by `id`: `Outcome<bool>`.
1522#[derive(Debug, Default, Serialize, Deserialize)]
1523pub struct JobArtifactsArgs {
1524 pub job: String,
1525 pub token: String,
1526 #[serde(default)]
1527 pub run_id: Option<String>,
1528 #[serde(default)]
1529 pub name: Option<String>,
1530 #[serde(default)]
1531 pub id: Option<u64>,
1532}
1533
1534/// `artifacts`: a repository's artifacts, newest first, or one run's.
1535/// Anyone who can see the repository. Returns `Outcome<ArtifactList>`.
1536#[derive(Debug, Serialize, Deserialize)]
1537pub struct ArtifactsArgs {
1538 pub repo: RepoPath,
1539 pub viewer: Viewer,
1540 #[serde(default)]
1541 pub run: Option<String>,
1542 #[serde(default)]
1543 pub name: Option<String>,
1544 #[serde(default)]
1545 pub page: Option<u32>,
1546 #[serde(default)]
1547 pub per_page: Option<u32>,
1548}
1549
1550/// `artifact` (`Outcome<Artifact>`) and `artifact_download`
1551/// (`Outcome<ArtifactBlob>`, with a token good for a few minutes): one
1552/// artifact by `id`, or by `name` within `run`. Anyone who can see the
1553/// repository.
1554#[derive(Debug, Serialize, Deserialize)]
1555pub struct ArtifactArgs {
1556 pub repo: RepoPath,
1557 pub viewer: Viewer,
1558 #[serde(default)]
1559 pub id: Option<u64>,
1560 #[serde(default)]
1561 pub run: Option<String>,
1562 #[serde(default)]
1563 pub name: Option<String>,
1564}
1565
1566/// `delete_artifact`: needs the Write role. Returns `Outcome<Artifact>`.
1567#[derive(Debug, Serialize, Deserialize)]
1568pub struct DeleteArtifactArgs {
1569 pub actor: User,
1570 pub repo: RepoPath,
1571 pub id: u64,
1572}
1573
1574/// `artifact_retention`: anyone who can see the repository. With `days`,
1575/// sets it, which needs the Maintain role. Returns
1576/// `Outcome<ArtifactRetention>`.
1577#[derive(Debug, Serialize, Deserialize)]
1578pub struct ArtifactRetentionArgs {
1579 pub repo: RepoPath,
1580 pub viewer: Viewer,
1581 #[serde(default)]
1582 pub days: Option<u32>,
1583}
1584
1585/// GitHub's shape: the days artifacts are kept by default, and the most a
1586/// repository may choose.
1587#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1588pub struct ArtifactRetention {
1589 pub days: u32,
1590 pub maximum_allowed_days: u32,
1591}
1592
1593// ── The toolkit's protocols ───────────────────────────────────────────────
1594//
1595// Actions built on GitHub's toolkit (`@actions/cache`, `@actions/artifact`,
1596// `@actions/core`'s `getIDToken`) reach g1t with the job's runtime token,
1597// `ACTIONS_RUNTIME_TOKEN`: a JSON Web Token whose `scp` names the run and
1598// job, signed with a key derived from the job's own token, so the actions
1599// service checks it without keeping another secret. Cache and artifact
1600// operations above take it in place of the job's token.
1601
1602/// `runtime_auth`: which job a runtime token is, while it runs:
1603/// `Outcome<RuntimeJob>`. `oidc_claims` takes the same and returns
1604/// `Outcome<Value>`: the claims of the job's OIDC token, less `iss`, `aud`,
1605/// `jti` and the times, or `forbidden` when the job's `permissions` do not
1606/// give it `id-token: write`.
1607#[derive(Debug, Serialize, Deserialize)]
1608pub struct RuntimeAuthArgs {
1609 pub job: String,
1610 pub token: String,
1611}
1612
1613#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1614pub struct RuntimeJob {
1615 pub job: String,
1616 pub run: String,
1617 pub repo_id: String,
1618 pub namespace: String,
1619 /// `owner/name`.
1620 pub repository: String,
1621}
1622
1623/// What a signed blob token lets its holder do.
1624#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1625pub struct BlobGrant {
1626 /// `cache` or `artifact`.
1627 pub kind: String,
1628 /// The entry's id: a cache entry's `cache_…`, an artifact's number.
1629 pub id: String,
1630 pub object: String,
1631 /// The R2 upload it sends parts to; `None` for a download.
1632 pub upload: Option<String>,
1633 /// For a download: what to call the file, and its type.
1634 #[serde(default)]
1635 pub filename: Option<String>,
1636 #[serde(default)]
1637 pub content_type: Option<String>,
1638}
1639
1640/// `blob_sign`: a token for uploading an entry the job reserved, to the R2
1641/// upload the API started for it. Returns `Outcome<String>`.
1642#[derive(Debug, Serialize, Deserialize)]
1643pub struct BlobSignArgs {
1644 pub job: String,
1645 pub token: String,
1646 /// `cache` or `artifact`.
1647 pub kind: String,
1648 pub id: String,
1649 pub upload: String,
1650}
1651
1652/// `blob_open`: what a signed token grants, while it is good and its entry
1653/// is there: `Outcome<BlobGrant>`. `blob_part` records a part sent with an
1654/// upload token (`part`, `etag`, `size`): `Outcome<bool>`. `blob_parts`
1655/// gives the parts recorded, in order: `Outcome<Vec<BlobPart>>`, and
1656/// `blob_done` forgets them: `Outcome<bool>`.
1657#[derive(Debug, Default, Serialize, Deserialize)]
1658pub struct BlobArgs {
1659 pub blob: String,
1660 #[serde(default)]
1661 pub part: u32,
1662 #[serde(default)]
1663 pub etag: String,
1664 #[serde(default)]
1665 pub size: u64,
1666}
1667
1668#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1669pub struct BlobPart {
1670 pub part: u32,
1671 pub etag: String,
1672 pub size: u64,
1673}
1674
1675#[cfg(test)]
1676mod instance_tests {
1677 use super::*;
1678
1679 fn labels(given: &[&str]) -> Vec<String> {
1680 given.iter().map(|l| (*l).to_owned()).collect()
1681 }
1682
1683 #[test]
1684 fn runs_on_picks_the_machine() {
1685 assert_eq!(instance_for(&labels(&["ubuntu-latest"])), STANDARD_INSTANCE);
1686 assert_eq!(instance_for(&labels(&[])).label, "standard");
1687 assert_eq!(instance_for(&labels(&["g1t-4core"])).label, "g1t-4core");
1688 assert_eq!(instance_for(&labels(&["ubuntu-latest", "G1T-2Core"])).label, "g1t-2core");
1689 // Both named: the later one.
1690 assert_eq!(instance_for(&labels(&["g1t-2core", "g1t-4core"])).label, "g1t-4core");
1691 assert_eq!(instance_named("g1t-2core").map(|i| i.vcpu), Some(2.0));
1692 assert_eq!(instance_named("g1t-4core").map(|i| i.vcpu), Some(4.0));
1693 assert_eq!(instance_named("standard"), Some(STANDARD_INSTANCE));
1694 assert_eq!(instance_named("g1t-64core"), None);
1695 }
1696
1697 #[test]
1698 fn every_machine_is_a_named_instance_type_at_its_size() {
1699 // Containers' named instance types, at the sizes Cloudflare gives
1700 // them; no custom types.
1701 let named = |container: &str| match container {
1702 "standard-3" => Some((2.0, 8.0, 16.0)),
1703 "standard-4" => Some((4.0, 12.0, 20.0)),
1704 _ => None,
1705 };
1706 for instance in INSTANCE_TYPES {
1707 assert_eq!(named(instance.container), Some((instance.vcpu, instance.memory_gib, instance.disk_gb)), "{}", instance.label);
1708 }
1709 // g1t-2core is a name of the standard machine, in a class of its own.
1710 let two = instance_named("g1t-2core").unwrap();
1711 assert_eq!(InstanceType { label: "standard", class: "AttemptSandbox", ..two }, STANDARD_INSTANCE);
1712 }
1713
1714 #[test]
1715 fn the_catalogue_is_one_row_a_label_and_one_size_a_machine() {
1716 let mut labels: Vec<_> = INSTANCE_TYPES.iter().map(|i| i.label).collect();
1717 let mut classes: Vec<_> = INSTANCE_TYPES.iter().map(|i| i.class).collect();
1718 labels.sort_unstable();
1719 labels.dedup();
1720 classes.sort_unstable();
1721 classes.dedup();
1722 assert_eq!((labels.len(), classes.len()), (INSTANCE_TYPES.len(), INSTANCE_TYPES.len()));
1723 // Every row of a machine says the same size and price as its first.
1724 for instance in INSTANCE_TYPES {
1725 let first = machine_named(instance.machine).unwrap();
1726 assert_eq!(
1727 (instance.container, instance.vcpu, instance.memory_gib, instance.disk_gb, instance.micros_per_minute),
1728 (first.container, first.vcpu, first.memory_gib, first.disk_gb, first.micros_per_minute),
1729 "{}",
1730 instance.label
1731 );
1732 }
1733 assert_eq!(machines().iter().map(|m| m.machine).collect::<Vec<_>>(), ["2-core", "4-core"]);
1734 assert_eq!(STANDARD_INSTANCE.size(), "2 vCPU, 8 GiB, 16 GB");
1735 assert!((INSTANCE_TYPES[2].price_scale() - 1.75).abs() < 1e-12);
1736 }
1737
1738 #[test]
1739 fn rates_cover_the_machine_at_full_cpu_and_its_usual_cost_plus_the_margin() {
1740 // Memory, disk and the Durable Object behind the container (128 MB)
1741 // for every second, and vCPU as used, at Cloudflare's list prices,
1742 // in micros a minute.
1743 let per_minute = |i: &InstanceType, busy_vcpus: f64| 60.0 * (i.memory_gib * 2.5 + i.disk_gb * 0.07 + 0.125 * 12.5 + busy_vcpus * 20.0);
1744 let tenth_of_a_cent = |micros: f64| ((micros / 1_000.0).ceil() * 1_000.0) as i64;
1745 for instance in machines() {
1746 let usual = per_minute(&instance, instance.vcpu / 2.0) * 1.2;
1747 let full = per_minute(&instance, instance.vcpu);
1748 assert_eq!(instance.micros_per_minute, tenth_of_a_cent(usual).max(tenth_of_a_cent(full)), "{}: {usual} {full}", instance.machine);
1749 assert!(instance.micros_per_minute as f64 >= full, "{}", instance.machine);
1750 }
1751 assert_eq!(STANDARD_INSTANCE.micros_per_minute, 4_000);
1752 assert_eq!(machine_named("4-core").map(|m| m.micros_per_minute), Some(7_000));
1753 }
1754
1755 #[test]
1756 fn the_typescript_mirror_has_every_row() {
1757 let mirror = include_str!("../../../packages/contracts/src/instances.ts");
1758 let rows = mirror.lines().filter(|line| line.trim_start().starts_with("{ label: ")).count();
1759 assert_eq!(rows, INSTANCE_TYPES.len());
1760 for i in INSTANCE_TYPES {
1761 let row = format!(
1762 r#"{{ label: "{}", machine: "{}", sandboxClass: "{}", container: "{}", vcpu: {}, memoryGib: {}, diskGb: {}, microsPerMinute: {} }}"#,
1763 i.label, i.machine, i.class, i.container, i.vcpu, i.memory_gib, i.disk_gb, i.micros_per_minute
1764 );
1765 assert!(mirror.contains(&row), "instances.ts has no row\n{row}");
1766 }
1767 }
1768
1769 #[test]
1770 fn a_job_is_charged_its_minutes_rounded_up() {
1771 assert_eq!(runner_minutes(0), 0);
1772 assert_eq!(runner_minutes(-5), 0);
1773 assert_eq!(runner_minutes(1), 1);
1774 assert_eq!(runner_minutes(60), 1);
1775 assert_eq!(runner_minutes(61), 2);
1776 assert_eq!(runner_minutes(3_600), 60);
1777 }
1778
1779 #[test]
1780 fn start_args_from_older_callers_read() {
1781 let args: StartJobArgs = serde_json::from_value(serde_json::json!({
1782 "job": "job_1", "token": "t", "repo": { "namespace": "acme", "name": "web" }, "timeoutMinutes": 30
1783 }))
1784 .unwrap();
1785 assert!(args.instance.is_none() && !args.brokered);
1786 // Callers from when workflow-only domains existed still read.
1787 let older: StartJobArgs = serde_json::from_value(serde_json::json!({
1788 "job": "job_1", "token": "t", "repo": { "namespace": "acme", "name": "web" }, "timeoutMinutes": 30,
1789 "workflow": ".g1t/workflows/deploy.yml", "environment": "production", "trusted": true
1790 }))
1791 .unwrap();
1792 assert_eq!(older.timeout_minutes, 30);
1793 }
1794}
1795
1796#[cfg(test)]
1797mod setting_args_tests {
1798 use super::*;
1799
1800 #[test]
1801 fn who_reads_a_row_is_read_as_the_site_and_api_send_it() {
1802 let args: SetSettingArgs = serde_json::from_value(serde_json::json!({
1803 "actor": { "id": "usr_1", "username": "a" },
1804 "repo": { "namespace": "acme", "name": "web" },
1805 "kind": "secret",
1806 "name": "STRIPE_KEY",
1807 "availableTo": ["deployments"],
1808 "environments": ["production"],
1809 }))
1810 .unwrap();
1811 assert_eq!(args.available_to, Some(vec!["deployments".to_owned()]));
1812 }
1813}