@intentius/chant 0.124.103 → 0.124.104

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.
Files changed (67) hide show
  1. package/dist/audit/secrets.d.ts +6 -0
  2. package/dist/audit/secrets.js +9 -2
  3. package/dist/cli/commands/import-index.d.ts +15 -0
  4. package/dist/cli/commands/import-index.js +37 -3
  5. package/dist/cli/handlers/lifecycle.js +6 -0
  6. package/dist/cli/handlers/release-config.d.ts +15 -0
  7. package/dist/cli/handlers/release-config.js +58 -0
  8. package/dist/cli/handlers/release.js +36 -3
  9. package/dist/cli/main.js +12 -2
  10. package/dist/cli/parse-args.js +7 -0
  11. package/dist/cli/registry.d.ts +2 -0
  12. package/dist/cli/release-commands/cut.js +3 -0
  13. package/dist/config-import.js +26 -4
  14. package/dist/config.d.ts +14 -0
  15. package/dist/config.js +4 -0
  16. package/dist/floor-table.data.js +7 -6
  17. package/dist/floor-table.js +3 -1
  18. package/dist/graph-refs.d.ts +9 -0
  19. package/dist/graph-refs.js +9 -7
  20. package/dist/lifecycle/cloud-index.d.ts +6 -0
  21. package/dist/lifecycle/cloud-index.js +32 -5
  22. package/dist/lifecycle/identity-match.d.ts +18 -2
  23. package/dist/lifecycle/identity-match.js +10 -5
  24. package/dist/lifecycle/index-drift.d.ts +13 -0
  25. package/dist/lifecycle/index-drift.js +21 -3
  26. package/dist/lifecycle/index-import.d.ts +15 -0
  27. package/dist/lifecycle/index-import.js +25 -2
  28. package/dist/lifecycle/index-join.d.ts +1 -1
  29. package/dist/lifecycle/index-join.js +1 -1
  30. package/dist/lifecycle/publish-declaration.d.ts +6 -0
  31. package/dist/lifecycle/publish-declaration.js +18 -1
  32. package/dist/lifecycle/publish-forge.d.ts +2 -0
  33. package/dist/lifecycle/publish-forge.js +3 -1
  34. package/dist/lifecycle/publish-oci.d.ts +27 -0
  35. package/dist/lifecycle/publish-oci.js +63 -8
  36. package/dist/lifecycle/release-changelog.d.ts +18 -5
  37. package/dist/lifecycle/release-changelog.js +22 -10
  38. package/dist/lifecycle/release-cut.d.ts +13 -1
  39. package/dist/lifecycle/release-cut.js +3 -0
  40. package/dist/lifecycle/release-images.d.ts +32 -2
  41. package/dist/lifecycle/release-images.js +70 -2
  42. package/dist/lifecycle/release-init-goreleaser-images.d.ts +21 -0
  43. package/dist/lifecycle/release-init-goreleaser-images.js +160 -0
  44. package/dist/lifecycle/release-init.d.ts +22 -0
  45. package/dist/lifecycle/release-init.js +86 -7
  46. package/dist/local-chant.d.ts +3 -0
  47. package/dist/local-chant.js +28 -2
  48. package/dist/release-floors.d.ts +10 -6
  49. package/dist/release-floors.js +10 -6
  50. package/dist/ts-loader.d.ts +12 -3
  51. package/dist/ts-loader.js +27 -11
  52. package/dist/wave-runtime.mjs +291 -290
  53. package/dist/workspace/catalog-edges.d.ts +22 -0
  54. package/dist/workspace/catalog-edges.js +23 -0
  55. package/dist/workspace/release-steps/goreleaser.d.ts +6 -3
  56. package/dist/workspace/release-steps/goreleaser.js +12 -6
  57. package/dist/workspace/release-toolchains.d.ts +6 -0
  58. package/dist/workspace/release-toolchains.js +8 -0
  59. package/dist/workspace/release-train-workflow.d.ts +18 -0
  60. package/dist/workspace/release-train-workflow.js +135 -7
  61. package/dist/workspace/release-train.js +1 -1
  62. package/dist/workspace/release-workflow.d.ts +26 -0
  63. package/dist/workspace/release-workflow.js +60 -12
  64. package/dist/workspace/train-artifacts.js +3 -4
  65. package/dist/workspace/train-cut.d.ts +22 -1
  66. package/dist/workspace/train-cut.js +78 -14
  67. package/package.json +2 -2
@@ -53,6 +53,8 @@ import { bytesDigest, checkReleaseDigest, fileDigest, isDir, memberFile, publish
53
53
  import { trainName, waitUntilServed } from "./publish-train-names.js";
54
54
  import { PublishTargetError } from "./release-publish.js";
55
55
  import { prereleaseOf } from "./release-prerelease.js";
56
+ /** The first chant whose oci target takes `platformTags`, a tag for each platform's image in the index (#5269). */
57
+ export const OCI_PLATFORM_TAGS_FLOOR = "0.124.104";
56
58
  const INDEX_TYPES = new Set(["application/vnd.oci.image.index.v1+json", "application/vnd.docker.distribution.manifest.list.v2+json"]);
57
59
  export function parseRepository(repository) {
58
60
  const parts = repository.split("/");
@@ -410,12 +412,49 @@ export function referrerManifest(a, subject) {
410
412
  };
411
413
  return new Uint8Array(Buffer.from(JSON.stringify(manifest)));
412
414
  }
415
+ /**
416
+ * The tag of each platform's image (#5269): `platformTags` with `{label}`,
417
+ * `{version}`, `{os}` and `{arch}` (the architecture and its variant, `armv7`) filled in
418
+ * for each image of the layout's index, from the index entry's platform or
419
+ * else the image's config. None for a release with no label. Two images
420
+ * that would take one tag are refused.
421
+ */
422
+ export function ociPlatformTags(decl, label, manifests, configPlatform = () => undefined) {
423
+ if (!decl.platformTags || label === null)
424
+ return [];
425
+ const out = [];
426
+ const taken = new Map();
427
+ for (const m of manifests) {
428
+ const p = m.platform ?? configPlatform(m.digest);
429
+ if (!p?.architecture || p.architecture === "unknown")
430
+ continue;
431
+ const arch = `${p.architecture}${p.variant ?? ""}`;
432
+ for (const t of decl.platformTags) {
433
+ const tag = fillTag(t, label).split("{arch}").join(arch).split("{os}").join(p.os ?? "");
434
+ const other = taken.get(tag);
435
+ if (other !== undefined && other !== m.digest) {
436
+ throw new PublishTargetError("publish-oci-platform-tag-taken", `${decl.image} holds two images that platformTags would both tag ${tag}`, "Name {os} in platformTags as well, or build one image per platform.");
437
+ }
438
+ if (other === undefined)
439
+ out.push({ tag, digest: m.digest });
440
+ taken.set(tag, m.digest);
441
+ }
442
+ }
443
+ return out;
444
+ }
445
+ /** A tag that names the release, by `{label}` or `{version}` (#5269), and so belongs to it. */
446
+ const namesRelease = (t) => t.includes("{label}") || t.includes("{version}");
447
+ /** `t` with `{label}` and `{version}` (the label from its first digit, #5269) filled in. */
448
+ function fillTag(t, label) {
449
+ const at = label.search(/\d/);
450
+ return t.split("{label}").join(label).split("{version}").join(at >= 0 ? label.slice(at) : label);
451
+ }
413
452
  /** The tags to point at the digest: the context's tag when set, else the declared ones with `{label}` filled in, without `latest` for a prerelease label. */
414
453
  export function ociTags(decl, ctx) {
415
454
  if (ctx.tag)
416
455
  return [ctx.tag];
417
456
  const declared = decl.tags ?? (ctx.label ? ["{label}"] : []);
418
- const tags = declared.filter((t) => ctx.label !== null || !t.includes("{label}")).map((t) => t.split("{label}").join(ctx.label ?? ""));
457
+ const tags = declared.filter((t) => ctx.label !== null || !namesRelease(t)).map((t) => (ctx.label === null ? t : fillTag(t, ctx.label)));
419
458
  // A prerelease label moves no `latest`; what is left is its own label tag.
420
459
  if (prereleaseOf(ctx.label) === null)
421
460
  return tags;
@@ -441,7 +480,7 @@ export function ociArchiveDigest(abs) {
441
480
  export function ociMovingTags(decl, channel, label = null) {
442
481
  if (channel)
443
482
  return [channel];
444
- const moving = (decl.tags ?? ["{label}"]).filter((t) => !t.includes("{label}"));
483
+ const moving = (decl.tags ?? ["{label}"]).filter((t) => !namesRelease(t));
445
484
  return prereleaseOf(label) === null ? moving : moving.filter((t) => t !== "latest");
446
485
  }
447
486
  export function ociTarget(decl, deps) {
@@ -460,8 +499,17 @@ export function ociTarget(decl, deps) {
460
499
  }
461
500
  return layout;
462
501
  };
463
- const item = (ctx, digest) => {
464
- const tags = ociTags(decl, ctx);
502
+ /** #5269: each platform's image's tags, from the layout. */
503
+ const platformTags = (ctx, layout) => ociPlatformTags(decl, ctx.label, layout.manifests, (digest) => {
504
+ const m = layout.manifests.find((x) => x.digest === digest);
505
+ const config = m?.blobs[0];
506
+ if (!config)
507
+ return undefined;
508
+ const c = JSON.parse(Buffer.from(layout.readBlob(config.digest)).toString("utf-8"));
509
+ return { ...(c.os ? { os: c.os } : {}), ...(c.architecture ? { architecture: c.architecture } : {}), ...(c.variant ? { variant: c.variant } : {}) };
510
+ });
511
+ const item = (ctx, digest, perPlatform = []) => {
512
+ const tags = [...ociTags(decl, ctx), ...perPlatform.map((p) => p.tag)];
465
513
  return {
466
514
  name: `${decl.image}${tags.length > 0 ? ` (tag${tags.length === 1 ? "" : "s"} ${tags.join(", ")})` : ""}`,
467
515
  destination: `${decl.repository}@${digest}`,
@@ -548,7 +596,7 @@ export function ociTarget(decl, deps) {
548
596
  const label = ctx.label;
549
597
  if (label === null)
550
598
  return null;
551
- const tags = (decl.tags ?? ["{label}"]).filter((t) => t.includes("{label}")).map((t) => t.split("{label}").join(label));
599
+ const tags = (decl.tags ?? ["{label}"]).filter(namesRelease).map((t) => fillTag(t, label));
552
600
  if (tags.length === 0)
553
601
  return null;
554
602
  const { registry } = connect(ctx);
@@ -632,7 +680,7 @@ export function ociTarget(decl, deps) {
632
680
  async plan(ctx) {
633
681
  const layout = inspect(ctx);
634
682
  try {
635
- return [item(ctx, layout.top.digest), ...referrers(ctx, layout).map(referrerItem), ...(ctx.signing ? signatures.map((s) => signatureItem(ctx, s, layout.top.digest)) : [])];
683
+ return [item(ctx, layout.top.digest, platformTags(ctx, layout)), ...referrers(ctx, layout).map(referrerItem), ...(ctx.signing ? signatures.map((s) => signatureItem(ctx, s, layout.top.digest)) : [])];
636
684
  }
637
685
  finally {
638
686
  layout.cleanup();
@@ -643,7 +691,7 @@ export function ociTarget(decl, deps) {
643
691
  try {
644
692
  const attached = referrers(ctx, layout);
645
693
  const { cred, registry } = connect(ctx);
646
- const staged = { ...item(ctx, layout.top.digest), name: decl.image };
694
+ const staged = { ...item(ctx, layout.top.digest, platformTags(ctx, layout)), name: decl.image };
647
695
  const items = [];
648
696
  if (await registry.hasManifest(layout.top.digest, layout.top.mediaType)) {
649
697
  ctx.log(`${decl.repository} already holds ${layout.top.digest}; the image is not pushed again`);
@@ -691,8 +739,15 @@ export function ociTarget(decl, deps) {
691
739
  for (const t of tags)
692
740
  await registry.putManifest(t, layout.top.mediaType, layout.top.bytes);
693
741
  ctx.log(tags.length > 0 ? `tagged ${layout.top.digest} ${tags.join(", ")}` : `no tag to point at ${layout.top.digest}`);
742
+ // #5269: each platform's image under its own tag, pushed by digest in the stage.
743
+ const perPlatform = platformTags(ctx, layout);
744
+ for (const p of perPlatform) {
745
+ const m = layout.manifests.find((x) => x.digest === p.digest);
746
+ await registry.putManifest(p.tag, m.mediaType, m.bytes);
747
+ ctx.log(`tagged ${p.digest} ${p.tag}`);
748
+ }
694
749
  const signed = (staged?.items ?? []).filter((i) => i.attachment === "signature" || i.attachment === "attestation").map(({ present: _present, ...i }) => i);
695
- return { target: this.name, destination: this.destination, items: [item(ctx, layout.top.digest), ...referrers(ctx, layout).map(referrerItem), ...signed] };
750
+ return { target: this.name, destination: this.destination, items: [item(ctx, layout.top.digest, perPlatform), ...referrers(ctx, layout).map(referrerItem), ...signed] };
696
751
  }
697
752
  finally {
698
753
  layout.cleanup();
@@ -41,12 +41,25 @@ export declare function changelogBump(messages: readonly string[]): ReleaseBump;
41
41
  export declare function releaseChangelog(commits: readonly ChangelogCommit[]): ReleaseChangelog;
42
42
  /** The commit types a forge release's notes generated from commits list when none are declared (#5153). */
43
43
  export declare const DEFAULT_NOTES_TYPES: readonly string[];
44
+ /** Which commits a forge release's notes generated from commits list (#5153, #5270). */
45
+ export interface NotesFilter {
46
+ /** The conventional types listed. Default `feat`, `fix` and `perf`; `*` lists every type. */
47
+ types?: readonly string[];
48
+ /** The conventional types left out, every other commit listed: goreleaser's `changelog.filters.exclude`. Not with `types`. */
49
+ exclude?: readonly string[];
50
+ /** List the commits whose subject is not conventional. Default: with `exclude` or `*` yes, with a list of types no. */
51
+ nonConventional?: boolean;
52
+ }
53
+ /** Whether the notes list `message` under `filter` (#5270). A breaking change is listed whatever its type. */
54
+ export declare function notesListCommit(message: string, filter?: NotesFilter): boolean;
44
55
  /**
45
56
  * Release notes from `commits` (#5153), newest first as `git log` lists
46
- * them: the commits whose conventional type is in `types`, grouped by
57
+ * them: the commits {@link notesListCommit} lists, grouped by
47
58
  * {@link releaseChangelog} under a `###` heading each, one line per commit
48
- * with its scope and short sha. A breaking change is listed whatever its
49
- * type; `*` in `types` lists every commit, conventional or not. Empty when
50
- * no commit is listed.
59
+ * with its scope and short sha. `types` (default `feat`, `fix` and `perf`)
60
+ * lists those types, `*` every commit; `exclude` lists every commit but those
61
+ * types (#5270). Commits that are not conventional are listed with `*` or
62
+ * `exclude` and not with a list of types, unless `nonConventional` says
63
+ * otherwise. Empty when no commit is listed.
51
64
  */
52
- export declare function changelogNotes(commits: readonly ChangelogCommit[], types?: readonly string[]): string;
65
+ export declare function changelogNotes(commits: readonly ChangelogCommit[], filter?: NotesFilter | readonly string[]): string;
@@ -44,20 +44,32 @@ const NOTES_GROUPS = [
44
44
  ["fix", "Fixes"],
45
45
  ["other", "Other changes"],
46
46
  ];
47
+ /** Whether the notes list `message` under `filter` (#5270). A breaking change is listed whatever its type. */
48
+ export function notesListCommit(message, filter = {}) {
49
+ const { kind, type } = classifyCommit(message);
50
+ if (kind === "breaking")
51
+ return true;
52
+ const types = filter.types ?? (filter.exclude ? ["*"] : DEFAULT_NOTES_TYPES);
53
+ const all = types.includes("*");
54
+ if (type === undefined)
55
+ return filter.nonConventional ?? all;
56
+ if (filter.exclude?.includes(type))
57
+ return false;
58
+ return all || types.includes(type);
59
+ }
47
60
  /**
48
61
  * Release notes from `commits` (#5153), newest first as `git log` lists
49
- * them: the commits whose conventional type is in `types`, grouped by
62
+ * them: the commits {@link notesListCommit} lists, grouped by
50
63
  * {@link releaseChangelog} under a `###` heading each, one line per commit
51
- * with its scope and short sha. A breaking change is listed whatever its
52
- * type; `*` in `types` lists every commit, conventional or not. Empty when
53
- * no commit is listed.
64
+ * with its scope and short sha. `types` (default `feat`, `fix` and `perf`)
65
+ * lists those types, `*` every commit; `exclude` lists every commit but those
66
+ * types (#5270). Commits that are not conventional are listed with `*` or
67
+ * `exclude` and not with a list of types, unless `nonConventional` says
68
+ * otherwise. Empty when no commit is listed.
54
69
  */
55
- export function changelogNotes(commits, types = DEFAULT_NOTES_TYPES) {
56
- const all = types.includes("*");
57
- const listed = commits.filter((c) => {
58
- const { kind, type } = classifyCommit(c.message);
59
- return all || kind === "breaking" || (type !== undefined && types.includes(type));
60
- });
70
+ export function changelogNotes(commits, filter = {}) {
71
+ const f = Array.isArray(filter) ? { types: filter } : filter;
72
+ const listed = commits.filter((c) => notesListCommit(c.message, f));
61
73
  const { groups } = releaseChangelog(listed);
62
74
  const out = [];
63
75
  for (const [kind, title] of NOTES_GROUPS) {
@@ -75,7 +75,9 @@ export type ReleaseCutCode = "not-a-git-repository" | "release-commit-not-green"
75
75
  /** #5149: `release.green: "none"` under a security group or release gate that needs a green commit. */
76
76
  | "release-green-none-refused"
77
77
  /** #5149: `release.green: "forge-checks"`, and the forge could not be asked. */
78
- | "release-forge-checks-unavailable" | "release-worktree-dirty" | "release-no-environments" | "release-no-components" | "release-build-inputs-differ" | "release-image-invalid" | "release-image-unknown-component" | "release-image-name-taken" | "release-image-build-failed"
78
+ | "release-forge-checks-unavailable" | "release-worktree-dirty"
79
+ /** #5261: a `release.check` line exited non-zero. */
80
+ | "release-check-failed" | "release-no-environments" | "release-no-components" | "release-build-inputs-differ" | "release-image-invalid" | "release-image-unknown-component" | "release-image-name-taken" | "release-image-build-failed" | "release-image-archive-in-dist"
79
81
  /** #5151: `release.artifacts`, as ./release-artifacts.ts refuses it. */
80
82
  | "release-artifact-invalid" | "release-artifact-name-invalid" | "release-artifact-name-taken" | "release-artifact-outside" | "release-artifact-build-failed" | "release-artifact-no-output" | "release-artifact-output-taken" | "release-artifact-no-label" | "release-artifact-version-mismatch" | "release-artifact-checksums-name-taken"
81
83
  /** #5183: an entry with no build command whose files are not there, or are read from a checkout of another commit. */
@@ -84,6 +86,8 @@ export type ReleaseCutCode = "not-a-git-repository" | "release-commit-not-green"
84
86
  | "publish-npm-carries-image" | "publish-npm-pack-failed"
85
87
  /** #5230: an npm target names a package the registry has never published, or the registry can't say. */
86
88
  | "publish-npm-never-published" | "publish-npm-registry-unreadable";
89
+ /** The first chant whose `chant release cut` runs `release.check`, shell lines that refuse the cut with `release-check-failed` before anything is recorded or tagged, in a dry run too (#5261). */
90
+ export declare const RELEASE_CHECK_FLOOR = "0.124.104";
87
91
  export declare class ReleaseCutError extends Error {
88
92
  readonly code: ReleaseCutCode;
89
93
  readonly fix?: string | undefined;
@@ -178,6 +182,14 @@ export interface CutRequest {
178
182
  * environments, so a commit that does not build is not cut.
179
183
  */
180
184
  build?: () => void | Promise<void>;
185
+ /**
186
+ * Run `release.check` (#5261), once the label is stamped and the images,
187
+ * files and build command have run, and before any environment is
188
+ * compiled or anything recorded or tagged. Given the commit being cut;
189
+ * throws {@link ReleaseCutError} `release-check-failed` to refuse the cut.
190
+ * A dry run runs it too, so it refuses the same label.
191
+ */
192
+ check?: (commit: string) => void | Promise<void>;
181
193
  /** The intent files the cut consumes (#5159), recorded on its cut line. */
182
194
  intents?: readonly ReleaseCutIntent[];
183
195
  }
@@ -80,6 +80,8 @@ export function greenOverrideRule(lane) {
80
80
  }
81
81
  /** How long a recorded request for an override stands before a cut records a fresh one. */
82
82
  const OVERRIDE_REQUEST_HOURS = 48;
83
+ /** The first chant whose `chant release cut` runs `release.check`, shell lines that refuse the cut with `release-check-failed` before anything is recorded or tagged, in a dry run too (#5261). */
84
+ export const RELEASE_CHECK_FLOOR = "0.124.104";
83
85
  export class ReleaseCutError extends Error {
84
86
  constructor(code, message, fix,
85
87
  /** The cut recorded a request for an override on `chant/lifecycle` (#4693), which the caller pushes. */
@@ -410,6 +412,7 @@ async function prepare(req, record = false) {
410
412
  const builtFiles = req.buildArtifacts ? await req.buildArtifacts(commit) : [];
411
413
  if (artifactRelease)
412
414
  await req.build?.();
415
+ await req.check?.(commit);
413
416
  const compiled = [];
414
417
  for (const env of envs)
415
418
  compiled.push(await req.compiler.compile(env));
@@ -48,6 +48,13 @@ export declare const RELEASE_IMAGES_FLOOR = "0.124.71";
48
48
  export declare const RELEASE_IMAGE_DOCKERFILE_FLOOR = "0.124.78";
49
49
  /** The first chant whose Dockerfile entry in `release.images` takes `args`, build arguments beside the two chant passes (#4908). */
50
50
  export declare const RELEASE_IMAGE_ARGS_FLOOR = "0.124.88";
51
+ /**
52
+ * The first chant whose Dockerfile entry takes `labels`, OCI labels on the
53
+ * image, and `{label}` and `{version}` in `args` and `labels` values, and
54
+ * whose image builds see `CHANT_RELEASE_VERSION`; and whose default archive
55
+ * moves out of a goreleaser entry's `dist` (#5269).
56
+ */
57
+ export declare const RELEASE_IMAGE_LABELS_FLOOR = "0.124.104";
51
58
  /** One image a release builds in its cut with a command of the product's. */
52
59
  export interface ReleaseImageBuild {
53
60
  /** The image's name: its key in the digests file, and its artifact's `component` in the release. */
@@ -80,9 +87,17 @@ export interface ReleaseImageDockerfile {
80
87
  * Build arguments beside `SOURCE_DATE_EPOCH` and `CHANT_RELEASE_LABEL`
81
88
  * (#4908), such as the packed package's file and the chant packages the
82
89
  * image installs beside it, as sql-yodeler's `release-image.sh` passed
83
- * them. Values are literal; the config computes them.
90
+ * them. `{label}` in a value is the release's label and `{version}` the
91
+ * label from its first digit (#5269), such as `{ VERSION: "{version}" }`;
92
+ * the rest is literal.
84
93
  */
85
94
  args?: Record<string, string>;
95
+ /**
96
+ * OCI labels on the image (#5269), such as
97
+ * `{ "org.opencontainers.image.version": "{version}" }`, with the same
98
+ * placeholders as `args`.
99
+ */
100
+ labels?: Record<string, string>;
86
101
  }
87
102
  /** One image a release builds in its cut. */
88
103
  export type ReleaseImageDeclaration = ReleaseImageBuild | ReleaseImageDockerfile;
@@ -100,6 +115,20 @@ export declare const RELEASE_IMAGE_BUILDER = "chant-release";
100
115
  export declare function releaseImageBuildCommand(i: ReleaseImageDockerfile, o?: {
101
116
  versionArg?: boolean;
102
117
  }): string;
118
+ /** The archive of a Dockerfile entry that names none and whose default would be inside a goreleaser entry's `dist` (#5269). */
119
+ export declare const imageArchiveBesideGoreleaser: (name: string) => string;
120
+ /**
121
+ * A member's `release.images` with each archive placed (#5269). goreleaser
122
+ * empties its `dist` (`--clean`) when it builds, after the images, so an
123
+ * archive there would be gone before the cut records it: a Dockerfile entry
124
+ * that names no archive, whose default `dist/images/<name>.tar` is inside a
125
+ * goreleaser entry's `dist`, writes {@link imageArchiveBesideGoreleaser}
126
+ * instead. An archive named inside it is left for
127
+ * {@link checkImagesOutsideGoreleaser} to refuse.
128
+ */
129
+ export declare function placeReleaseImages(images: readonly ReleaseImageDeclaration[], artifacts?: readonly unknown[]): ReleaseImageDeclaration[];
130
+ /** Refuse an image archive inside a goreleaser entry's `dist` (#5269), which goreleaser empties after the images are built. */
131
+ export declare function checkImagesOutsideGoreleaser(images: readonly ReleaseImageDeclaration[], artifacts?: readonly unknown[]): void;
103
132
  /** Each entry as a command and an archive: a Dockerfile entry's command is {@link releaseImageBuildCommand}, its archive the default when it names none. */
104
133
  export declare function resolveReleaseImages(images: readonly ReleaseImageDeclaration[], o?: {
105
134
  versionArg?: boolean;
@@ -142,7 +171,8 @@ export interface BuildImagesInput {
142
171
  /**
143
172
  * Build each image and return it as the release's image artifact. The
144
173
  * command runs with `SOURCE_DATE_EPOCH` and, for a cut with a label,
145
- * `CHANT_RELEASE_LABEL`; an archive it did not write, or a command that
174
+ * `CHANT_RELEASE_LABEL` and `CHANT_RELEASE_VERSION` (the label from its
175
+ * first digit, when it has one); an archive it did not write, or a command that
146
176
  * fails, stops the cut.
147
177
  */
148
178
  export declare function buildReleaseImages(i: BuildImagesInput): ReleaseArtifact[];
@@ -49,6 +49,13 @@ export const RELEASE_IMAGES_FLOOR = "0.124.71";
49
49
  export const RELEASE_IMAGE_DOCKERFILE_FLOOR = "0.124.78";
50
50
  /** The first chant whose Dockerfile entry in `release.images` takes `args`, build arguments beside the two chant passes (#4908). */
51
51
  export const RELEASE_IMAGE_ARGS_FLOOR = "0.124.88";
52
+ /**
53
+ * The first chant whose Dockerfile entry takes `labels`, OCI labels on the
54
+ * image, and `{label}` and `{version}` in `args` and `labels` values, and
55
+ * whose image builds see `CHANT_RELEASE_VERSION`; and whose default archive
56
+ * moves out of a goreleaser entry's `dist` (#5269).
57
+ */
58
+ export const RELEASE_IMAGE_LABELS_FLOOR = "0.124.104";
52
59
  /** The platforms a Dockerfile entry builds by default. Building arm64 on amd64 needs QEMU's binfmt handlers. */
53
60
  export const RELEASE_IMAGE_PLATFORMS = ["linux/amd64", "linux/arm64"];
54
61
  /** The buildx builder a Dockerfile entry builds with, created with the `docker-container` driver when missing: the default driver cannot rewrite timestamps in an OCI archive. */
@@ -58,6 +65,14 @@ const PLATFORM = /^[a-z0-9]+\/[a-z0-9_]+(?:\/[a-z0-9]+)?$/;
58
65
  const sh = (s) => (/^[A-Za-z0-9_./:=,@+%-]+$/.test(s) ? s : `'${s.replace(/'/g, "'\\''")}'`);
59
66
  const isDockerfile = (i) => "dockerfile" in i && i.dockerfile !== undefined;
60
67
  const archiveOf = (i) => i.archive ?? `dist/images/${i.name}.tar`;
68
+ /** The placeholders an `args` or `labels` value takes (#5269), each the variable the build command reads. */
69
+ const PLACEHOLDERS = { "{label}": '"$CHANT_RELEASE_LABEL"', "{version}": '"$CHANT_RELEASE_VERSION"' };
70
+ /** `s` as one shell word, its `{label}` and `{version}` read from the build's environment (#5269). */
71
+ const word = (s) => s
72
+ .split(/(\{label\}|\{version\})/)
73
+ .filter((p) => p.length > 0)
74
+ .map((p) => PLACEHOLDERS[p] ?? sh(p))
75
+ .join("");
61
76
  /**
62
77
  * The shell command a Dockerfile entry builds with (#4819), the one
63
78
  * terragucci's and plywood's `scripts/release-image.sh` ran: `--no-cache`,
@@ -74,12 +89,52 @@ export function releaseImageBuildCommand(i, o = {}) {
74
89
  [
75
90
  `docker buildx build --builder ${b} --no-cache --platform ${sh((i.platforms ?? RELEASE_IMAGE_PLATFORMS).join(","))}`,
76
91
  `--provenance=false --sbom=false --build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH"${o.versionArg ? ' --build-arg CHANT_RELEASE_LABEL="$CHANT_RELEASE_LABEL"' : ""}${Object.entries(i.args ?? {})
77
- .map(([k, v]) => ` --build-arg ${sh(`${k}=${v}`)}`)
92
+ .map(([k, v]) => ` --build-arg ${word(`${k}=${v}`)}`)
93
+ .join("")}${Object.entries(i.labels ?? {})
94
+ .map(([k, v]) => ` --label ${word(`${k}=${v}`)}`)
78
95
  .join("")}`,
79
96
  `--output ${sh(`type=oci,dest=${archive},rewrite-timestamp=true`)} -f ${sh(i.dockerfile)} ${sh(i.context ?? ".")} >&2`,
80
97
  ].join(" "),
81
98
  ].join(" && ");
82
99
  }
100
+ /** The archive of a Dockerfile entry that names none and whose default would be inside a goreleaser entry's `dist` (#5269). */
101
+ export const imageArchiveBesideGoreleaser = (name) => `build/images/${name}.tar`;
102
+ /** `p` is `dir` or inside it, both relative to the member. */
103
+ const within = (p, dir) => {
104
+ const a = posix.normalize(p.replace(/\\/g, "/"));
105
+ const d = posix.normalize(dir.replace(/\\/g, "/")).replace(/\/$/, "");
106
+ return d === "." || a === d || a.startsWith(`${d}/`);
107
+ };
108
+ /** The `dist` directory of each goreleaser entry in `release.artifacts` (#5269). */
109
+ const goreleaserDists = (artifacts) => artifacts.flatMap((a) => {
110
+ const g = a?.goreleaser;
111
+ return g && typeof g === "object" ? [typeof g.dist === "string" ? g.dist : "dist"] : [];
112
+ });
113
+ /**
114
+ * A member's `release.images` with each archive placed (#5269). goreleaser
115
+ * empties its `dist` (`--clean`) when it builds, after the images, so an
116
+ * archive there would be gone before the cut records it: a Dockerfile entry
117
+ * that names no archive, whose default `dist/images/<name>.tar` is inside a
118
+ * goreleaser entry's `dist`, writes {@link imageArchiveBesideGoreleaser}
119
+ * instead. An archive named inside it is left for
120
+ * {@link checkImagesOutsideGoreleaser} to refuse.
121
+ */
122
+ export function placeReleaseImages(images, artifacts = []) {
123
+ const dists = goreleaserDists(artifacts);
124
+ if (dists.length === 0)
125
+ return [...images];
126
+ return images.map((i) => (isDockerfile(i) && i.archive === undefined && dists.some((d) => within(archiveOf(i), d)) ? { ...i, archive: imageArchiveBesideGoreleaser(i.name) } : i));
127
+ }
128
+ /** Refuse an image archive inside a goreleaser entry's `dist` (#5269), which goreleaser empties after the images are built. */
129
+ export function checkImagesOutsideGoreleaser(images, artifacts = []) {
130
+ const dists = goreleaserDists(artifacts);
131
+ for (const i of images) {
132
+ const dist = dists.find((d) => within(archiveOf(i), d));
133
+ if (dist === undefined)
134
+ continue;
135
+ throw new ReleaseImageError("release-image-archive-in-dist", `release.images "${i.name}": the archive ${archiveOf(i)} is inside ${dist}, which goreleaser empties when it builds the release's files, after the images`, `Write it outside ${dist}, such as archive: "${imageArchiveBesideGoreleaser(i.name)}".`);
136
+ }
137
+ }
83
138
  /** Each entry as a command and an archive: a Dockerfile entry's command is {@link releaseImageBuildCommand}, its archive the default when it names none. */
84
139
  export function resolveReleaseImages(images, o = {}) {
85
140
  return images.map((i) => (isDockerfile(i) ? { name: i.name, build: releaseImageBuildCommand(i, o), archive: archiveOf(i) } : i));
@@ -102,6 +157,7 @@ export class ReleaseImageError extends Error {
102
157
  }
103
158
  const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
104
159
  const BUILD_ARG = /^[A-Za-z_][A-Za-z0-9_]*$/;
160
+ const LABEL_KEY = /^[A-Za-z0-9][A-Za-z0-9._\/-]*$/;
105
161
  /** The build arguments chant passes itself, which an entry's `args` cannot set. */
106
162
  const CHANT_BUILD_ARGS = ["SOURCE_DATE_EPOCH", "CHANT_RELEASE_LABEL"];
107
163
  const outside = (p) => isAbsolute(p) || p.split(/[\\/]/).includes("..");
@@ -121,6 +177,12 @@ export function checkReleaseImages(images) {
121
177
  if (p !== undefined && outside(p))
122
178
  throw new ReleaseImageError("release-image-archive-outside", `release.images "${i.name}": ${what} ${p} is not a path inside the member`);
123
179
  }
180
+ for (const [k, v] of Object.entries((isDockerfile(i) && i.labels) || {})) {
181
+ if (!LABEL_KEY.test(k))
182
+ throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}": labels names ${JSON.stringify(k)}, which is not a label key such as org.opencontainers.image.version`);
183
+ if (typeof v !== "string" || /[\r\n]/.test(v))
184
+ throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}": labels.${k} is not a one-line string`);
185
+ }
124
186
  for (const [k, v] of Object.entries((isDockerfile(i) && i.args) || {})) {
125
187
  if (!BUILD_ARG.test(k))
126
188
  throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}": args names ${JSON.stringify(k)}, which is not a build argument name`);
@@ -138,7 +200,8 @@ const defaultRun = (command, o) => spawnSync(command, { cwd: o.cwd, env: o.env,
138
200
  /**
139
201
  * Build each image and return it as the release's image artifact. The
140
202
  * command runs with `SOURCE_DATE_EPOCH` and, for a cut with a label,
141
- * `CHANT_RELEASE_LABEL`; an archive it did not write, or a command that
203
+ * `CHANT_RELEASE_LABEL` and `CHANT_RELEASE_VERSION` (the label from its
204
+ * first digit, when it has one); an archive it did not write, or a command that
142
205
  * fails, stops the cut.
143
206
  */
144
207
  export function buildReleaseImages(i) {
@@ -148,8 +211,13 @@ export function buildReleaseImages(i) {
148
211
  const envFor = () => {
149
212
  const env = { ...(i.env ?? process.env), SOURCE_DATE_EPOCH: String(i.sourceDateEpoch) };
150
213
  delete env.CHANT_RELEASE_LABEL;
214
+ delete env.CHANT_RELEASE_VERSION;
151
215
  if (i.label !== null)
152
216
  env.CHANT_RELEASE_LABEL = i.label;
217
+ // #5269: the label from its first digit, for an entry's {version}.
218
+ const at = i.label?.search(/\d/) ?? -1;
219
+ if (i.label !== null && at >= 0)
220
+ env.CHANT_RELEASE_VERSION = i.label.slice(at);
153
221
  return env;
154
222
  };
155
223
  // #4819: each prepare command once, before any build, with no digests file, as the image's contents are built in the cut and the publish job alike.
@@ -0,0 +1,21 @@
1
+ /** The image a goreleaser config builds, as `release init` declares it. */
2
+ export interface GoreleaserImage {
3
+ /** The `release.images` entry's name: the repository's last segment. */
4
+ name: string;
5
+ repository: string;
6
+ dockerfile: string;
7
+ platforms: string[];
8
+ args: Record<string, string>;
9
+ labels: Record<string, string>;
10
+ /** The oci target's tags. */
11
+ tags: string[];
12
+ /** The oci target's `platformTags`, such as `{version}-{arch}`. */
13
+ platformTags: string[];
14
+ archive: string;
15
+ /** The goreleaser keys the plan replaces, to remove from the config. */
16
+ keys: string[];
17
+ /** What was not carried, each in words. */
18
+ unread: string[];
19
+ }
20
+ /** The image a goreleaser config builds, or null when it builds none with `dockers` or `dockers_v2`. */
21
+ export declare function goreleaserImage(text: string): GoreleaserImage | null;
@@ -0,0 +1,160 @@
1
+ /**
2
+ * `chant release init` for a goreleaser config that builds container images
3
+ * (#5269): its `dockers` (with `docker_manifests`) or `dockers_v2` read as
4
+ * one `release.images` Dockerfile entry and an `oci` target with the same
5
+ * repository, tags, per-platform tags, build arguments and labels, so a
6
+ * project that adopts the plan keeps publishing its image. What does not
7
+ * translate is named, never dropped without a word.
8
+ *
9
+ * goreleaser's templates map to chant's placeholders: `{{ .Version }}` is
10
+ * `{version}`. Any other template is not carried.
11
+ */
12
+ import { parseYAML } from "../yaml.js";
13
+ import { imageArchiveBesideGoreleaser } from "./release-images.js";
14
+ const VERSION = /\{\{\s*\.Version\s*\}\}/g;
15
+ /** A goreleaser template as a chant value, or null when it holds a template chant has no placeholder for. */
16
+ function template(t) {
17
+ const v = t.replace(VERSION, "{version}");
18
+ return /\{\{/.test(v) ? null : v;
19
+ }
20
+ /** `repo:tag` split at the tag's colon (a registry port's colon comes before the last slash). */
21
+ function splitRef(ref) {
22
+ const at = ref.lastIndexOf(":");
23
+ if (at <= ref.lastIndexOf("/"))
24
+ return null;
25
+ return { repository: ref.slice(0, at), tag: ref.slice(at + 1) };
26
+ }
27
+ const strings = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === "string") : typeof v === "string" ? [v] : []);
28
+ /** `--build-arg=K=V`, `--label=K=V` and `--platform=...` flags into args and labels; the rest is not carried. */
29
+ function readFlags(flags, into) {
30
+ for (const f of flags) {
31
+ const m = /^--(build-arg|label)[= ]([^=\s]+)=(.*)$/.exec(f.trim());
32
+ if (m) {
33
+ const value = template(m[3]);
34
+ if (value === null)
35
+ into.unread.push(`the ${m[1]} ${m[2]}=${m[3]}, whose template chant has no placeholder for`);
36
+ else
37
+ (m[1] === "label" ? into.labels : into.args)[m[2]] = value;
38
+ }
39
+ else if (!/^--platform[= ]/.test(f.trim()))
40
+ into.unread.push(`the build flag ${f}`);
41
+ }
42
+ }
43
+ /** The image a goreleaser config builds, or null when it builds none with `dockers` or `dockers_v2`. */
44
+ export function goreleaserImage(text) {
45
+ let doc;
46
+ try {
47
+ doc = parseYAML(text);
48
+ }
49
+ catch {
50
+ return null;
51
+ }
52
+ if (!doc || typeof doc !== "object")
53
+ return null;
54
+ const unread = [];
55
+ const args = {};
56
+ const labels = {};
57
+ const flags = { args, labels, unread };
58
+ const platforms = [];
59
+ const tags = [];
60
+ const platformTags = new Set();
61
+ const repositories = new Set();
62
+ const dockerfiles = new Set();
63
+ const keys = [];
64
+ const addTag = (raw) => {
65
+ const t = template(raw);
66
+ if (t === null)
67
+ unread.push(`the tag ${raw}, whose template chant has no placeholder for`);
68
+ else if (!tags.includes(t))
69
+ tags.push(t);
70
+ };
71
+ const v2 = Array.isArray(doc.dockers_v2) ? doc.dockers_v2 : [];
72
+ const v1 = Array.isArray(doc.dockers) ? doc.dockers : [];
73
+ if (v2.length > 0) {
74
+ keys.push("dockers_v2");
75
+ for (const d of v2) {
76
+ for (const r of strings(d.images))
77
+ repositories.add(r);
78
+ dockerfiles.add(typeof d.dockerfile === "string" ? d.dockerfile : "Dockerfile");
79
+ for (const p of strings(d.platforms))
80
+ if (!platforms.includes(p))
81
+ platforms.push(p);
82
+ for (const t of strings(d.tags))
83
+ addTag(t);
84
+ for (const [k, v] of Object.entries(d.build_args ?? {})) {
85
+ const value = typeof v === "string" ? template(v) : null;
86
+ if (value === null)
87
+ unread.push(`the build argument ${k}, whose value chant can't carry`);
88
+ else
89
+ args[k] = value;
90
+ }
91
+ for (const [k, v] of Object.entries(d.labels ?? {})) {
92
+ const value = typeof v === "string" ? template(v) : null;
93
+ if (value === null)
94
+ unread.push(`the label ${k}, whose value chant can't carry`);
95
+ else
96
+ labels[k] = value;
97
+ }
98
+ readFlags(strings(d.flags), flags);
99
+ }
100
+ }
101
+ if (v1.length > 0) {
102
+ keys.push("dockers");
103
+ // The images each entry pushes: per platform, or the whole image when there are no manifests.
104
+ const manifests = Array.isArray(doc.docker_manifests) ? doc.docker_manifests : [];
105
+ if (manifests.length > 0)
106
+ keys.push("docker_manifests");
107
+ for (const d of v1) {
108
+ const goos = typeof d.goos === "string" ? d.goos : "linux";
109
+ const goarch = typeof d.goarch === "string" ? d.goarch : "amd64";
110
+ const variant = goarch === "arm" && d.goarm !== undefined ? `v${String(d.goarm)}` : "";
111
+ const platform = `${goos}/${goarch}${variant ? `/${variant}` : ""}`;
112
+ if (!platforms.includes(platform))
113
+ platforms.push(platform);
114
+ dockerfiles.add(typeof d.dockerfile === "string" ? d.dockerfile : "Dockerfile");
115
+ readFlags(strings(d.build_flag_templates), flags);
116
+ for (const ref of strings(d.image_templates)) {
117
+ const r = splitRef(ref);
118
+ if (!r) {
119
+ unread.push(`the image ${ref}, which names no tag`);
120
+ continue;
121
+ }
122
+ repositories.add(r.repository);
123
+ const t = template(r.tag);
124
+ const arch = `${goarch}${variant}`;
125
+ if (manifests.length === 0)
126
+ addTag(r.tag);
127
+ else if (t !== null && t.includes(arch))
128
+ platformTags.add(t.split(arch).join("{arch}"));
129
+ else
130
+ unread.push(`the per-platform tag ${r.tag}, which does not name its platform's architecture`);
131
+ }
132
+ }
133
+ for (const m of manifests) {
134
+ const name = typeof m.name_template === "string" ? splitRef(m.name_template) : null;
135
+ if (!name)
136
+ continue;
137
+ repositories.add(name.repository);
138
+ addTag(name.tag);
139
+ }
140
+ }
141
+ if (keys.length === 0)
142
+ return null;
143
+ if (Object.keys(doc).includes("kos"))
144
+ unread.push("the kos images, which chant does not build");
145
+ const [repository, ...others] = [...repositories];
146
+ if (!repository)
147
+ return null;
148
+ if (others.length > 0)
149
+ unread.push(`the images pushed to ${others.join(", ")}, as one oci target pushes to one repository`);
150
+ const [dockerfile, ...moreFiles] = [...dockerfiles];
151
+ if (moreFiles.length > 0)
152
+ unread.push(`the images built from ${moreFiles.join(", ")}, as one entry builds one Dockerfile`);
153
+ const name = (repository.split("/").pop() ?? "image").toLowerCase().replace(/[^a-z0-9._-]+/g, "-") || "image";
154
+ // A platform tag that names no version would move with every release; chant tags each release's own.
155
+ const ownTags = [...platformTags].filter((t) => t.includes("{version}") || t.includes("{label}"));
156
+ for (const t of platformTags)
157
+ if (!ownTags.includes(t))
158
+ unread.push(`the per-platform tag ${t}, which names no version`);
159
+ return { name, repository, dockerfile: dockerfile ?? "Dockerfile", platforms, args, labels, tags, platformTags: ownTags, archive: imageArchiveBesideGoreleaser(name), keys, unread };
160
+ }