Skip to content

Commit e306d4a

Browse files
authored
fix: allow tagged detached head for prod deploy (#711)
1 parent 93d272e commit e306d4a

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

scripts/deploy-pages-safe.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ async function getGitRef(args = ["rev-parse", "--abbrev-ref", "HEAD"]) {
242242
async function preflight(targetName, target) {
243243
const branch = await getGitRef();
244244
const commit = await getGitRef(["rev-parse", "--short", "HEAD"]);
245+
const pkg = JSON.parse(await readFile(path.join(root, "package.json"), "utf8"));
246+
const expectedReleaseTag = `v${String(pkg.version ?? "").trim()}`;
247+
const { stdout: headTagsStdout } = await run("git", ["tag", "--points-at", "HEAD"], { capture: true });
248+
const headTags = headTagsStdout
249+
.split("\n")
250+
.map((line) => line.trim())
251+
.filter(Boolean);
245252
const status = await run("git", ["status", "--porcelain"], { capture: true });
246253
const dirtyPaths = parseDirtyPathsFromPorcelain(status.stdout);
247254
const unexpectedDirty = dirtyPaths.filter((file) => !ALLOWED_DIRTY_PATHS.has(file));
@@ -253,7 +260,12 @@ async function preflight(targetName, target) {
253260
console.log(`[deploy-pages-safe] Allowing expected dirty files: ${dirtyPaths.join(", ")}`);
254261
}
255262
if (target.requiredBranch) {
256-
assert(branch === target.requiredBranch, `Preflight failed: target ${targetName} requires current branch '${target.requiredBranch}'.`);
263+
const isTaggedProdCheckout =
264+
targetName === "prod-main" && branch === "HEAD" && headTags.includes(expectedReleaseTag);
265+
assert(
266+
branch === target.requiredBranch || isTaggedProdCheckout,
267+
`Preflight failed: target ${targetName} requires current branch '${target.requiredBranch}'.`,
268+
);
257269
}
258270

259271
await verifyRequiredDeployEnv(targetName);

0 commit comments

Comments
 (0)