Repository navigation
feat(template): deploy templates whose services build from a GitHub repo #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CarmenDou
wants to merge
4
commits into
main
Choose a base branch
from
feat/template-github-sources
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+365
−22
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
35f30be
feat(template): accept a GitHub source on a compute service
CarmenDou bed3a6e
feat(template): deploy links GitHub when a source repo needs it
CarmenDou b750732
fix(template): correct kind-switch help and show source in drafts
CarmenDou cc391d0
fix(template): strip control characters from rendered GitHub source text
CarmenDou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,12 +22,16 @@ export type ManifestEnv = { | |||||
| optional?: Record<string, VarSpec | string> | ||||||
| } | ||||||
|
|
||||||
| // The platform API's SourceInput names. The start command stays in the service's `command`. | ||||||
| export type ManifestSource = { owner?: string; repo?: string; branch?: string; rootDir?: string; buildCommand?: string } | ||||||
|
|
||||||
| export type ManifestService = { | ||||||
| type?: string // web and worker are judged here, every other type (postgres, redis, mysql, mongodb, storage) is the platform's call | ||||||
| pgVersion?: number // postgres only, a Postgres major the platform offers, checked by the platform | ||||||
| public?: boolean // storage only, anonymous public-read, checked by the platform | ||||||
| image?: string | ||||||
| build?: string | ||||||
| source?: ManifestSource // a GitHub repo the platform builds at deploy, instead of image or build | ||||||
| port?: number | ||||||
| healthcheck?: string | ||||||
| volume?: boolean // needs a /data disk; the platform owns the size | ||||||
|
|
@@ -67,6 +71,9 @@ export const ENV_NAME_RE = /^[A-Z][A-Z0-9_]{0,63}$/ | |||||
| const GENERATOR_RE = /^secret:([1-9]\d{0,2})$/ | ||||||
| // The platform's HEALTHCHECK_RE (src/provisioning/templateManifest.ts), verbatim. | ||||||
| const HEALTHCHECK_RE = /^\/(?!\/)[A-Za-z0-9\-._~!$&'()*+,;=:@%/?]*$/ | ||||||
| // GitHub's grammars for a source's owner and repo, as the platform parser has them. | ||||||
| const GITHUB_OWNER_RE = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/ | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This accepts invalid GitHub owners such as Prompt for AI agents
Suggested change
|
||||||
| const GITHUB_REPO_RE = /^[A-Za-z0-9._-]{1,100}$/ | ||||||
|
|
||||||
| // The compute vocabulary every CLI has known. Any other type is the platform's to accept or refuse. | ||||||
| const COMPUTE_TYPES = ['web', 'worker'] | ||||||
|
|
@@ -111,6 +118,27 @@ function asVarSpec(v: VarSpec | string | null | undefined): VarSpec { | |||||
| return v ?? {} | ||||||
| } | ||||||
|
|
||||||
| // Mirrors parseTemplateSource in the platform's src/provisioning/templateManifest.ts, all at once. | ||||||
| function sourceProblems(where: string, raw: unknown): string[] { | ||||||
| if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return [`${where}.source must be a map`] | ||||||
| const s = raw as Record<string, unknown> | ||||||
| const problems: string[] = [] | ||||||
| if (typeof s.owner !== 'string' || !GITHUB_OWNER_RE.test(s.owner)) problems.push(`${where}.source.owner must be a GitHub user or organization name`) | ||||||
| if (typeof s.repo !== 'string' || !GITHUB_REPO_RE.test(s.repo) || s.repo === '.' || s.repo === '..') problems.push(`${where}.source.repo must be a GitHub repository name`) | ||||||
| if (s.branch !== undefined) { | ||||||
| const b = typeof s.branch === 'string' ? s.branch.trim() : '' | ||||||
| if (!b || b.length > 255 || /\s/.test(b) || b.includes('..') || b.startsWith('/') || b.endsWith('/')) problems.push(`${where}.source.branch must be a branch name`) | ||||||
| } | ||||||
| if (s.rootDir !== undefined) { | ||||||
| const d = typeof s.rootDir === 'string' ? s.rootDir.trim() : null | ||||||
| if (d === null || d.startsWith('/') || d.split('/').includes('..')) problems.push(`${where}.source.rootDir must be a relative path inside the repository`) | ||||||
| } | ||||||
| if (s.buildCommand !== undefined && (typeof s.buildCommand !== 'string' || s.buildCommand.trim().length > 1000)) { | ||||||
| problems.push(`${where}.source.buildCommand must be a command of at most 1000 characters`) | ||||||
| } | ||||||
| return problems | ||||||
| } | ||||||
|
|
||||||
| /** All local validation problems, empty when the manifest is deployable. */ | ||||||
| export function validateManifest(m: TemplateManifest): string[] { | ||||||
| const problems: string[] = [] | ||||||
|
|
@@ -135,8 +163,11 @@ export function validateManifest(m: TemplateManifest): string[] { | |||||
| const type = typeof svc.type === 'string' ? svc.type : undefined | ||||||
| // Every other type, and every field and env on it, is the platform's to judge. It answers 400 with its own list. | ||||||
| if (!type || !COMPUTE_TYPES.includes(type)) continue | ||||||
| if (svc.image && svc.build) problems.push(`${where}: image and build are mutually exclusive`) | ||||||
| if (!svc.image && !svc.build) problems.push(`${where}: one of image or build is required`) | ||||||
| // The platform's order: required check first, then exclusion by keys present. | ||||||
| const present = [svc.image, svc.build, svc.source].filter((v) => v !== undefined).length | ||||||
| if (!svc.image && !svc.build && svc.source === undefined) problems.push(`${where}: one of image, build or source is required`) | ||||||
| else if (present > 1) problems.push(`${where}: image, build and source are mutually exclusive`) | ||||||
| if (svc.source !== undefined) problems.push(...sourceProblems(where, svc.source)) | ||||||
| // A parsed YAML document holds whatever the author typed, so both scalars are type-checked the | ||||||
| // platform's way BEFORE any rule reads them as strings. | ||||||
| const image = svc.image !== undefined ? scalarString(svc.image) : undefined | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3:
--yespromises a non-interactive run, but it only suppresses the variable prompt (ttyincludes!opts.yes); the new GitHub-authorization gatecanAuthorizeHere(opts)ignoresopts.yes, soinsta template deploy <code> --yeson a terminal still starts the device/App-install flow and can block for up to 15 minutes per repo. Gate the GitHub path behind--yesas well, so--yesmeans no interactive steps of either kind.Prompt for AI agents