@git.zone/cli 6.16.2 → 6.17.0

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/readme.md CHANGED
@@ -186,20 +186,94 @@ Before interactive confirmation or source mutation, a Docker release verifies th
186
186
 
187
187
  The release core is not configurable plumbing. It always follows the same professional release transaction:
188
188
 
189
- 1. Verify the release branch, clean state, and `main` worktree ownership.
189
+ 1. Verify the release branch, clean state, and `main` worktree ownership. A release that builds or packs a commit with a `package.json` also proves here that the source commit carries a `pnpm-lock.yaml` its checkout can install with `--frozen-lockfile`.
190
190
  2. Read `changelog.md` `## Pending` entries and infer or accept a semver bump, raised to `release.versionFloor` when that is higher.
191
191
  3. Run configured tests.
192
192
  4. With `--merge`, fast-forward and lease-push `main` before release metadata is created.
193
193
  5. Update version files and baked commit info.
194
194
  6. Move pending changelog entries into the new version section.
195
195
  7. Create the local release commit and tag on `main`.
196
- 8. Run the configured release build, require a clean tree, and revalidate the release checkout.
197
- 9. When npm is selected, pack it once into an exact tarball.
196
+ 8. Create a disposable detached checkout of that release commit, install its locked dependencies when the commit carries a `package.json`, and run the configured release build there. An active Docker target additionally builds the release worktree its qualification reads.
197
+ 9. When npm is selected, pack it once into an exact tarball from that checkout.
198
198
  10. Atomically install a durable journal before final publication. Root npm releases use journal schema 1; Docker releases use schema 2; tspublish component releases use schema 3 in the same storage tree.
199
199
  11. For schema 2, run the project-local tSDocker qualification build and configured image tests, then durably record the candidate digest graph and complete ordered promotion set.
200
200
  12. Publish and verify Git, then each npm registry, then each Docker destination. Remove only the exact qualified candidate after every destination is verified, or after a terminal qualification destination conflict before Git/npm publication.
201
201
  13. Remove the test artifacts tstest wrote, so a machine does not accumulate test output release after release. This runs only after a successful publication, leaving the logs in place when a release fails. It is skipped when the project has no tstest installed, and a project opts out with `{"@git.zone/tstest": {"cleanup": {"onRelease": false}}}` in `.smartconfig.json`. See the tstest readme for what it removes; snapshots are kept.
202
202
 
203
+ ### The release builds and packs the release commit
204
+
205
+ A release publishes what its release commit contains. After the commit and tag
206
+ exist, GitZone creates a disposable detached worktree of that exact commit under
207
+ the system temporary directory, runs `pnpm install --frozen-lockfile` in it when
208
+ that commit carries a `package.json`, and runs the configured release build and
209
+ `pnpm pack` there. Gitea assets are frozen from the same checkout. The checkout
210
+ must still be the exact commit with a clean tree before and after packing, and it
211
+ is removed on success and on failure. Recovery (`gitzone release recover`) has
212
+ always worked this way; every release now does.
213
+
214
+ Consequences worth knowing before upgrading:
215
+
216
+ - The release build no longer refreshes `dist_*` in your working folder for
217
+ npm-only, Git-only, and Gitea-asset releases. Run `pnpm build` yourself when
218
+ you want fresh local output.
219
+ - A build that depends on untracked or ignored local files now fails instead of
220
+ publishing output nobody else can reproduce.
221
+ - Untracked files that match the `files` globs can no longer reach the tarball.
222
+ - Unreadable paths anywhere in the working folder, such as container-owned
223
+ service data under `.nogit/`, no longer break packing. pnpm walks the whole
224
+ project tree before applying `files`, and the checkout does not contain that
225
+ data.
226
+ - A release commit that carries a `package.json` must install from its own
227
+ committed lockfile. Preflight proves that before anything is created: the
228
+ source commit has to carry a tracked `pnpm-lock.yaml`, and `pnpm install
229
+ --frozen-lockfile --lockfile-only` — pnpm's no-install, no-write form of the
230
+ same check — has to accept it. A lockfile that is missing, ignored, or
231
+ outdated stops the release there, with no release commit, no tag, and nothing
232
+ pushed. Commit the lockfile, or run `pnpm install` and commit it, then release
233
+ again. The version bump only changes `version`, which never changes a
234
+ dependency specifier, so a lockfile accepted in preflight is still accepted in
235
+ the release commit. A project with both a `package.json` and a `deno.json` is
236
+ an npm project here and owes the same proof.
237
+ - A Deno-only project — a commit with a `deno.json` and no `package.json` —
238
+ neither needs a pnpm lockfile nor installs anything: its checkout runs the
239
+ configured build and test commands against the committed tree, and pinning
240
+ dependencies stays the project's `deno.lock` or import map. The plan of such a
241
+ release has no `preflight.lockfile` step. Preflight and the checkout both read
242
+ the release commit rather than the working folder, so an ignored
243
+ `package.json` never makes a release demand a lockfile its checkout would not
244
+ install; in that one case the plan, which reads the working folder, still
245
+ lists the step, and the step then does nothing.
246
+ - The checkout holds only committed files, so a gitignored project-level
247
+ `.npmrc` is not in it. A project that authenticates private dependencies
248
+ through such a file now fails its checkout install after the local commit and
249
+ tag exist. Authenticate at user level instead: `pnpm npm login
250
+ --registry=<registry>` — what `gitzone config doctor` suggests as well —
251
+ writes `~/.npmrc`, and the checkout reads that.
252
+ - An install that fails in the checkout for an environmental reason — an
253
+ unreachable registry, a missing credential, an unusable store — stops the
254
+ release with the local release commit and tag created, nothing pushed, and no
255
+ release journal written. Fix the environment, then: a release with a Git
256
+ target plus a root-npm and/or Docker target continues with `gitzone release
257
+ recover <version>`, which prepares and publishes that exact tagged commit
258
+ without moving any ref. Other configurations — tspublish component releases,
259
+ Gitea-asset releases, and single-target releases — have no recovery path,
260
+ because nothing was published: delete the tag and drop the release commit
261
+ (`git tag -d v<version>` and `git reset --hard HEAD^` on `main`), then release
262
+ again. Confirm first that `HEAD` is the release commit — `git log -1
263
+ --format=%s` prints `v<version>` — so that a commit made on top of it is never
264
+ dropped.
265
+ - The `--plan` step list names the isolated work: `preflight.lockfile` for a
266
+ project with a `package.json`, then `core.releaseCheckout`,
267
+ `core.releaseCheckout.build`, then `core.packNpmArtifact`.
268
+
269
+ An active `docker` target additionally runs the build in the release worktree,
270
+ as before, and the plan shows that step as `core.build`. tSDocker binds
271
+ qualification to the project directory: the journaled request carries that `cwd`
272
+ and a project identity hash derived from it, so the image is still built from the
273
+ working folder and untracked files there can still reach an image. Moving Docker
274
+ qualification to the release commit belongs to `@git.zone/tsdocker` and is not
275
+ part of this release.
276
+
203
277
  Targets decide what happens after that:
204
278
 
205
279
  | Target | What it does |
@@ -566,11 +640,20 @@ are not supported.
566
640
  The first attempt records the exact refs, destination and resolved workflow under
567
641
  the common Git directory in `gitzone/releases/v1/v<version>.preparation.json`.
568
642
  For Docker, this binding also includes the exact canonical qualification request.
569
- Retries must match that binding. Recovery creates a disposable detached worktree
570
- from the tagged commit, runs `pnpm install --frozen-lockfile`, and runs the configured
571
- tests and build before packing. Ignored runtime data and local project secrets are
572
- not copied. A build that depends on those files must be made reproducible through
573
- the project's normal configuration before it can recover.
643
+ Retries must match that binding, and a binding written by another GitZone version
644
+ does not match, because the resolved workflow contains the release plan: when
645
+ `Release recovery identity or configuration differs from its original
646
+ preparation.` appears on the first recovery after upgrading from 6.16.3 or
647
+ earlier, remove that `<git-common-dir>/gitzone/releases/v1/v<version>.preparation.json`
648
+ file and recover again. Recovery uses the same disposable checkout every
649
+ release uses: a detached worktree of the tagged commit, `pnpm install
650
+ --frozen-lockfile`, then the configured tests and build before packing. Recovery
651
+ always installs, because it matches the release identity against the root
652
+ `package.json` and is therefore available only to projects that have one.
653
+ Recovery runs the configured tests there because no preflight ran ahead of it. Ignored
654
+ runtime data and local project secrets are not copied. A build that depends on
655
+ those files must be made reproducible through the project's normal configuration
656
+ before it can recover.
574
657
 
575
658
  Prepared npm artifacts are installed through the normal journal API. Docker
576
659
  recovery verifies the project-local tSDocker capabilities and configuration before
@@ -1067,10 +1150,26 @@ contents. Native deletion is attempted there. If container-owned files remain,
1067
1150
  GitZone uses a short-lived root container scoped to that quarantine; Docker's
1068
1151
  `--privileged` mode is not used. The helper reserves one deterministic name per
1069
1152
  bind target, carries a random invocation label, is created stopped, and is
1070
- inspected by immutable ID before execution or cleanup. Old stopped helpers can
1071
- be recovered only after their complete runtime envelope, bind target, age, and
1072
- immutable ID are proven; running, fresh, or noncanonical occupants block the
1073
- operation. If interruption or helper failure leaves bytes, the persisted intent
1153
+ inspected by immutable ID before execution or cleanup. Old stopped helpers,
1154
+ whether still `created` or already `exited`, can be recovered only after their
1155
+ complete runtime envelope, bind target, age, and immutable ID are proven;
1156
+ running, fresh, or noncanonical occupants block the operation.
1157
+
1158
+ A helper carries exactly one read-write bind of its target. Service images such
1159
+ as `mongo:7.0` additionally declare their own `VOLUME` destinations, for which
1160
+ Docker attaches anonymous volumes GitZone never requested; those are accepted
1161
+ only where Docker proves them image-declared and anonymous, namely the local
1162
+ driver, a random 64-character volume name, and a destination the container's own
1163
+ image configuration declares outside the bind destination. A named volume, a
1164
+ second bind, a read-only target bind, or a volume at any other destination
1165
+ leaves the helper unproven and blocks the operation. Whenever a helper is proven
1166
+ — after a successful run, when an old helper is reclaimed, and on the rollback
1167
+ path of a failed run — it is removed together with its anonymous volumes; a
1168
+ named volume is never removed this way. A helper whose closing inspection
1169
+ refuses it or times out is left in place and reported as cleanup that could not
1170
+ be confirmed; it keeps blocking the operation until a later run proves it.
1171
+
1172
+ If interruption or helper failure leaves bytes, the persisted intent
1074
1173
  lets the next `clean` or `prune --apply` resume the same quarantine. A partial
1075
1174
  failure therefore never leaves a corrupt directory at the canonical service
1076
1175
  path. Startup refuses to create fresh service data while such an intent remains.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@git.zone/cli',
6
- version: '6.16.2',
6
+ version: '6.17.0',
7
7
  description: 'A comprehensive CLI tool for enhancing and managing local development workflows with gitzone utilities, focusing on project setup, version control, code formatting, and template management.'
8
8
  }
@@ -1,6 +1,11 @@
1
1
  import { getCliConfigValue } from "./helpers.smartconfig.js";
2
2
  import { getProcessUserArgv } from "./helpers.climode.js";
3
3
  import { shouldCleanTestArtifactsOnRelease } from "./helpers.tstest.js";
4
+ import {
5
+ detectProjectType,
6
+ projectTypeHasPackageJson,
7
+ type ProjectType,
8
+ } from "./mod_commit/mod.helpers.js";
4
9
  import { parseReleaseVersionFloor } from "./mod_release/helpers.releaseversion.js";
5
10
  import { defaultNpmVerificationWindowMinutes } from "./mod_release/helpers.npmartifact.js";
6
11
 
@@ -193,6 +198,8 @@ export interface IResolvedCommitWorkflow {
193
198
  export interface IResolvedReleaseWorkflow {
194
199
  confirmation: TConfirmationMode;
195
200
  plan: string[];
201
+ /** Version files and dependency installation the project owns. */
202
+ projectType: ProjectType;
196
203
  targets: TReleaseTarget[];
197
204
  runTests: boolean;
198
205
  runBuild: boolean;
@@ -631,20 +638,49 @@ const releaseTargetOrder: TReleaseTarget[] = [
631
638
  "docker",
632
639
  ];
633
640
 
641
+ /**
642
+ * The release build and every release artifact are produced in a disposable
643
+ * checkout of the release commit, so a release that neither builds nor packs
644
+ * anything has nothing to isolate and keeps working only from the release
645
+ * worktree.
646
+ */
647
+ export const releaseNeedsIsolatedCheckout = (
648
+ workflowArg: Pick<IResolvedReleaseWorkflow, "runBuild" | "targets">,
649
+ ): boolean =>
650
+ workflowArg.runBuild ||
651
+ workflowArg.targets.includes("npm") ||
652
+ workflowArg.targets.includes("giteaAssets");
653
+
634
654
  const buildReleasePlan = (options: {
635
655
  mergeRequested: boolean;
636
656
  runTests: boolean;
637
657
  runBuild: boolean;
658
+ projectType: ProjectType;
638
659
  targets: TReleaseTarget[];
639
660
  cleanTestArtifacts: boolean;
640
661
  }): string[] => {
641
662
  const plan: string[] = ["preflight.branch", "preflight.cleanTree"];
663
+ // Only a checkout with a package.json installs from a committed pnpm
664
+ // lockfile, so only such a release proves that install before it creates its
665
+ // commit and tag. A Deno-only project has no pnpm lockfile to prove.
666
+ if (
667
+ releaseNeedsIsolatedCheckout(options) &&
668
+ projectTypeHasPackageJson(options.projectType)
669
+ )
670
+ plan.push("preflight.lockfile");
642
671
  if (options.runTests) plan.push("preflight.test");
643
672
  if (options.mergeRequested) {
644
673
  plan.push("integration.main", "integration.pushMain");
645
674
  }
646
675
  plan.push("core.version", "core.changelog", "core.commit", "core.tag");
647
- if (options.runBuild) plan.push("core.build");
676
+ // tSDocker keys qualification to the project directory, so an active Docker
677
+ // target keeps the release worktree build it reads.
678
+ if (options.runBuild && options.targets.includes("docker"))
679
+ plan.push("core.build");
680
+ if (releaseNeedsIsolatedCheckout(options)) {
681
+ plan.push("core.releaseCheckout");
682
+ if (options.runBuild) plan.push("core.releaseCheckout.build");
683
+ }
648
684
  if (options.targets.includes("npm")) plan.push("core.packNpmArtifact");
649
685
  if (options.targets.includes("giteaAssets"))
650
686
  plan.push("core.freezeGiteaAssets");
@@ -902,6 +938,14 @@ export const resolveReleaseWorkflow = async (
902
938
  const cleanTestArtifacts = await shouldCleanTestArtifactsOnRelease(
903
939
  process.cwd(),
904
940
  );
941
+ // The plan names `preflight.lockfile` when the release runs it, and the
942
+ // release core has to know which version files it owns. The release worktree
943
+ // is clean before anything is created, so the working folder answers both
944
+ // questions the way the release commit does for every tracked manifest; the
945
+ // preflight itself reads the commit. An ignored `package.json` in the working
946
+ // folder of a Deno-only commit is the one case where the plan lists the step
947
+ // and the step then does nothing.
948
+ const projectType = await detectProjectType(process.cwd());
905
949
 
906
950
  return {
907
951
  confirmation,
@@ -909,9 +953,11 @@ export const resolveReleaseWorkflow = async (
909
953
  mergeRequested,
910
954
  runTests,
911
955
  runBuild,
956
+ projectType,
912
957
  targets,
913
958
  cleanTestArtifacts,
914
959
  }),
960
+ projectType,
915
961
  targets,
916
962
  runTests,
917
963
  runBuild,
@@ -58,6 +58,14 @@ export async function detectProjectType(cwdArg = paths.cwd): Promise<ProjectType
58
58
  }
59
59
  }
60
60
 
61
+ /**
62
+ * A pnpm lockfile, `pnpm install` and `pnpm pack` belong to a project's
63
+ * package.json, so every npm-shaped decision asks this one question.
64
+ */
65
+ export const projectTypeHasPackageJson = (
66
+ projectTypeArg: ProjectType,
67
+ ): boolean => projectTypeArg === 'npm' || projectTypeArg === 'both';
68
+
61
69
  /**
62
70
  * Parses a semantic version string and bumps it according to the version type
63
71
  * @param currentVersion Current version string (e.g., "1.2.3")
@@ -1,6 +1,12 @@
1
1
  import * as plugins from "./mod.plugins.js";
2
2
  import type { IResolvedReleaseWorkflow } from "../helpers.workflow.js";
3
+ import { logger } from "../gitzone.logging.js";
3
4
  import { readPendingChangelog } from "../helpers.changelog.js";
5
+ import {
6
+ detectProjectType,
7
+ projectTypeHasPackageJson,
8
+ type ProjectType,
9
+ } from "../mod_commit/mod.helpers.js";
4
10
  import { InterProcessLock } from "../mod_services/classes.interprocesslock.js";
5
11
  import { ReleaseJournalStore } from "./classes.releasejournal.js";
6
12
  import {
@@ -32,12 +38,12 @@ export interface IReleasePreparationRecovery {
32
38
  dockerRequest?: IReleaseQualificationRequest;
33
39
  }
34
40
 
35
- const git = async (
36
- options: IReleasePreparationRecovery,
41
+ const releaseGit = async (
42
+ smartshell: plugins.smartshell.Smartshell,
37
43
  args: string[],
38
- cwd = options.branch.sourceCwd,
44
+ cwd: string,
39
45
  ) => {
40
- const result = await options.smartshell.execSpawn("git", args, {
46
+ const result = await smartshell.execSpawn("git", args, {
41
47
  cwd,
42
48
  env: releaseGitEnv,
43
49
  silent: true,
@@ -45,10 +51,16 @@ const git = async (
45
51
  timeoutKillGraceMs: 5_000,
46
52
  });
47
53
  if (result.exitCode !== 0)
48
- throw new Error(`Release recovery Git validation failed: ${args[0]}.`);
54
+ throw new Error(`Release Git validation failed: ${args[0]}.`);
49
55
  return result.stdout.trim();
50
56
  };
51
57
 
58
+ const git = async (
59
+ options: IReleasePreparationRecovery,
60
+ args: string[],
61
+ cwd = options.branch.sourceCwd,
62
+ ) => releaseGit(options.smartshell, args, cwd);
63
+
52
64
  export const assertPackageReleaseRecovery = async (
53
65
  options: IReleasePreparationRecovery,
54
66
  ): Promise<string> => {
@@ -211,6 +223,211 @@ const bindPreparation = async (
211
223
  }
212
224
  };
213
225
 
226
+ const releaseLockfileName = "pnpm-lock.yaml";
227
+
228
+ /** The commit the release commit is built on top of, and its clean worktree. */
229
+ export interface IReleaseSourceCommit {
230
+ smartshell: plugins.smartshell.Smartshell;
231
+ /** Clean source worktree the release is prepared from. */
232
+ cwd: string;
233
+ /** Commit the release commit is built on top of. */
234
+ sourceOid: string;
235
+ }
236
+
237
+ const commitCarriesBlob = async (
238
+ options: IReleaseSourceCommit,
239
+ fileArg: string,
240
+ ): Promise<boolean> => {
241
+ const result = await options.smartshell.execSpawn(
242
+ "git",
243
+ ["cat-file", "-t", `${options.sourceOid}:./${fileArg}`],
244
+ {
245
+ cwd: options.cwd,
246
+ env: releaseGitEnv,
247
+ silent: true,
248
+ timeout: 60_000,
249
+ timeoutKillGraceMs: 5_000,
250
+ },
251
+ );
252
+ return result.exitCode === 0 && result.stdout.trim() === "blob";
253
+ };
254
+
255
+ /**
256
+ * The release checkout holds the release commit, so what it needs is decided by
257
+ * what that commit tracks rather than by what the working folder happens to
258
+ * contain: an ignored package.json or deno.json is not part of the release, and
259
+ * `detectProjectType` would still report it. For every tracked manifest both
260
+ * answers agree, because a release requires a clean worktree.
261
+ */
262
+ export const detectReleaseCommitProjectType = async (
263
+ options: IReleaseSourceCommit,
264
+ ): Promise<ProjectType> => {
265
+ const hasPackageJson = await commitCarriesBlob(options, "package.json");
266
+ const hasDenoJson = await commitCarriesBlob(options, "deno.json");
267
+ if (hasPackageJson && hasDenoJson) return "both";
268
+ if (hasPackageJson) return "npm";
269
+ if (hasDenoJson) return "deno";
270
+ throw new Error(
271
+ `Commit ${options.sourceOid} tracks neither package.json nor deno.json, so it carries no release version file.`,
272
+ );
273
+ };
274
+
275
+ /**
276
+ * The isolated release checkout of a project with a package.json installs with
277
+ * `pnpm install --frozen-lockfile`, so a lockfile that the release commit does
278
+ * not carry, or that no longer matches its manifest, would fail a release that
279
+ * already created its commit and tag. Preflight proves both before anything is
280
+ * created. A Deno-only commit installs nothing, so it is asked for nothing.
281
+ *
282
+ * The release commit only adds the version bump, the baked commit info, and the
283
+ * changelog section on top of the source commit, and a version change never
284
+ * changes a dependency specifier, so what installs here installs there.
285
+ */
286
+ export const assertReleaseCheckoutInstallable = async (
287
+ options: IReleaseSourceCommit,
288
+ ): Promise<void> => {
289
+ const projectType = await detectReleaseCommitProjectType(options);
290
+ if (!projectTypeHasPackageJson(projectType)) {
291
+ logger.log(
292
+ "info",
293
+ "The release commit carries no package.json, so its checkout runs the configured commands against the committed tree without installing npm dependencies",
294
+ );
295
+ return;
296
+ }
297
+ logger.log(
298
+ "info",
299
+ "Verifying the committed lockfile installs the release checkout",
300
+ );
301
+ const tracked = await commitCarriesBlob(options, releaseLockfileName);
302
+ if (!tracked) {
303
+ throw new Error(
304
+ `The release builds and packs a checkout of its release commit and installs that checkout with \`pnpm install --frozen-lockfile\`, but commit ${options.sourceOid} carries no ${releaseLockfileName}. Commit the lockfile — it must not be ignored — and release again.`,
305
+ );
306
+ }
307
+ // `--frozen-lockfile --lockfile-only` is pnpm's no-install, no-write form of
308
+ // this exact check: an up-to-date lockfile exits 0 without touching the
309
+ // lockfile or node_modules, a stale one exits 1 with ERR_PNPM_OUTDATED_LOCKFILE
310
+ // before resolving anything. `--dry-run` cannot replace it: it prints the
311
+ // difference and still exits 0.
312
+ const frozen = await options.smartshell.execSpawn(
313
+ "pnpm",
314
+ ["install", "--frozen-lockfile", "--lockfile-only"],
315
+ {
316
+ cwd: options.cwd,
317
+ silent: true,
318
+ timeout: 5 * 60_000,
319
+ timeoutKillGraceMs: 5_000,
320
+ },
321
+ );
322
+ if (frozen.exitCode !== 0 || frozen.timedOut) {
323
+ throw new Error(
324
+ `\`pnpm install --frozen-lockfile --lockfile-only\` rejects the committed ${releaseLockfileName}, so the release checkout could not install it. Run \`pnpm install\`, commit the updated lockfile, and release again.\n${frozen.combinedOutput.trim()}`,
325
+ );
326
+ }
327
+ };
328
+
329
+ export interface IIsolatedReleaseCheckout {
330
+ /** Disposable detached worktree that holds exactly the release commit. */
331
+ path: string;
332
+ /** Re-assert that the checkout still is that exact commit, unmodified. */
333
+ assertExact: () => Promise<void>;
334
+ }
335
+
336
+ export interface IIsolatedReleaseCheckoutOptions {
337
+ smartshell: plugins.smartshell.Smartshell;
338
+ /** Repository that owns the release commit; the worktree registers there. */
339
+ repositoryCwd: string;
340
+ /** Exact release commit the checkout must contain. */
341
+ mainOid: string;
342
+ /** Configured test command, when the checkout must run tests. */
343
+ testCommand?: string;
344
+ /** Configured build command, when the checkout must build. */
345
+ buildCommand?: string;
346
+ }
347
+
348
+ /**
349
+ * A release publishes what its release commit contains, so the release build
350
+ * and every artifact are produced in a disposable detached checkout of that
351
+ * commit instead of the user's working folder. Untracked files, ignored runtime
352
+ * data, and local project secrets are not part of it, so they can neither reach
353
+ * an artifact nor break packing. The checkout is removed on success and on
354
+ * failure.
355
+ */
356
+ export const withIsolatedReleaseCheckout = async <T>(
357
+ options: IIsolatedReleaseCheckoutOptions,
358
+ use: (checkout: IIsolatedReleaseCheckout) => Promise<T>,
359
+ ): Promise<T> => {
360
+ const root = await plugins.fs.mkdtemp(
361
+ plugins.path.join(plugins.os.tmpdir(), "gitzone-release-source-"),
362
+ );
363
+ const checkout = plugins.path.join(root, "source");
364
+ const assertExact = async () => {
365
+ if (
366
+ (await releaseGit(
367
+ options.smartshell,
368
+ ["rev-parse", "HEAD"],
369
+ checkout,
370
+ )) !== options.mainOid ||
371
+ (await releaseGit(
372
+ options.smartshell,
373
+ ["status", "--porcelain", "--untracked-files=all"],
374
+ checkout,
375
+ ))
376
+ ) {
377
+ throw new Error(
378
+ "The release checkout no longer holds the exact release commit. Aborting release.",
379
+ );
380
+ }
381
+ };
382
+ let added = false;
383
+ try {
384
+ console.log(
385
+ `\nPreparing the release checkout of ${options.mainOid} at ${checkout}`,
386
+ );
387
+ await releaseGit(
388
+ options.smartshell,
389
+ ["worktree", "add", "--detach", checkout, options.mainOid],
390
+ options.repositoryCwd,
391
+ );
392
+ added = true;
393
+ // The checkout is the release commit, so its own tree decides whether npm
394
+ // dependencies are installed. A Deno-only commit carries no package.json
395
+ // and no pnpm lockfile: its configured commands run against the committed
396
+ // tree, and pinning dependencies is the project's deno.lock or import map.
397
+ if (projectTypeHasPackageJson(await detectProjectType(checkout))) {
398
+ const install = await options.smartshell.execSpawn(
399
+ "pnpm",
400
+ ["install", "--frozen-lockfile"],
401
+ {
402
+ cwd: checkout,
403
+ timeout: 10 * 60_000,
404
+ timeoutKillGraceMs: 5_000,
405
+ },
406
+ );
407
+ if (install.exitCode !== 0)
408
+ throw new Error("Release checkout dependency installation failed.");
409
+ }
410
+ if (options.testCommand)
411
+ await run(options.smartshell, checkout, options.testCommand, "tests");
412
+ if (options.buildCommand)
413
+ await run(options.smartshell, checkout, options.buildCommand, "build");
414
+ await assertExact();
415
+ const result = await use({ path: checkout, assertExact });
416
+ await assertExact();
417
+ return result;
418
+ } finally {
419
+ // This path is a uniquely owned disposable checkout, never the user's
420
+ // source tree or runtime data. Keep registration evidence if cleanup fails.
421
+ if (added)
422
+ await releaseGit(
423
+ options.smartshell,
424
+ ["worktree", "remove", "--force", checkout],
425
+ options.repositoryCwd,
426
+ );
427
+ await plugins.fs.rm(root, { recursive: true, force: true });
428
+ }
429
+ };
430
+
214
431
  /** Build and seal one unpublished, already tagged package without changing refs. */
215
432
  export const withReleasePreparationRecovery = async <T>(
216
433
  options: IReleasePreparationRecovery,
@@ -243,76 +460,36 @@ export const withReleasePreparationRecovery = async <T>(
243
460
  `${directory}.preparation.json`,
244
461
  `${canonicalReleaseJson(preparationBinding(options))}\n`,
245
462
  );
246
- const root = await plugins.fs.mkdtemp(
247
- plugins.path.join(plugins.os.tmpdir(), "gitzone-release-prepare-"),
463
+ return withIsolatedReleaseCheckout(
464
+ {
465
+ smartshell: options.smartshell,
466
+ repositoryCwd: options.branch.sourceCwd,
467
+ mainOid: options.refs.mainOid,
468
+ // Recovery has no preflight run behind it, so it runs the configured
469
+ // checks itself.
470
+ ...(options.workflow.runTests
471
+ ? { testCommand: options.workflow.testCommand }
472
+ : {}),
473
+ ...(options.workflow.runBuild
474
+ ? { buildCommand: options.workflow.buildCommand }
475
+ : {}),
476
+ },
477
+ async (checkout) => {
478
+ await ensureState();
479
+ return prepare(checkout.path, checkout.assertExact);
480
+ },
248
481
  );
249
- const checkout = plugins.path.join(root, "source");
250
- let added = false;
251
- try {
252
- await git(options, [
253
- "worktree",
254
- "add",
255
- "--detach",
256
- checkout,
257
- options.refs.mainOid,
258
- ]);
259
- added = true;
260
- const install = await options.smartshell.execSpawn(
261
- "pnpm",
262
- ["install", "--frozen-lockfile"],
263
- {
264
- cwd: checkout,
265
- timeout: 10 * 60_000,
266
- timeoutKillGraceMs: 5_000,
267
- },
268
- );
269
- if (install.exitCode !== 0)
270
- throw new Error("Release recovery dependency installation failed.");
271
- if (options.workflow.runTests)
272
- await run(options, checkout, options.workflow.testCommand, "tests");
273
- if (options.workflow.runBuild)
274
- await run(options, checkout, options.workflow.buildCommand, "build");
275
- await assertCheckout(options, checkout);
276
- await ensureState();
277
- const result = await prepare(checkout, () =>
278
- assertCheckout(options, checkout),
279
- );
280
- await assertCheckout(options, checkout);
281
- return result;
282
- } finally {
283
- // This path is a uniquely owned disposable checkout, never the user's
284
- // source tree or runtime data. Keep registration evidence if cleanup fails.
285
- if (added)
286
- await git(options, ["worktree", "remove", "--force", checkout]);
287
- await plugins.fs.rm(root, { recursive: true, force: true });
288
- }
289
482
  });
290
483
  };
291
484
 
292
485
  const run = async (
293
- options: IReleasePreparationRecovery,
486
+ smartshell: plugins.smartshell.Smartshell,
294
487
  cwd: string,
295
488
  command: string,
296
489
  phase: string,
297
490
  ) => {
298
- const result = await options.smartshell.exec(command, { cwd });
491
+ console.log(`\nRunning the release ${phase} in the release checkout`);
492
+ const result = await smartshell.exec(command, { cwd });
299
493
  if (result.exitCode !== 0)
300
- throw new Error(`Release recovery ${phase} failed.`);
301
- };
302
-
303
- const assertCheckout = async (
304
- options: IReleasePreparationRecovery,
305
- checkout: string,
306
- ) => {
307
- if (
308
- (await git(options, ["rev-parse", "HEAD"], checkout)) !==
309
- options.refs.mainOid ||
310
- (await git(
311
- options,
312
- ["status", "--porcelain", "--untracked-files=all"],
313
- checkout,
314
- ))
315
- ) {
316
- throw new Error("Release recovery build changed its exact tracked source.");
317
- }
494
+ throw new Error(`Release ${phase} failed in the release checkout.`);
318
495
  };