pr_01m47d24b0e6n91zwymwxg0vpx/packages/contracts/src/deployments.ts
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.
| Deployments: a preview for every pull request, production on g1t.page | 1 | import type { User, Viewer } from "./identity"; |
| 2 | import type { Result } from "./result"; | |
| 3 | ||
| 4 | /** | |
| Projects: what a workspace builds and runs, first on every page | 5 | * Deployments: a project's production, deployed from its default branch on |
| 6 | * every push, and a live preview of every branch with an open pull request. | |
| 7 | * Apps run as Workers in a Workers for Platforms namespace, so an app no | |
| 8 | * one visits costs nothing. A paid feature: the workspace turns it on with | |
| 9 | * a monthly plan (see `Feature` in `./billing`), and each project then | |
| 10 | * chooses for itself. | |
| Deployments: a preview for every pull request, production on g1t.page | 11 | */ |
| 12 | ||
| 13 | /** The domain apps are served on. Never g1t.sh, so they share no cookies with it. */ | |
| 14 | export const DEPLOYMENTS_DOMAIN = "g1t.page"; | |
| 15 | ||
| Projects: what a workspace builds and runs, first on every page | 16 | /** A project, as deployments name it. */ |
| 17 | export type ProjectRef = { workspace: string; slug: string }; | |
| 18 | ||
| 19 | /** A project's deployment settings. */ | |
| Deployments: a preview for every pull request, production on g1t.page | 20 | export type DeploySettings = { |
| Projects: what a workspace builds and runs, first on every page | 21 | /** Whether this project deploys at all. Off until someone turns it on. */ |
| Deployments: a preview for every pull request, production on g1t.page | 22 | enabled: boolean; |
| Projects: what a workspace builds and runs, first on every page | 23 | /** A preview for every branch with an open pull request. */ |
| Deployments: a preview for every pull request, production on g1t.page | 24 | previews: boolean; |
| 25 | /** The default branch deployed to production on every push. */ | |
| 26 | production: boolean; | |
| 27 | /** Runs instead of the project's own `build` script. */ | |
| 28 | buildCommand: string | null; | |
| 29 | /** What to serve, for a static site; found by itself when null. */ | |
| 30 | outputDir: string | null; | |
| 31 | /** A preview no one has visited in this many days is taken down. */ | |
| 32 | idleDays: number; | |
| 33 | /** Where production is served. */ | |
| 34 | productionUrl: string; | |
| 35 | }; | |
| 36 | ||
| 37 | export type DeployKind = "preview" | "production"; | |
| 38 | ||
| 39 | export type DeployStatus = | |
| 40 | /** Waiting for a sandbox. */ | |
| 41 | | "queued" | |
| 42 | | "building" | |
| 43 | | "ready" | |
| 44 | | "failed" | |
| 45 | /** Not built: the workspace's plan is off, or the build was replaced. */ | |
| 46 | | "skipped"; | |
| 47 | ||
| 48 | /** One build of one commit, and where it went. */ | |
| 49 | export type Deployment = { | |
| 50 | id: string; | |
| 51 | kind: DeployKind; | |
| Projects: what a workspace builds and runs, first on every page | 52 | /** For a preview: the branch, or `pr-<n>` for a pull request from a fork. */ |
| 53 | branch: string | null; | |
| 54 | /** For a preview: its pull request. */ | |
| Deployments: a preview for every pull request, production on g1t.page | 55 | number: number | null; |
| 56 | commit: string; | |
| 57 | status: DeployStatus; | |
| 58 | url: string; | |
| 59 | /** Why it failed or was skipped. */ | |
| 60 | error: string | null; | |
| 61 | /** What the build could not provide, such as bindings not provisioned yet. */ | |
| 62 | warnings: string[]; | |
| 63 | /** How long the build ran, in seconds; charged at the container price. */ | |
| 64 | buildSeconds: number | null; | |
| 65 | createdBy: string; | |
| 66 | /** RFC 3339. */ | |
| 67 | createdAt: string; | |
| 68 | finishedAt: string | null; | |
| 69 | }; | |
| 70 | ||
| Projects: what a workspace builds and runs, first on every page | 71 | /** An app that is up: production, or one branch's preview. */ |
| Deployments: a preview for every pull request, production on g1t.page | 72 | export type LiveApp = { |
| 73 | kind: DeployKind; | |
| Projects: what a workspace builds and runs, first on every page | 74 | branch: string | null; |
| Deployments: a preview for every pull request, production on g1t.page | 75 | number: number | null; |
| 76 | url: string; | |
| 77 | commit: string; | |
| 78 | /** RFC 3339: when it was last deployed. */ | |
| 79 | deployedAt: string; | |
| 80 | }; | |
| 81 | ||
| Projects: what a workspace builds and runs, first on every page | 82 | /** One project at a glance, for the workspace's page. */ |
| 83 | export type ProjectDeploys = { | |
| 84 | slug: string; | |
| 85 | enabled: boolean; | |
| 86 | production: LiveApp | null; | |
| 87 | previews: number; | |
| 88 | /** The newest build, whatever its status. */ | |
| 89 | latest: Deployment | null; | |
| 90 | }; | |
| 91 | ||
| Deployments: a preview for every pull request, production on g1t.page | 92 | /** What a workspace's apps used this month against its plan. */ |
| 93 | export type DeployUsage = { | |
| 94 | /** `YYYY-MM`. */ | |
| 95 | month: string; | |
| 96 | requests: number; | |
| 97 | cpuMs: number; | |
| 98 | /** Apps up now, and the most at once this month. */ | |
| 99 | apps: number; | |
| 100 | peakApps: number; | |
| 101 | buildSeconds: number; | |
| 102 | /** Charged so far this month for builds, in millionths of a dollar. */ | |
| 103 | buildMicros: number; | |
| 104 | /** RFC 3339: when requests and CPU time were last counted. */ | |
| 105 | countedAt: string | null; | |
| 106 | }; | |
| 107 | ||
| 108 | export interface DeploymentsApi { | |
| 109 | /** Members of the workspace only. */ | |
| Projects: what a workspace builds and runs, first on every page | 110 | settings(project: ProjectRef, viewer: Viewer): Promise<Result<DeploySettings>>; |
| 111 | /** Members only. Turning deployments on needs the workspace's plan. */ | |
| 112 | updateSettings(actor: User, project: ProjectRef, changes: Partial<DeploySettings>): Promise<Result<DeploySettings>>; | |
| 113 | /** The newest builds first, and what is up now. Members only. */ | |
| 114 | list(project: ProjectRef, viewer: Viewer): Promise<Result<{ deployments: Deployment[]; live: LiveApp[] }>>; | |
| 115 | /** One build, with its log. Members only. */ | |
| 116 | get(project: ProjectRef, id: string, viewer: Viewer): Promise<Result<Deployment & { log: string | null }>>; | |
| 117 | /** Builds production (`branch` null), or a branch's preview, again from its head. */ | |
| 118 | redeploy(actor: User, project: ProjectRef, branch: string | null): Promise<Result<Deployment>>; | |
| Project dependencies: addresses, preview stacks, Affects, and agents who know | 119 | /** |
| 120 | * Builds previews of the projects that use this one, under the same | |
| 121 | * branch, each pointed at this branch's preview. Answers at once with the | |
| 122 | * names of the projects being built; the builds go on in the | |
| 123 | * background. Members only. | |
| 124 | */ | |
| 125 | stack(actor: User, project: ProjectRef, branch: string): Promise<Result<string[]>>; | |
| Projects: what a workspace builds and runs, first on every page | 126 | /** Takes production (`branch` null), or a branch's preview, down now. */ |
| 127 | takeDown(actor: User, project: ProjectRef, branch: string | null): Promise<Result<true>>; | |
| 128 | /** Every project of a workspace at a glance. Members only. */ | |
| 129 | overview(workspace: string, viewer: Viewer): Promise<Result<ProjectDeploys[]>>; | |
| Deployments: a preview for every pull request, production on g1t.page | 130 | /** What the workspace's apps used this month. Members only. */ |
| 131 | usage(workspace: string, viewer: Viewer): Promise<Result<DeployUsage>>; | |
| 132 | } |