Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55ab5b27dc |
No files matched your search
@@ -103,6 +103,12 @@ git push origin main:release/66
|
|||||||
pnpm deploy:web:staging
|
pnpm deploy:web:staging
|
||||||
```
|
```
|
||||||
|
|
||||||
staging Pages 배포 스크립트는 `CF_PAGES_STAGING_BRANCH`가 있으면 그 값을
|
staging/prod Pages 배포 스크립트는 명시 릴리즈 브랜치 환경변수가 있으면 그
|
||||||
사용하고, 없으면 최신 `release/*` 브랜치를 자동으로 선택합니다. 최신 기준은
|
값을 사용하고, 없으면 최신 `release/*` 브랜치를 자동으로 선택합니다. 최신
|
||||||
브랜치가 가리키는 커밋 시각이며, 동률이면 브랜치명 내림차순입니다.
|
기준은 브랜치가 가리키는 커밋 시각이며, 동률이면 브랜치명 내림차순입니다.
|
||||||
|
staging은 선택된 릴리즈 브랜치로 preview 배포를 만들고, prod는 Cloudflare
|
||||||
|
Pages production branch로 업로드해 production 배포를 만듭니다.
|
||||||
|
|
||||||
|
명시 릴리즈 브랜치는 staging은 `CF_PAGES_STAGING_BRANCH`, prod는
|
||||||
|
`CF_PAGES_RELEASE_BRANCH`로 지정합니다. Cloudflare Pages production branch가
|
||||||
|
`main`이 아니면 `CF_PAGES_PRODUCTION_BRANCH`로 지정합니다.
|
||||||
@@ -26,12 +26,23 @@ export function main(args = process.argv.slice(2), env = process.env) {
|
|||||||
env.CF_PAGES_PROJECT_NAME ??
|
env.CF_PAGES_PROJECT_NAME ??
|
||||||
env.CLOUDFLARE_PAGES_PROJECT_NAME ??
|
env.CLOUDFLARE_PAGES_PROJECT_NAME ??
|
||||||
"lolympus";
|
"lolympus";
|
||||||
const stagingBranch =
|
const deployPlan = resolveDeployPlan(target, env);
|
||||||
target === "staging" ? resolveStagingBranch(env) : undefined;
|
|
||||||
|
|
||||||
validateEnv(viteMode, env);
|
validateEnv(viteMode, env);
|
||||||
run("pnpm", ["--filter", "web", "run", `build:${target}`], repoRoot);
|
run("pnpm", ["--filter", "web", "run", `build:${target}`], repoRoot);
|
||||||
|
|
||||||
|
const deployArgs = createPagesDeployArgs(projectName, deployPlan.pagesBranch);
|
||||||
|
console.error(
|
||||||
|
[
|
||||||
|
`Deploying ${target} from ${deployPlan.sourceBranch}`,
|
||||||
|
`to Cloudflare Pages branch ${deployPlan.pagesBranch}`,
|
||||||
|
].join(" "),
|
||||||
|
);
|
||||||
|
|
||||||
|
run("pnpm", deployArgs, webDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createPagesDeployArgs(projectName, branch) {
|
||||||
const deployArgs = [
|
const deployArgs = [
|
||||||
"exec",
|
"exec",
|
||||||
"wrangler",
|
"wrangler",
|
||||||
@@ -42,37 +53,62 @@ export function main(args = process.argv.slice(2), env = process.env) {
|
|||||||
projectName,
|
projectName,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (target === "staging") {
|
if (branch) deployArgs.push("--branch", branch);
|
||||||
deployArgs.push("--branch", stagingBranch);
|
return deployArgs;
|
||||||
console.error(
|
|
||||||
`Deploying staging to Cloudflare Pages branch ${stagingBranch}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
run("pnpm", deployArgs, webDir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveStagingBranch(env = process.env) {
|
export function resolveStagingBranch(env = process.env) {
|
||||||
const configuredBranch = env.CF_PAGES_STAGING_BRANCH?.trim();
|
return resolveDeployPlan("staging", env).pagesBranch;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveDeployPlan(
|
||||||
|
target,
|
||||||
|
env = process.env,
|
||||||
|
releaseBranchRowsProvider = () => {
|
||||||
|
refreshRemoteReleaseBranches();
|
||||||
|
return listReleaseBranchRefs();
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const sourceBranch = resolveSourceBranch(
|
||||||
|
target,
|
||||||
|
env,
|
||||||
|
releaseBranchRowsProvider,
|
||||||
|
);
|
||||||
|
const pagesBranch =
|
||||||
|
target === "prod" ? resolveProductionBranch(env) : sourceBranch;
|
||||||
|
|
||||||
|
return { sourceBranch, pagesBranch };
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveSourceBranch(target, env, releaseBranchRowsProvider) {
|
||||||
|
const sourceEnvKey =
|
||||||
|
target === "prod" ? "CF_PAGES_RELEASE_BRANCH" : "CF_PAGES_STAGING_BRANCH";
|
||||||
|
const configuredBranch = env[sourceEnvKey]?.trim();
|
||||||
if (configuredBranch) return configuredBranch;
|
if (configuredBranch) return configuredBranch;
|
||||||
|
|
||||||
refreshRemoteReleaseBranches();
|
|
||||||
|
|
||||||
const latestReleaseBranch = selectLatestReleaseBranch(
|
const latestReleaseBranch = selectLatestReleaseBranch(
|
||||||
listReleaseBranchRefs(),
|
releaseBranchRowsProvider(),
|
||||||
);
|
);
|
||||||
if (latestReleaseBranch) return latestReleaseBranch;
|
if (latestReleaseBranch) return latestReleaseBranch;
|
||||||
|
|
||||||
console.error(
|
console.error(
|
||||||
[
|
[
|
||||||
"No release/* branch found for staging deploy.",
|
`No release/* branch found for ${target} deploy.`,
|
||||||
"Create a release branch, for example: git push origin main:release/66",
|
"Create a release branch, for example: git push origin main:release/66",
|
||||||
"Or set CF_PAGES_STAGING_BRANCH explicitly.",
|
`Or set ${sourceEnvKey} explicitly.`,
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveProductionBranch(env) {
|
||||||
|
return (
|
||||||
|
env.CF_PAGES_PRODUCTION_BRANCH?.trim() ||
|
||||||
|
env.CF_PAGES_PROD_BRANCH?.trim() ||
|
||||||
|
"main"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function selectLatestReleaseBranch(refRows) {
|
export function selectLatestReleaseBranch(refRows) {
|
||||||
const latestByBranch = new Map();
|
const latestByBranch = new Map();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { describe, it } from "node:test";
|
||||||
|
|
||||||
|
import {
|
||||||
|
createPagesDeployArgs,
|
||||||
|
resolveDeployPlan,
|
||||||
|
} from "./deploy-cloudflare-pages.mjs";
|
||||||
|
|
||||||
|
describe("deploy-cloudflare-pages", () => {
|
||||||
|
it("deploys prod to the production branch using the latest release branch as source", () => {
|
||||||
|
const plan = resolveDeployPlan("prod", {}, () => [
|
||||||
|
"1710000000\torigin/release/66",
|
||||||
|
"1720000000\torigin/release/67",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert.deepEqual(plan, {
|
||||||
|
sourceBranch: "release/67",
|
||||||
|
pagesBranch: "main",
|
||||||
|
});
|
||||||
|
assert.deepEqual(
|
||||||
|
createPagesDeployArgs("lolympus", plan.pagesBranch),
|
||||||
|
[
|
||||||
|
"exec",
|
||||||
|
"wrangler",
|
||||||
|
"pages",
|
||||||
|
"deploy",
|
||||||
|
"dist",
|
||||||
|
"--project-name",
|
||||||
|
"lolympus",
|
||||||
|
"--branch",
|
||||||
|
"main",
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps explicit staging branch override behavior", () => {
|
||||||
|
const plan = resolveDeployPlan(
|
||||||
|
"staging",
|
||||||
|
{ CF_PAGES_STAGING_BRANCH: "release/manual" },
|
||||||
|
() => {
|
||||||
|
throw new Error("should not inspect git refs when branch is explicit");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(plan, {
|
||||||
|
sourceBranch: "release/manual",
|
||||||
|
pagesBranch: "release/manual",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows overriding the Cloudflare Pages production branch", () => {
|
||||||
|
const plan = resolveDeployPlan(
|
||||||
|
"prod",
|
||||||
|
{ CF_PAGES_PRODUCTION_BRANCH: "production" },
|
||||||
|
() => ["1720000000\torigin/release/67"],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(plan, {
|
||||||
|
sourceBranch: "release/67",
|
||||||
|
pagesBranch: "production",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user