@databricks-solutions/lakebase-scm-utils 0.3.10 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{pr-e-E4aP4j.d.cts → pr-D-eayWyJ.d.cts} +59 -1
- package/dist/{pr-e-E4aP4j.d.ts → pr-D-eayWyJ.d.ts} +59 -1
- package/dist/scripts/git/index.cjs +30 -14
- package/dist/scripts/git/index.d.cts +32 -1
- package/dist/scripts/git/index.d.ts +32 -1
- package/dist/scripts/git/index.js +28 -14
- package/dist/scripts/github/index.d.cts +2 -60
- package/dist/scripts/github/index.d.ts +2 -60
- package/dist/scripts/index.cjs +244 -76
- package/dist/scripts/index.d.cts +4 -4
- package/dist/scripts/index.d.ts +4 -4
- package/dist/scripts/index.js +239 -76
- package/dist/scripts/lakebase/ci-resolve-branch.cli.cjs +2 -2
- package/dist/scripts/lakebase/ci-resolve-branch.cli.js +2 -2
- package/dist/scripts/lakebase/collapse-heads.cli.cjs +2 -2
- package/dist/scripts/lakebase/collapse-heads.cli.js +2 -2
- package/dist/scripts/lakebase/detect-language.cli.cjs +2 -2
- package/dist/scripts/lakebase/detect-language.cli.js +2 -2
- package/dist/scripts/lakebase/doctor.cli.cjs +2 -2
- package/dist/scripts/lakebase/doctor.cli.js +2 -2
- package/dist/scripts/lakebase/get-connection.cli.cjs +2 -2
- package/dist/scripts/lakebase/get-connection.cli.js +2 -2
- package/dist/scripts/lakebase/index.cjs +256 -77
- package/dist/scripts/lakebase/index.d.cts +74 -2
- package/dist/scripts/lakebase/index.d.ts +74 -2
- package/dist/scripts/lakebase/index.js +253 -77
- package/dist/scripts/lakebase/infra-runner.cli.cjs +2 -2
- package/dist/scripts/lakebase/infra-runner.cli.js +2 -2
- package/dist/scripts/lakebase/new-migration.cli.cjs +2 -2
- package/dist/scripts/lakebase/new-migration.cli.js +2 -2
- package/dist/scripts/lakebase/schema-diff.cli.cjs +2 -2
- package/dist/scripts/lakebase/schema-diff.cli.js +2 -2
- package/dist/scripts/lakebase/schema-migrate.cli.cjs +2 -2
- package/dist/scripts/lakebase/schema-migrate.cli.js +2 -2
- package/dist/scripts/lakebase/scm-claim-feature.cli.cjs +2 -2
- package/dist/scripts/lakebase/scm-claim-feature.cli.js +2 -2
- package/dist/scripts/lakebase/scm-doctor.cli.cjs +2 -2
- package/dist/scripts/lakebase/scm-doctor.cli.js +2 -2
- package/dist/scripts/lakebase/scm-merge.cli.cjs +2 -2
- package/dist/scripts/lakebase/scm-merge.cli.js +2 -2
- package/dist/scripts/lakebase/scm-reconcile-tier.cli.cjs +2 -2
- package/dist/scripts/lakebase/scm-reconcile-tier.cli.js +2 -2
- package/dist/scripts/util/index.cjs +2 -2
- package/dist/scripts/util/index.js +2 -2
- package/package.json +1 -1
- package/scripts/git/commit-push.ts +60 -14
- package/scripts/lakebase/create-preflight.ts +213 -1
- package/scripts/lakebase/create-project.ts +98 -30
|
@@ -9,20 +9,23 @@ import * as fs from "node:fs";
|
|
|
9
9
|
import * as path from "node:path";
|
|
10
10
|
import { writeEnvFile } from "./env-file.js";
|
|
11
11
|
import { verifyProject, verifyHooks, verifyWorkflows } from "./project-verify.js";
|
|
12
|
-
import { createRepo, getRepoFullName, getCurrentUser } from "../github/repo.js";
|
|
12
|
+
import { createRepo, getRepoFullName, getCurrentUser, deleteRepo } from "../github/repo.js";
|
|
13
13
|
import { cloneRepo } from "../git/clone.js";
|
|
14
14
|
import { gitInit } from "../git/init.js";
|
|
15
|
-
import {
|
|
15
|
+
import { commitInitial, pushInitial, WorkflowScopeError } from "../git/commit-push.js";
|
|
16
16
|
import {
|
|
17
17
|
createLakebaseProject,
|
|
18
18
|
getDefaultBranchId,
|
|
19
|
+
deleteLakebaseProject,
|
|
19
20
|
} from "./lakebase-project.js";
|
|
20
21
|
import {
|
|
21
22
|
checkDatabricksAuth,
|
|
22
23
|
databricksAuthPrereqMessage,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
checkGitHubPreflight,
|
|
25
|
+
warmAndVerifyKit,
|
|
26
|
+
kitWarmWarning,
|
|
27
|
+
createRollbackLedger,
|
|
28
|
+
withCreateRollback,
|
|
26
29
|
validateCreateInputs,
|
|
27
30
|
dirIsEmpty,
|
|
28
31
|
} from "./create-preflight.js";
|
|
@@ -32,7 +35,7 @@ import { createLongRunningBranch } from "./long-running-branch.js";
|
|
|
32
35
|
import { enableE2eForProject } from "./enable-e2e.js";
|
|
33
36
|
import { ensureClientLockfile } from "./client-lockfile.js";
|
|
34
37
|
import { enableInfraForProject } from "./enable-infra.js";
|
|
35
|
-
import { setupRunner } from "./runner-setup.js";
|
|
38
|
+
import { setupRunner, removeRunner } from "./runner-setup.js";
|
|
36
39
|
import { syncCiSecrets, missingCiSecrets } from "../util/ci-secrets.js";
|
|
37
40
|
import { delay } from "../util/delay.js";
|
|
38
41
|
import {
|
|
@@ -291,19 +294,33 @@ export async function createProject(
|
|
|
291
294
|
throw new Error(databricksAuthPrereqMessage(host, auth.reason));
|
|
292
295
|
}
|
|
293
296
|
|
|
294
|
-
// ── GitHub
|
|
295
|
-
//
|
|
296
|
-
//
|
|
297
|
-
//
|
|
298
|
-
//
|
|
297
|
+
// ── GitHub account + requisites precondition (B) ──────────────
|
|
298
|
+
// ONE up-front GitHub preflight, BEFORE any repo / Lakebase project exists, so a
|
|
299
|
+
// missing requisite fails in seconds with a fix instead of mid-create (where it
|
|
300
|
+
// orphans partial artifacts): the active account resolves (else a wrong/absent
|
|
301
|
+
// token 403s LATE at the push), the full required scope set is present (repo +
|
|
302
|
+
// workflow — not just workflow), and the repo name is free. Conservative: notes
|
|
303
|
+
// (owner/org mismatch, invisible/advisory scopes) are surfaced but never block.
|
|
299
304
|
if (useGithub) {
|
|
300
|
-
report("Checking GitHub token
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
305
|
+
report("Checking GitHub account + token requisites...");
|
|
306
|
+
const gh = await checkGitHubPreflight({ owner: input.githubOwner!, repoName: input.projectName });
|
|
307
|
+
for (const w of gh.warnings) {
|
|
308
|
+
warnings.push(w);
|
|
309
|
+
report(`Note: ${w}`);
|
|
304
310
|
}
|
|
311
|
+
if (!gh.ok) throw new Error(gh.reason);
|
|
305
312
|
}
|
|
306
313
|
|
|
314
|
+
// The created-resources ledger (A3): each resource registers its teardown the
|
|
315
|
+
// moment it is created, and a genuine provisioning throw inside the wrapper below
|
|
316
|
+
// rolls back ALL of them in reverse — the GitHub repo, the runner, the local dir,
|
|
317
|
+
// AND the Lakebase project together — leaving a clean "name is free" state (not
|
|
318
|
+
// the old 4-artifact orphan where only the Lakebase project was undone). A
|
|
319
|
+
// push-only failure is caught locally below and is NOT a provisioning throw, so
|
|
320
|
+
// it never triggers a rollback.
|
|
321
|
+
const rollback = createRollbackLedger();
|
|
322
|
+
return await withCreateRollback(rollback, { report }, async (): Promise<CreateProjectResult> => {
|
|
323
|
+
|
|
307
324
|
// ── Step 1+2: GitHub repo + clone, OR local-only setup ────────
|
|
308
325
|
if (useGithub) {
|
|
309
326
|
report("Creating GitHub repository...", fullRepoName);
|
|
@@ -311,6 +328,7 @@ export async function createProject(
|
|
|
311
328
|
private: input.privateRepo !== false,
|
|
312
329
|
description: `Lakebase project: ${input.projectName}`,
|
|
313
330
|
});
|
|
331
|
+
rollback.register(`GitHub repo ${fullRepoName}`, () => deleteRepo(fullRepoName));
|
|
314
332
|
|
|
315
333
|
report("Waiting for GitHub repo to be visible...", fullRepoName);
|
|
316
334
|
const probeDelays = [1000, 2000, 3000, 5000, 8000];
|
|
@@ -349,25 +367,23 @@ export async function createProject(
|
|
|
349
367
|
repoUrl: `https://github.com/${fullRepoName}.git`,
|
|
350
368
|
parentDir: input.parentDir,
|
|
351
369
|
});
|
|
370
|
+
rollback.register(`local project dir ${projectDir}`, () => fs.rmSync(projectDir, { recursive: true, force: true }));
|
|
352
371
|
} else {
|
|
353
372
|
report("Creating local project directory...", projectDir);
|
|
354
373
|
// A pre-existing EMPTY dir is accepted (validated up front); mkdir with
|
|
355
374
|
// recursive is a no-op on it. A non-empty dir was already rejected.
|
|
356
375
|
fs.mkdirSync(projectDir, { recursive: true });
|
|
357
376
|
await gitInit(projectDir);
|
|
377
|
+
rollback.register(`local project dir ${projectDir}`, () => fs.rmSync(projectDir, { recursive: true, force: true }));
|
|
358
378
|
}
|
|
359
379
|
|
|
360
380
|
// ── Step 3: Lakebase project ──────────────────────────────────
|
|
361
381
|
report("Creating Lakebase database (provisioning Postgres)...", lakebaseProjectId);
|
|
362
382
|
await createLakebaseProject({ projectId: lakebaseProjectId, host });
|
|
363
|
-
|
|
364
|
-
//
|
|
365
|
-
//
|
|
366
|
-
|
|
367
|
-
// with rollback context.
|
|
368
|
-
return await withLakebaseRollback(
|
|
369
|
-
{ projectId: lakebaseProjectId, host, report },
|
|
370
|
-
async (): Promise<CreateProjectResult> => {
|
|
383
|
+
// From here on the Lakebase project EXISTS; register its teardown so a later
|
|
384
|
+
// provisioning throw rolls it back (W9) alongside the repo + dir above — a retry
|
|
385
|
+
// with the same name would otherwise collide with the reserved/soft-deleted slug.
|
|
386
|
+
rollback.register(`Lakebase project ${lakebaseProjectId}`, () => deleteLakebaseProject({ projectId: lakebaseProjectId, host }));
|
|
371
387
|
|
|
372
388
|
// ── Step 4: Default branch lookup (non-fatal if not ready yet) ─
|
|
373
389
|
report("Resolving database endpoint...");
|
|
@@ -481,6 +497,11 @@ export async function createProject(
|
|
|
481
497
|
projectName: input.projectName,
|
|
482
498
|
report: (m) => report(m),
|
|
483
499
|
});
|
|
500
|
+
// Registered only after a SUCCESSFUL setup, so a provisioning throw later
|
|
501
|
+
// tears the runner down (stop + deregister + rm dir) alongside the rest.
|
|
502
|
+
rollback.register(`self-hosted runner ${input.projectName}`, () =>
|
|
503
|
+
removeRunner({ fullRepoName, projectName: input.projectName }),
|
|
504
|
+
);
|
|
484
505
|
} catch (err) {
|
|
485
506
|
const msg = err instanceof Error ? err.message : String(err);
|
|
486
507
|
warnings.push(`Runner setup failed: ${msg}`);
|
|
@@ -594,6 +615,25 @@ export async function createProject(
|
|
|
594
615
|
);
|
|
595
616
|
}
|
|
596
617
|
|
|
618
|
+
// ── Step 7g: pre-warm the toolkit so the first push doesn't cold-download mid-hook (A1) ──
|
|
619
|
+
// The scaffolded project's pre-push hook runs `./scripts/lk`, which triggers the
|
|
620
|
+
// one-time cold download of the Consort toolkit (hundreds of npm fetches). If that
|
|
621
|
+
// very first `lk` is the PUSH's hook, the heavy download races the push and the push
|
|
622
|
+
// fails (the cold-download incident). Warming HERE — after the scaffold laid down
|
|
623
|
+
// scripts/lk, before the push — makes the hook find a populated cache. Best-effort
|
|
624
|
+
// with ONE retry: if warming still fails we do NOT block create (the push then
|
|
625
|
+
// cold-downloads itself, exactly as before, and the retriable push below absorbs it).
|
|
626
|
+
if (enableSftdd && useGithub) {
|
|
627
|
+
report("Warming the Consort toolkit (so the first push doesn't cold-download mid-hook)...");
|
|
628
|
+
let warm = warmAndVerifyKit(projectDir);
|
|
629
|
+
if (!warm.ok) warm = warmAndVerifyKit(projectDir);
|
|
630
|
+
if (!warm.ok) {
|
|
631
|
+
const m = kitWarmWarning(projectDir, warm.reason);
|
|
632
|
+
warnings.push(m);
|
|
633
|
+
report(`Note: ${m}`);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
597
637
|
// ── Step 8: Initial commit (+ push when GitHub configured) ────
|
|
598
638
|
const langLabels: Record<string, string> = {
|
|
599
639
|
java: "Java/Spring Boot",
|
|
@@ -622,11 +662,29 @@ export async function createProject(
|
|
|
622
662
|
}
|
|
623
663
|
|
|
624
664
|
report("Creating initial commit...");
|
|
625
|
-
await
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
665
|
+
await commitInitial(projectDir, `Initial project scaffold (${langLabel} + Lakebase)`);
|
|
666
|
+
// The commit is now LOCAL on disk. A push failure after this point is RETRIABLE,
|
|
667
|
+
// NOT a provisioning fault (A2): repo + Lakebase + runner + scaffold all succeeded,
|
|
668
|
+
// so tearing them down for a transient first-push cold download is wrong. Push with
|
|
669
|
+
// ONE retry (the toolkit is cached after the warm above / the first hook run); if it
|
|
670
|
+
// STILL fails, leave every resource intact and print the one-line resume — do NOT
|
|
671
|
+
// throw (which would fire the rollback ledger). A real `workflow`-scope rejection is
|
|
672
|
+
// not transient and IS surfaced as a hard error.
|
|
673
|
+
let pushLanded = !useGithub; // local-only: nothing to push → treat as landed
|
|
674
|
+
if (useGithub) {
|
|
675
|
+
try {
|
|
676
|
+
await pushInitial({ projectDir, attempts: 2 });
|
|
677
|
+
pushLanded = true;
|
|
678
|
+
} catch (err) {
|
|
679
|
+
if (err instanceof WorkflowScopeError) throw err;
|
|
680
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
681
|
+
const m =
|
|
682
|
+
`Provisioning is complete, but the initial push did not land after a retry: ${msg}. ` +
|
|
683
|
+
`The project on disk is fine , finish it with: cd ${projectDir} && git push -u origin main`;
|
|
684
|
+
warnings.push(m);
|
|
685
|
+
report(`WARNING: ${m}`);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
630
688
|
|
|
631
689
|
// ── Step 8b: Long-running tier setup (architectural choice) ───
|
|
632
690
|
// Tier semantics (features are NOT tiers, they are short-lived branches):
|
|
@@ -644,7 +702,17 @@ export async function createProject(
|
|
|
644
702
|
// origin to already have the parent ref (e.g. main, staging).
|
|
645
703
|
// tiers 2/3 with --no-github is rejected up front by validateCreateInputs, so
|
|
646
704
|
// by here useGithub is guaranteed true for any tiers>1 request.
|
|
647
|
-
|
|
705
|
+
// Skip cleanly when the initial push did NOT land (A2): createLongRunningBranch
|
|
706
|
+
// forks off origin/main, which does not exist yet — cutting a tier now would fail.
|
|
707
|
+
// Surface the deferral so the user cuts the tiers after finishing the push.
|
|
708
|
+
if ((tiers === 2 || tiers === 3) && !pushLanded) {
|
|
709
|
+
const m =
|
|
710
|
+
`INCOMPLETE TIERS: you requested ${tiers} tiers, but the initial push hasn't landed, so the ` +
|
|
711
|
+
`tier branches can't fork off origin yet. After you finish the push (above), cut them with ` +
|
|
712
|
+
`\`./scripts/lk lakebase-cut-tier --name staging --fork-from main\`${tiers === 3 ? " and \`--name dev --fork-from staging\`" : ""}.`;
|
|
713
|
+
warnings.push(m);
|
|
714
|
+
report(`WARNING: ${m}`);
|
|
715
|
+
} else if (tiers === 2 || tiers === 3) {
|
|
648
716
|
report(`Cutting staging tier (tiers=${tiers}) via createLongRunningBranch...`);
|
|
649
717
|
try {
|
|
650
718
|
await createLongRunningBranch({
|
|
@@ -712,7 +780,7 @@ export async function createProject(
|
|
|
712
780
|
warnings,
|
|
713
781
|
};
|
|
714
782
|
|
|
715
|
-
} // end
|
|
783
|
+
} // end withCreateRollback closure
|
|
716
784
|
);
|
|
717
785
|
}
|
|
718
786
|
|