feat: wpop provisino

This commit is contained in:
2026-06-11 14:13:56 -04:00
parent b8973559ca
commit 9b7cb13e65
5 changed files with 475 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
import { z } from "zod";
import { consola } from "consola";
import { execa } from "execa";
import { getGiteaBaseUrl, getGiteaToken } from "./gitea";
const deployEnvSchema = z.object({
REMOTE_HOST: z.string().min(1),
@@ -25,6 +26,48 @@ const giteaVariableKeys = [
export type DeployEnv = z.infer<typeof deployEnvSchema>;
const provisionEnvSchema = z.object({
WP_LOCAL_ROOT_PATH: z.string().min(1),
WEBSIMPLE_STACK_DOMAIN: z.string().min(1),
WEBSIMPLE_STACK_PROTOCOL: z.string().default("https"),
WP_VERSION: z.string().default("latest"),
WP_LOCALE: z.string().default("fr_CA"),
WPOP_GITEA_OWNER: z.string().default("wp-sites"),
WPOP_GITEA_TEMPLATE: z.string().default("templates/wp-boilerplate"),
WPOP_GITEA_SSH_USER: z.string().default("git"),
WPOP_GITEA_SSH_PORT: z.coerce.number().int().positive().default(222),
});
export type ProvisionEnv = z.infer<typeof provisionEnvSchema> & {
giteaToken: string;
giteaBaseUrl: string;
};
export function readProvisionEnv(env: NodeJS.ProcessEnv = process.env): ProvisionEnv {
const missing = (["WP_LOCAL_ROOT_PATH", "WEBSIMPLE_STACK_DOMAIN"] as const).filter(
(key) => !hasValue(env[key]),
);
if (missing.length > 0) {
throw new Error(`Missing provision environment variable(s): ${missing.join(", ")}`);
}
const giteaToken = getGiteaToken(env);
if (!giteaToken) {
throw new Error(
[
"Missing Gitea API token for provisioning.",
"Set WPOP_GITEA_TOKEN, WEBSIMPLE_GITEA_API_TOKEN, or GITEA_TOKEN (write access required to create the site repository).",
].join("\n"),
);
}
return {
...provisionEnvSchema.parse(env),
giteaToken,
giteaBaseUrl: getGiteaBaseUrl(env),
};
}
type GiteaVariableKey = (typeof giteaVariableKeys)[number];
type GiteaRepo = {
@@ -118,14 +161,6 @@ async function readGiteaDeployEnv(
};
}
function getGiteaToken(env: NodeJS.ProcessEnv): string | undefined {
return firstValue(env.WPOP_GITEA_TOKEN, env.WEBSIMPLE_GITEA_API_TOKEN, env.GITEA_TOKEN);
}
function getGiteaBaseUrl(env: NodeJS.ProcessEnv): string {
return firstValue(env.WPOP_GITEA_BASE_URL, env.GITEA_BASE_URL) ?? "https://gitea.websimple.com";
}
async function resolveGiteaRepo(
env: NodeJS.ProcessEnv,
cwd: string,