verifyTurns

tcmts.dev.verifyTurns · #fepkgftt · term · runs on the server

uses node:path

A verify's turns in dist: its own place to build in (dir, dist/candidates/: candidateDir), once no other verify of the same branch has it; and, main's alone, promote: making its tcm the known-good one, which every checkout runs, once no other verify is (dist/verify.lock), until what it returns is called. Verifies of different branches build side by side, and a branch's never waits for a promotion.

import { candidateDir, holdLock } from "#codebase/tcmts/dev";
import path from "node:path";

export async function verifyTurns(
  dist: string,
  branch?: string,
): Promise<{ dir: string; promote: () => Promise<() => void> }> {
  const dir = candidateDir(dist, branch);
  await holdLock(path.join(dir, "verify.lock"), `another verify of ${branch ?? "main"}`);
  return {
    dir,
    promote: () => {
      if (branch)
        throw new Error(`${branch}'s verify makes nothing the known-good tcm: that's main's`);
      return holdLock(
        path.join(dist, "verify.lock"),
        "another verify making its tcm the known-good one",
      );
    },
  };
}

uses

used by