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 { RepoPath } from "./repos"; | |
| 3 | import type { Result } from "./result"; | |
| 4 | ||
| 5 | /** | |
| 6 | * Deployments: every pull request gets a live preview on g1t.page, and the | |
| 7 | * default branch goes to production on each push. Apps run as Workers in a | |
| 8 | * Workers for Platforms namespace, so an app no one visits costs nothing. | |
| 9 | * A paid feature: the workspace turns it on with a monthly plan (see | |
| 10 | * `Feature` in `./billing`), and each repository then chooses for itself. | |
| 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 | ||
| 16 | /** A repository's deployment settings. */ | |
| 17 | export type DeploySettings = { | |
| 18 | /** Whether this repository deploys at all. Off until someone turns it on. */ | |
| 19 | enabled: boolean; | |
| 20 | /** A preview for every open pull request. */ | |
| 21 | previews: boolean; | |
| 22 | /** The default branch deployed to production on every push. */ | |
| 23 | production: boolean; | |
| 24 | /** Runs instead of the project's own `build` script. */ | |
| 25 | buildCommand: string | null; | |
| 26 | /** What to serve, for a static site; found by itself when null. */ | |
| 27 | outputDir: string | null; | |
| 28 | /** Variables the build runs with. Not secret: shown to members. */ | |
| 29 | buildEnv: Record<string, string>; | |
| 30 | /** A preview no one has visited in this many days is taken down. */ | |
| 31 | idleDays: number; | |
| 32 | /** Where production is served. */ | |
| 33 | productionUrl: string; | |
| 34 | }; | |
| 35 | ||
| 36 | export type DeployKind = "preview" | "production"; | |
| 37 | ||
| 38 | export type DeployStatus = | |
| 39 | /** Waiting for a sandbox. */ | |
| 40 | | "queued" | |
| 41 | | "building" | |
| 42 | | "ready" | |
| 43 | | "failed" | |
| 44 | /** Not built: the workspace's plan is off, or the build was replaced. */ | |
| 45 | | "skipped"; | |
| 46 | ||
| 47 | /** One build of one commit, and where it went. */ | |
| 48 | export type Deployment = { | |
| 49 | id: string; | |
| 50 | kind: DeployKind; | |
| 51 | /** For a preview: the pull request. */ | |
| 52 | number: number | null; | |
| 53 | commit: string; | |
| 54 | status: DeployStatus; | |
| 55 | url: string; | |
| 56 | /** Why it failed or was skipped. */ | |
| 57 | error: string | null; | |
| 58 | /** What the build could not provide, such as bindings not provisioned yet. */ | |
| 59 | warnings: string[]; | |
| 60 | /** How long the build ran, in seconds; charged at the container price. */ | |
| 61 | buildSeconds: number | null; | |
| 62 | createdBy: string; | |
| 63 | /** RFC 3339. */ | |
| 64 | createdAt: string; | |
| 65 | finishedAt: string | null; | |
| 66 | }; | |
| 67 | ||
| 68 | /** An app that is up: production, or one pull request's preview. */ | |
| 69 | export type LiveApp = { | |
| 70 | kind: DeployKind; | |
| 71 | number: number | null; | |
| 72 | url: string; | |
| 73 | commit: string; | |
| 74 | /** RFC 3339: when it was last deployed. */ | |
| 75 | deployedAt: string; | |
| 76 | }; | |
| 77 | ||
| 78 | /** What a workspace's apps used this month against its plan. */ | |
| 79 | export type DeployUsage = { | |
| 80 | /** `YYYY-MM`. */ | |
| 81 | month: string; | |
| 82 | requests: number; | |
| 83 | cpuMs: number; | |
| 84 | /** Apps up now, and the most at once this month. */ | |
| 85 | apps: number; | |
| 86 | peakApps: number; | |
| 87 | buildSeconds: number; | |
| 88 | /** Charged so far this month for builds, in millionths of a dollar. */ | |
| 89 | buildMicros: number; | |
| 90 | /** RFC 3339: when requests and CPU time were last counted. */ | |
| 91 | countedAt: string | null; | |
| 92 | }; | |
| 93 | ||
| 94 | export interface DeploymentsApi { | |
| 95 | /** Members of the workspace only. */ | |
| 96 | settings(repo: RepoPath, viewer: Viewer): Promise<Result<DeploySettings>>; | |
| 97 | /** Members of the workspace only. Turning deployments on needs the plan. */ | |
| 98 | updateSettings(actor: User, repo: RepoPath, changes: Partial<DeploySettings>): Promise<Result<DeploySettings>>; | |
| 99 | /** The newest deployments first, and what is up now. */ | |
| 100 | list(repo: RepoPath, viewer: Viewer): Promise<Result<{ deployments: Deployment[]; live: LiveApp[] }>>; | |
| 101 | /** One deployment, with its build log. */ | |
| 102 | get(repo: RepoPath, id: string, viewer: Viewer): Promise<Result<Deployment & { log: string | null }>>; | |
| 103 | /** Builds production, or a pull request's preview, again from its current head. */ | |
| 104 | redeploy(actor: User, repo: RepoPath, number: number | null): Promise<Result<Deployment>>; | |
| 105 | /** Takes production, or a pull request's preview, down now. */ | |
| 106 | takeDown(actor: User, repo: RepoPath, number: number | null): Promise<Result<true>>; | |
| 107 | /** What the workspace's apps used this month. Members only. */ | |
| 108 | usage(workspace: string, viewer: Viewer): Promise<Result<DeployUsage>>; | |
| 109 | } |