@intentius/chant 0.124.70 → 0.124.71
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/ci-agent.d.ts +12 -1
- package/dist/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +13 -8
- package/dist/ci-commit.d.ts +297 -0
- package/dist/ci-commit.d.ts.map +1 -0
- package/dist/ci-commit.js +696 -0
- package/dist/ci-product-words.d.ts +6 -1
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +3 -1
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +7 -2
- package/dist/cli/handlers/commit.d.ts +26 -0
- package/dist/cli/handlers/commit.d.ts.map +1 -0
- package/dist/cli/handlers/commit.js +142 -0
- package/dist/cli/handlers/pr.d.ts +6 -0
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +16 -7
- package/dist/cli/handlers/release.d.ts +9 -0
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +114 -5
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +17 -0
- package/dist/components/product-pipeline.d.ts +33 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +34 -1
- package/dist/components/release-compile.d.ts +2 -0
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +8 -4
- package/dist/config.d.ts +46 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -0
- package/dist/lexicon.d.ts +37 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +28 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +4 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
- package/dist/lifecycle/__fixtures__/publish-fakes.js +6 -2
- package/dist/lifecycle/gated-request.d.ts +3 -1
- package/dist/lifecycle/gated-request.d.ts.map +1 -1
- package/dist/lifecycle/gated-request.js +5 -2
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +57 -0
- package/dist/lifecycle/publish-declaration.d.ts +16 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +35 -3
- package/dist/lifecycle/publish-forge.d.ts +12 -0
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +103 -19
- package/dist/lifecycle/publish-npm.d.ts +15 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +28 -1
- package/dist/lifecycle/publish-oci.d.ts +2 -0
- package/dist/lifecycle/publish-oci.d.ts.map +1 -1
- package/dist/lifecycle/publish-oci.js +10 -0
- package/dist/lifecycle/release-cut.d.ts +7 -1
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +8 -1
- package/dist/lifecycle/release-images.d.ts +87 -0
- package/dist/lifecycle/release-images.d.ts.map +1 -0
- package/dist/lifecycle/release-images.js +139 -0
- package/dist/lifecycle/release-publish.d.ts +2 -0
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/op/activities/review-agent.d.ts.map +1 -1
- package/dist/op/activities/review-agent.js +4 -2
- package/dist/op/gate.d.ts +5 -1
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +7 -2
- package/dist/op/op-waves-notify.d.ts +1 -1
- package/dist/op/op-waves-notify.d.ts.map +1 -1
- package/dist/op/op-waves-notify.js +2 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +12 -8
- package/dist/op/op-waves.d.ts +9 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +11 -0
- package/dist/pr-forge-base.d.ts +18 -0
- package/dist/pr-forge-base.d.ts.map +1 -0
- package/dist/pr-forge-base.js +29 -0
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +315 -315
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +1 -2
- package/dist/workspace/release-workflow.d.ts +23 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +203 -12
- package/package.json +1 -1
- package/src/ci-agent.ts +13 -8
- package/src/ci-commit.test.ts +415 -0
- package/src/ci-commit.ts +857 -0
- package/src/ci-product-words.ts +6 -2
- package/src/cli/handlers/approve.ts +6 -2
- package/src/cli/handlers/commit.ts +152 -0
- package/src/cli/handlers/operator.test.ts +2 -0
- package/src/cli/handlers/pr-wave-approve-lines.test.ts +32 -0
- package/src/cli/handlers/pr.ts +17 -7
- package/src/cli/handlers/release.ts +110 -5
- package/src/cli/main.ts +17 -0
- package/src/components/product-pipeline.test.ts +28 -1
- package/src/components/product-pipeline.ts +54 -1
- package/src/components/release-compile.ts +9 -3
- package/src/config.ts +24 -0
- package/src/lexicon.ts +56 -0
- package/src/lifecycle/__fixtures__/publish-fakes.ts +11 -5
- package/src/lifecycle/gated-request-spend.test.ts +115 -0
- package/src/lifecycle/gated-request.ts +5 -2
- package/src/lifecycle/git.ts +53 -0
- package/src/lifecycle/ledger-two-clones.test.ts +132 -0
- package/src/lifecycle/publish-declaration.ts +35 -3
- package/src/lifecycle/publish-forge-notes.test.ts +193 -0
- package/src/lifecycle/publish-forge.ts +101 -22
- package/src/lifecycle/publish-npm.ts +31 -2
- package/src/lifecycle/publish-oci.ts +10 -0
- package/src/lifecycle/publish-targets.test.ts +2 -1
- package/src/lifecycle/release-cut.ts +17 -1
- package/src/lifecycle/release-images.test.ts +242 -0
- package/src/lifecycle/release-images.ts +175 -0
- package/src/lifecycle/release-publish.ts +2 -0
- package/src/op/activities/review-agent.test.ts +20 -1
- package/src/op/activities/review-agent.ts +5 -2
- package/src/op/gate.ts +7 -2
- package/src/op/op-waves-approve-target.test.ts +108 -0
- package/src/op/op-waves-notify.ts +2 -2
- package/src/op/op-waves-run.ts +12 -7
- package/src/op/op-waves.ts +12 -0
- package/src/pr-forge-base.test.ts +37 -0
- package/src/pr-forge-base.ts +36 -0
- package/src/release-floors.ts +1 -1
- package/src/workspace/__fixtures__/release-workflow/forgejo-plain-member.yml +26 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-plain.yml +23 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-secure-member.yml +27 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-secure.yml +24 -0
- package/src/workspace/__fixtures__/release-workflow/github-plain-member.yml +26 -0
- package/src/workspace/__fixtures__/release-workflow/github-plain.yml +23 -0
- package/src/workspace/__fixtures__/release-workflow/github-secure-member.yml +27 -0
- package/src/workspace/__fixtures__/release-workflow/github-secure.yml +24 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-plain-member.yml +13 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-plain.yml +12 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-secure-member.yml +14 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-secure.yml +13 -0
- package/src/workspace/ci-green.ts +1 -2
- package/src/workspace/release-workflow.test.ts +151 -0
- package/src/workspace/release-workflow.ts +270 -12
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4637: two clones of one bare origin write to `chant/lifecycle`. An approval
|
|
3
|
+
* pushed from one clone survives every write the other makes afterwards.
|
|
4
|
+
*
|
|
5
|
+
* A plain `git fetch` in a full clone moves `refs/remotes/origin/chant/lifecycle`
|
|
6
|
+
* and leaves the local branch where it was. A write then built on the local
|
|
7
|
+
* branch, pushed with a lease on that ref, used to pass the lease and replace
|
|
8
|
+
* the remote's history with a branch missing the approval.
|
|
9
|
+
*/
|
|
10
|
+
import { afterEach, describe, expect, test } from "vitest";
|
|
11
|
+
import { execFileSync } from "node:child_process";
|
|
12
|
+
import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { pushLifecycleRebasing, pushLifecycleStatus, writeBlobToPath } from "./git";
|
|
16
|
+
import { appendGateResolution } from "./gate-ledger";
|
|
17
|
+
import { appendRunRecord } from "./run-ledger";
|
|
18
|
+
import type { OpRunRecordInput } from "../op/runtime";
|
|
19
|
+
|
|
20
|
+
const dirs: string[] = [];
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function git(args: string[], cwd: string): string {
|
|
27
|
+
return execFileSync("git", args, { cwd, encoding: "utf8", env: { ...process.env, LC_ALL: "C" } }).trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function tmp(name: string): string {
|
|
31
|
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), `ledger-two-${name}-`)));
|
|
32
|
+
dirs.push(dir);
|
|
33
|
+
return dir;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function clone(origin: string, name: string): string {
|
|
37
|
+
const dir = tmp(name);
|
|
38
|
+
git(["clone", "-q", origin, dir], tmpdir());
|
|
39
|
+
git(["config", "user.email", `${name}@chant.dev`], dir);
|
|
40
|
+
git(["config", "user.name", name], dir);
|
|
41
|
+
return dir;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A bare origin with `main` and a seeded `chant/lifecycle`, and two clones that both hold the seed locally. */
|
|
45
|
+
async function setup(): Promise<{ origin: string; a: string; b: string }> {
|
|
46
|
+
const origin = tmp("origin");
|
|
47
|
+
git(["init", "-q", "--bare", "-b", "main"], origin);
|
|
48
|
+
const a = clone(origin, "a");
|
|
49
|
+
writeFileSync(join(a, "README.md"), "fixture\n");
|
|
50
|
+
git(["add", "README.md"], a);
|
|
51
|
+
git(["commit", "-q", "-m", "init"], a);
|
|
52
|
+
git(["push", "-q", "origin", "main"], a);
|
|
53
|
+
await writeBlobToPath("prod", "seed.jsonl", '{"seed":true}\n', "seed", { cwd: a });
|
|
54
|
+
expect((await pushLifecycleStatus({ cwd: a })).status).toBe("pushed");
|
|
55
|
+
const b = clone(origin, "b");
|
|
56
|
+
git(["fetch", "-q", "origin", "chant/lifecycle:chant/lifecycle"], b);
|
|
57
|
+
return { origin, a, b };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const approval = { op: "deploy", gate: "prod", resolvedBy: "github:alice", timestamp: "2026-11-07T10:00:00Z" };
|
|
61
|
+
|
|
62
|
+
function run(overrides: Partial<OpRunRecordInput> = {}): OpRunRecordInput {
|
|
63
|
+
return {
|
|
64
|
+
op: "deploy",
|
|
65
|
+
env: "prod",
|
|
66
|
+
started: "2026-11-07T10:01:00.000Z",
|
|
67
|
+
ended: "2026-11-07T10:02:00.000Z",
|
|
68
|
+
status: "ok",
|
|
69
|
+
labels: {},
|
|
70
|
+
outcomes: {},
|
|
71
|
+
phases: [],
|
|
72
|
+
...overrides,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A file on origin's `chant/lifecycle`, or "" when it has none. */
|
|
77
|
+
function onOrigin(origin: string, path: string): string {
|
|
78
|
+
try {
|
|
79
|
+
return execFileSync("git", ["--git-dir", origin, "show", `chant/lifecycle:${path}`], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
80
|
+
} catch {
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function approveInA(a: string): Promise<void> {
|
|
86
|
+
await appendGateResolution(approval, { cwd: a });
|
|
87
|
+
expect((await pushLifecycleStatus({ cwd: a })).status).toBe("pushed");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
describe("ledger writers in two clones of one origin (#4637)", () => {
|
|
91
|
+
test("a write after a plain fetch keeps the approval the other clone pushed", async () => {
|
|
92
|
+
const { origin, a, b } = await setup();
|
|
93
|
+
await approveInA(a);
|
|
94
|
+
|
|
95
|
+
// An ordinary fetch: the tracking ref moves, the local branch does not.
|
|
96
|
+
git(["fetch", "-q", "origin"], b);
|
|
97
|
+
await appendRunRecord(run(), { cwd: b });
|
|
98
|
+
await pushLifecycleRebasing({ cwd: b });
|
|
99
|
+
|
|
100
|
+
expect(onOrigin(origin, "_gates/deploy.jsonl")).toContain("github:alice");
|
|
101
|
+
expect(onOrigin(origin, "prod/runs__deploy.jsonl")).toContain('"status":"ok"');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("a write committed before the fetch is replayed onto the approval, never pushed over it", async () => {
|
|
105
|
+
const { origin, a, b } = await setup();
|
|
106
|
+
await approveInA(a);
|
|
107
|
+
|
|
108
|
+
await appendRunRecord(run(), { cwd: b });
|
|
109
|
+
// The fetch lands after the commit, so the local branch no longer contains the lease.
|
|
110
|
+
git(["fetch", "-q", "origin"], b);
|
|
111
|
+
const status = await pushLifecycleStatus({ cwd: b });
|
|
112
|
+
expect(status.status).toBe("stale");
|
|
113
|
+
expect(onOrigin(origin, "_gates/deploy.jsonl")).toContain("github:alice");
|
|
114
|
+
|
|
115
|
+
expect(await pushLifecycleRebasing({ cwd: b })).toEqual({ pushed: true });
|
|
116
|
+
expect(onOrigin(origin, "_gates/deploy.jsonl")).toContain("github:alice");
|
|
117
|
+
expect(git(["--git-dir", origin, "log", "--format=%s", "chant/lifecycle"], b).split("\n")).toEqual(
|
|
118
|
+
expect.arrayContaining(["Gate resolution record", "Op run record: deploy"]),
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("a write with no fetch at all is refused as stale, then replayed onto the approval", async () => {
|
|
123
|
+
const { origin, a, b } = await setup();
|
|
124
|
+
await approveInA(a);
|
|
125
|
+
|
|
126
|
+
await appendRunRecord(run(), { cwd: b });
|
|
127
|
+
expect((await pushLifecycleStatus({ cwd: b })).status).toBe("stale");
|
|
128
|
+
expect(await pushLifecycleRebasing({ cwd: b })).toEqual({ pushed: true });
|
|
129
|
+
expect(onOrigin(origin, "_gates/deploy.jsonl")).toContain("github:alice");
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
@@ -69,6 +69,14 @@ export const NpmPublishSchema = z
|
|
|
69
69
|
* registry accepts a publish before it serves it. Unset, the wait ends
|
|
70
70
|
* only when every version is served or the registry fails (#4271).
|
|
71
71
|
*/
|
|
72
|
+
/**
|
|
73
|
+
* A file in the package, from its root, holding the image digests it pins
|
|
74
|
+
* (#4657), such as `dist/image-digests.json`. Every `sha256:` digest in it
|
|
75
|
+
* must be an image the release records, or the plan and `chant release
|
|
76
|
+
* verify` refuse the package. A package without the file is not checked,
|
|
77
|
+
* and a target none of whose packages has it is refused.
|
|
78
|
+
*/
|
|
79
|
+
pins: z.string().min(1).optional(),
|
|
72
80
|
registryWait: z.number().int().min(0).optional(),
|
|
73
81
|
})
|
|
74
82
|
.strict();
|
|
@@ -101,8 +109,31 @@ export const ForgePublishSchema = z
|
|
|
101
109
|
repo: z.string().min(1),
|
|
102
110
|
/** The API root: default `$GITHUB_API_URL` or `https://api.github.com` on GitHub, `$CI_API_V4_URL` or `https://gitlab.com/api/v4` on GitLab, `$GITHUB_API_URL` on Forgejo, which has no default. */
|
|
103
111
|
api: z.string().url().optional(),
|
|
104
|
-
/** Files to attach, relative to the member. */
|
|
105
|
-
assets: z.array(z.string().min(1))
|
|
112
|
+
/** Files to attach, relative to the member. May be empty when `notes` gives the release its body. */
|
|
113
|
+
assets: z.array(z.string().min(1)),
|
|
114
|
+
/**
|
|
115
|
+
* The release's notes (#4658): a section of a file in the member, sent as
|
|
116
|
+
* the release's body on GitHub and Forgejo and its description on GitLab.
|
|
117
|
+
*/
|
|
118
|
+
notes: z
|
|
119
|
+
.object({
|
|
120
|
+
/** The file, relative to the member, such as `CHANGELOG.md` or a docs site's changes page. */
|
|
121
|
+
file: z.string().min(1),
|
|
122
|
+
/**
|
|
123
|
+
* The heading that starts the section, such as `## In {version}` or `## [{version}]`. `{label}`, `{version}`
|
|
124
|
+
* (the label from its first digit) and `{tag}` are filled in. The section runs to the next heading of the same
|
|
125
|
+
* level or higher.
|
|
126
|
+
*/
|
|
127
|
+
heading: z.string().regex(/^#{1,6} \S/, "a markdown heading, such as ## {version}"),
|
|
128
|
+
/** Links that start with `/` are made absolute against this, such as `https://docs.example.com`. */
|
|
129
|
+
linkBase: z.string().url().optional(),
|
|
130
|
+
/** A paragraph before the section, with the same placeholders. */
|
|
131
|
+
before: z.string().min(1).optional(),
|
|
132
|
+
/** A paragraph after the section, with the same placeholders. */
|
|
133
|
+
after: z.string().min(1).optional(),
|
|
134
|
+
})
|
|
135
|
+
.strict()
|
|
136
|
+
.optional(),
|
|
106
137
|
/** The forge release's tag. Default: the tag the cut made, `release/<label>` or `release/<member>/<label>`. */
|
|
107
138
|
tag: z.string().min(1).optional(),
|
|
108
139
|
/** The variable holding the token. Default `GITHUB_TOKEN`, `GITLAB_TOKEN` (then `CI_JOB_TOKEN`), or `FORGEJO_TOKEN`. */
|
|
@@ -117,7 +148,8 @@ export const ForgePublishSchema = z
|
|
|
117
148
|
*/
|
|
118
149
|
latest: z.union([z.boolean(), z.literal("legacy")]).optional(),
|
|
119
150
|
})
|
|
120
|
-
.strict()
|
|
151
|
+
.strict()
|
|
152
|
+
.refine((d) => d.assets.length > 0 || d.notes !== undefined, { message: "a forge release needs assets, notes or both", path: ["assets"] });
|
|
121
153
|
|
|
122
154
|
/**
|
|
123
155
|
* A Homebrew formula in a tap repository on GitHub (#4676), rendered from a
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/** #4658: a forge release's notes, read from a section of a file in the member. */
|
|
2
|
+
import { afterAll, describe, expect, test } from "vitest";
|
|
3
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { createRedactor } from "./publish-credentials";
|
|
7
|
+
import { PublishDeclarationSchema } from "./publish-declaration";
|
|
8
|
+
import { releaseNotesSection } from "./publish-forge";
|
|
9
|
+
import { createPublishTargets } from "./publish-targets";
|
|
10
|
+
import { PublishTargetError, type PublishContext } from "./release-publish";
|
|
11
|
+
import { makeRelease } from "./release-store";
|
|
12
|
+
import { startFakeForge, writeLockfile } from "./__fixtures__/publish-fakes";
|
|
13
|
+
|
|
14
|
+
const dirs: string[] = [];
|
|
15
|
+
afterAll(() => {
|
|
16
|
+
for (const d of dirs) rmSync(d, { recursive: true, force: true });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const CHANGES = [
|
|
20
|
+
"# Changes",
|
|
21
|
+
"",
|
|
22
|
+
"## In 1.4.0",
|
|
23
|
+
"",
|
|
24
|
+
"- `api` reads its [config](/docs/config/) once.",
|
|
25
|
+
"- See [the guide](https://example.com/guide) and [a section](#later).",
|
|
26
|
+
"",
|
|
27
|
+
"```sh",
|
|
28
|
+
"# not a heading",
|
|
29
|
+
"api run",
|
|
30
|
+
"```",
|
|
31
|
+
"",
|
|
32
|
+
"### Fixed",
|
|
33
|
+
"",
|
|
34
|
+
"- a crash on start",
|
|
35
|
+
"",
|
|
36
|
+
"## In 1.3.0",
|
|
37
|
+
"",
|
|
38
|
+
"- older",
|
|
39
|
+
"",
|
|
40
|
+
].join("\n");
|
|
41
|
+
|
|
42
|
+
function member(): string {
|
|
43
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-notes-"));
|
|
44
|
+
dirs.push(dir);
|
|
45
|
+
writeFileSync(join(dir, "api-linux.tar.gz"), "binary bytes");
|
|
46
|
+
writeFileSync(join(dir, "CHANGES.md"), CHANGES);
|
|
47
|
+
writeLockfile(dir);
|
|
48
|
+
return dir;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function context(cwd: string, over: Partial<PublishContext> = {}): PublishContext & { lines: string[] } {
|
|
52
|
+
const env = over.env ?? {};
|
|
53
|
+
const redactor = createRedactor(env);
|
|
54
|
+
const lines: string[] = [];
|
|
55
|
+
return {
|
|
56
|
+
release: makeRelease({ member: null, commit: "c0ffee".padEnd(40, "0"), artifactDigests: [], targets: [{ env: "dev", params: [], templates: [] }] }),
|
|
57
|
+
label: "v1.4.0",
|
|
58
|
+
releaseTag: "release/v1.4.0",
|
|
59
|
+
provenance: { oidc: false, ci: null, reason: "not in CI" },
|
|
60
|
+
cwd,
|
|
61
|
+
tag: null,
|
|
62
|
+
env,
|
|
63
|
+
redactor,
|
|
64
|
+
log: (l) => lines.push(redactor.redact(l)),
|
|
65
|
+
...over,
|
|
66
|
+
lines,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const decl = (d: unknown) => PublishDeclarationSchema.parse(d);
|
|
71
|
+
const NOTES = { file: "CHANGES.md", heading: "## In {version}", linkBase: "https://docs.example.com" };
|
|
72
|
+
const SECTION = [
|
|
73
|
+
"- `api` reads its [config](https://docs.example.com/docs/config/) once.",
|
|
74
|
+
"- See [the guide](https://example.com/guide) and [a section](#later).",
|
|
75
|
+
"",
|
|
76
|
+
"```sh",
|
|
77
|
+
"# not a heading",
|
|
78
|
+
"api run",
|
|
79
|
+
"```",
|
|
80
|
+
"",
|
|
81
|
+
"### Fixed",
|
|
82
|
+
"",
|
|
83
|
+
"- a crash on start",
|
|
84
|
+
].join("\n");
|
|
85
|
+
|
|
86
|
+
describe("releaseNotesSection (#4658)", () => {
|
|
87
|
+
test("the section runs to the next heading of its level, past code and lower headings, with root links made absolute", () => {
|
|
88
|
+
expect(releaseNotesSection(CHANGES, "## In 1.4.0", "https://docs.example.com/")).toBe(SECTION);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("a changelog's version heading with a date matches; a longer version or a prerelease does not", () => {
|
|
92
|
+
const log = "## [1.2.30] - 2026-11-01\n\n- no\n\n## [1.2.3] - 2026-10-01\n\n- yes\n\n## 1.2.3-rc.1\n\n- no\n";
|
|
93
|
+
expect(releaseNotesSection(log, "## [1.2.3]")).toBe("- yes");
|
|
94
|
+
expect(() => releaseNotesSection("## 1.2.3-rc.1\n\n- rc\n", "## 1.2.3")).toThrow(/no heading "## 1.2.3"/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("a missing or empty section is an error", () => {
|
|
98
|
+
expect(() => releaseNotesSection(CHANGES, "## In 9.9.9")).toThrow(/no heading/);
|
|
99
|
+
expect(() => releaseNotesSection("## In 1.4.0\n\n## In 1.3.0\n- x\n", "## In 1.4.0")).toThrow(/section is empty/);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("a forge release's notes (#4658)", () => {
|
|
104
|
+
test("the plan carries the notes, with before and after filled in, so a dry run prints them", async () => {
|
|
105
|
+
const dir = member();
|
|
106
|
+
const forge = startFakeForge("github", "https://api.github.test", "acme/api");
|
|
107
|
+
const notes = { ...NOTES, before: "`@acme/api@{version}` on npm.", after: "Tag {tag}, label {label}." };
|
|
108
|
+
const [t] = await createPublishTargets([decl({ type: "forge", forge: "github", repo: "acme/api", api: "https://api.github.test", assets: ["api-linux.tar.gz"], notes })], { fetch: forge.fetch });
|
|
109
|
+
const items = await t!.plan(context(dir, { env: { GITHUB_TOKEN: "ghs_x" } }));
|
|
110
|
+
expect(items.at(-1)).toEqual({
|
|
111
|
+
name: "CHANGES.md",
|
|
112
|
+
destination: "github acme/api release release/v1.4.0, notes",
|
|
113
|
+
notes: `\`@acme/api@1.4.0\` on npm.\n\n${SECTION}\n\nTag release/v1.4.0, label v1.4.0.\n`,
|
|
114
|
+
});
|
|
115
|
+
expect(forge.calls).toEqual([]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("a missing section refuses at the plan, before anything is sent", async () => {
|
|
119
|
+
const dir = member();
|
|
120
|
+
const forge = startFakeForge("github", "https://api.github.test", "acme/api");
|
|
121
|
+
for (const notes of [{ ...NOTES, heading: "## In 2.0.0" }, { ...NOTES, file: "NOPE.md" }]) {
|
|
122
|
+
const [t] = await createPublishTargets([decl({ type: "forge", forge: "github", repo: "acme/api", api: "https://api.github.test", assets: ["api-linux.tar.gz"], notes })], { fetch: forge.fetch });
|
|
123
|
+
const err = await t!.plan(context(dir, { env: { GITHUB_TOKEN: "ghs_x" } })).catch((e: unknown) => e);
|
|
124
|
+
expect(err).toBeInstanceOf(PublishTargetError);
|
|
125
|
+
expect((err as PublishTargetError).code).toBe("publish-forge-notes-missing");
|
|
126
|
+
}
|
|
127
|
+
expect(forge.calls).toEqual([]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("GitHub: the draft and the published release carry the notes, and the release is made latest", async () => {
|
|
131
|
+
const dir = member();
|
|
132
|
+
const forge = startFakeForge("github", "https://api.github.test", "acme/api");
|
|
133
|
+
const [t] = await createPublishTargets([decl({ type: "forge", forge: "github", repo: "acme/api", api: "https://api.github.test", assets: ["api-linux.tar.gz"], notes: NOTES })], { fetch: forge.fetch });
|
|
134
|
+
const ctx = context(dir, { env: { GITHUB_TOKEN: "ghs_x" } });
|
|
135
|
+
const staged = await t!.stage(ctx);
|
|
136
|
+
expect(forge.releases[0]).toMatchObject({ draft: true, body: `${SECTION}\n` });
|
|
137
|
+
await t!.reveal(ctx, staged);
|
|
138
|
+
expect(forge.releases[0]).toMatchObject({ draft: false, body: `${SECTION}\n`, make_latest: "true" });
|
|
139
|
+
|
|
140
|
+
// A publish run again finds the release published and sends nothing that would change its notes.
|
|
141
|
+
forge.releases[0]!.body = "edited by hand";
|
|
142
|
+
const n = forge.calls.length;
|
|
143
|
+
const again = await t!.stage(ctx);
|
|
144
|
+
await t!.reveal(ctx, again);
|
|
145
|
+
expect(forge.calls.slice(n).map((c) => c.method)).toEqual(["GET"]);
|
|
146
|
+
expect(forge.releases[0]!.body).toBe("edited by hand");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("GitHub: a release cut to a channel is not made latest, and a declared latest wins", async () => {
|
|
150
|
+
const dir = member();
|
|
151
|
+
for (const [latest, sent] of [[undefined, "false"], [true, "true"]] as const) {
|
|
152
|
+
const forge = startFakeForge("github", "https://api.github.test", "acme/api");
|
|
153
|
+
const [t] = await createPublishTargets([decl({ type: "forge", forge: "github", repo: "acme/api", api: "https://api.github.test", assets: ["api-linux.tar.gz"], notes: NOTES, ...(latest !== undefined ? { latest } : {}) })], { fetch: forge.fetch });
|
|
154
|
+
const ctx = context(dir, { env: { GITHUB_TOKEN: "ghs_x" }, tag: "beta" });
|
|
155
|
+
await t!.reveal(ctx, await t!.stage(ctx));
|
|
156
|
+
expect(forge.releases[0]!.make_latest).toBe(sent);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("Forgejo: the notes are the release's body, and a channel's release is a prerelease", async () => {
|
|
161
|
+
const dir = member();
|
|
162
|
+
for (const [tag, prerelease] of [[null, undefined], ["beta", true]] as const) {
|
|
163
|
+
const forge = startFakeForge("forgejo", "https://forgejo.test/api/v1", "acme/api");
|
|
164
|
+
const [t] = await createPublishTargets([decl({ type: "forge", forge: "forgejo", repo: "acme/api", api: "https://forgejo.test/api/v1", assets: ["api-linux.tar.gz"], notes: NOTES })], { fetch: forge.fetch });
|
|
165
|
+
const ctx = context(dir, { env: { FORGEJO_TOKEN: "fj" }, tag });
|
|
166
|
+
await t!.reveal(ctx, await t!.stage(ctx));
|
|
167
|
+
expect(forge.releases[0]).toMatchObject({ draft: false, body: `${SECTION}\n` });
|
|
168
|
+
expect(forge.releases[0]!.prerelease).toBe(prerelease);
|
|
169
|
+
expect(JSON.parse(forge.calls.at(-1)!.body as string)).not.toHaveProperty("make_latest");
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("GitLab: the notes are the release's description", async () => {
|
|
174
|
+
const dir = member();
|
|
175
|
+
const api = "https://gitlab.test/api/v4";
|
|
176
|
+
const forge = startFakeForge("gitlab", api, "acme/api");
|
|
177
|
+
const [t] = await createPublishTargets([decl({ type: "forge", forge: "gitlab", repo: "acme/api", assets: ["api-linux.tar.gz"], notes: NOTES })], { fetch: forge.fetch });
|
|
178
|
+
const ctx = context(dir, { env: { GITLAB_TOKEN: "glpat", CI_API_V4_URL: api } });
|
|
179
|
+
await t!.reveal(ctx, await t!.stage(ctx));
|
|
180
|
+
expect(JSON.parse(forge.calls.at(-1)!.body as string).description).toBe(`${SECTION}\n`);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("a release of notes alone needs no assets and attaches no provenance statement; with neither, the declaration is refused", async () => {
|
|
184
|
+
const dir = member();
|
|
185
|
+
const forge = startFakeForge("github", "https://api.github.test", "acme/api");
|
|
186
|
+
const [t] = await createPublishTargets([decl({ type: "forge", forge: "github", repo: "acme/api", api: "https://api.github.test", assets: [], sbom: false, notes: NOTES })], { fetch: forge.fetch });
|
|
187
|
+
const ctx = context(dir, { env: { GITHUB_TOKEN: "ghs_x" } });
|
|
188
|
+
await t!.reveal(ctx, await t!.stage(ctx));
|
|
189
|
+
expect(forge.visible()).toEqual([{ tag: "release/v1.4.0", assets: [] }]);
|
|
190
|
+
expect(forge.releases[0]!.body).toBe(`${SECTION}\n`);
|
|
191
|
+
expect(() => decl({ type: "forge", forge: "github", repo: "acme/api", assets: [] })).toThrow(/assets, notes or both/);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
import { readFileSync } from "node:fs";
|
|
48
48
|
import { basename } from "node:path";
|
|
49
49
|
import { memberSbom, releaseProvenance } from "./publish-attachments";
|
|
50
|
+
import { releaseVersion } from "./publish-homebrew";
|
|
51
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
50
52
|
import { readCredential, type Credential } from "./publish-credentials";
|
|
51
53
|
import type { ForgePublishDeclaration } from "./publish-declaration";
|
|
52
54
|
import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets";
|
|
@@ -55,6 +57,52 @@ import { PublishTargetError, type PublishContext, type PublishDeps, type Publish
|
|
|
55
57
|
/** The first chant that reads `latest` on a forge target and sends it as GitHub's `make_latest` (#4676). */
|
|
56
58
|
export const PUBLISH_FORGE_LATEST_FLOOR = "0.124.63";
|
|
57
59
|
|
|
60
|
+
/** The first chant whose forge target reads `notes` and may have no assets (#4658). Products feature-detect on it. */
|
|
61
|
+
export const PUBLISH_FORGE_NOTES_FLOOR = NEXT_RELEASE;
|
|
62
|
+
|
|
63
|
+
/** `text` with `{label}`, `{version}` and `{tag}` filled in. */
|
|
64
|
+
function fillNotesText(text: string, values: { label: string; version: string; tag: string }): string {
|
|
65
|
+
return text.replaceAll("{label}", values.label).replaceAll("{version}", values.version).replaceAll("{tag}", values.tag);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The section of `page` that starts at the heading `heading` names (#4658),
|
|
70
|
+
* up to the next heading of the same level or higher, trimmed. A heading
|
|
71
|
+
* matches when it is the pattern, or the pattern and then whitespace, so
|
|
72
|
+
* `## [1.2.3] - 2026-11-07` matches `## [1.2.3]`, and neither `## 1.2.30`
|
|
73
|
+
* nor `## 1.2.3-rc.1` matches `## 1.2.3`. Links that start with `/` are
|
|
74
|
+
* made absolute against `linkBase`. Throws when there is no such heading or
|
|
75
|
+
* the section is empty.
|
|
76
|
+
*/
|
|
77
|
+
export function releaseNotesSection(page: string, heading: string, linkBase?: string): string {
|
|
78
|
+
const level = /^(#+)/.exec(heading)![1]!.length;
|
|
79
|
+
const lines = page.split("\n");
|
|
80
|
+
const matches = (l: string): boolean => {
|
|
81
|
+
const t = l.trimEnd();
|
|
82
|
+
return t === heading || (t.startsWith(heading) && /^\s/.test(t.slice(heading.length)));
|
|
83
|
+
};
|
|
84
|
+
const start = lines.findIndex(matches);
|
|
85
|
+
if (start < 0) throw new Error(`it has no heading "${heading}"`);
|
|
86
|
+
// A `#` line inside a fenced code block is code, not a heading.
|
|
87
|
+
let end = lines.length;
|
|
88
|
+
let fence: string | null = null;
|
|
89
|
+
for (let i = start + 1; i < lines.length; i++) {
|
|
90
|
+
const f = /^\s*(```|~~~)/.exec(lines[i]!);
|
|
91
|
+
if (f) fence = fence === null ? f[1]! : fence === f[1] ? null : fence;
|
|
92
|
+
if (fence !== null || f) continue;
|
|
93
|
+
const m = /^(#{1,6}) /.exec(lines[i]!);
|
|
94
|
+
if (m && m[1]!.length <= level) {
|
|
95
|
+
end = i;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const body = lines.slice(start + 1, end).join("\n").trim();
|
|
100
|
+
if (!body) throw new Error(`its "${heading}" section is empty`);
|
|
101
|
+
if (!linkBase) return body;
|
|
102
|
+
const base = linkBase.replace(/\/+$/, "");
|
|
103
|
+
return body.replace(/\]\((\/(?!\/)[^)\s]*)/g, (_, path: string) => `](${base}${path}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
58
106
|
/** The variables a forge's token is read from, in order. */
|
|
59
107
|
export function forgeTokenEnv(decl: Pick<ForgePublishDeclaration, "forge" | "tokenEnv">): string[] {
|
|
60
108
|
if (decl.tokenEnv) return [decl.tokenEnv];
|
|
@@ -145,7 +193,7 @@ class ForgeClient {
|
|
|
145
193
|
}
|
|
146
194
|
|
|
147
195
|
/** GitHub and Forgejo: the draft release for `tag`, made at `commit` when there is none. */
|
|
148
|
-
async draft(tag: string, commit: string, name: string): Promise<ForgeRelease> {
|
|
196
|
+
async draft(tag: string, commit: string, name: string, body?: string): Promise<ForgeRelease> {
|
|
149
197
|
const list = await this.call("GET", `${this.repoPath}/releases?per_page=100`);
|
|
150
198
|
if (list.status !== 200) this.fail("listing releases", list.status, list.text);
|
|
151
199
|
const drafts = Array.isArray(list.json) ? (list.json as Array<Record<string, unknown>>) : [];
|
|
@@ -155,25 +203,32 @@ class ForgeClient {
|
|
|
155
203
|
return this.toRelease(mine, tag);
|
|
156
204
|
}
|
|
157
205
|
this.ctx.log(`creating a draft ${this.decl.forge} release for ${tag} at ${commit.slice(0, 12)}`);
|
|
158
|
-
const create = await this.call("POST", `${this.repoPath}/releases`, JSON.stringify({ tag_name: tag, target_commitish: commit, name, draft: true }));
|
|
206
|
+
const create = await this.call("POST", `${this.repoPath}/releases`, JSON.stringify({ tag_name: tag, target_commitish: commit, name, draft: true, ...(body !== undefined ? { body } : {}) }));
|
|
159
207
|
if (create.status !== 201 || !create.json) this.fail(`creating a draft release ${tag}`, create.status, create.text);
|
|
160
208
|
return this.toRelease(create.json as Record<string, unknown>, tag);
|
|
161
209
|
}
|
|
162
210
|
|
|
163
|
-
/**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
211
|
+
/**
|
|
212
|
+
* GitHub and Forgejo: publish the draft `id` with its notes. GitHub gets
|
|
213
|
+
* `make_latest`: the declared `latest`, else `false` for a release cut to a
|
|
214
|
+
* channel and `true` for any other (#4658). Forgejo has no such setting and
|
|
215
|
+
* takes the newest release that is not a prerelease, so a channel's release
|
|
216
|
+
* is marked a prerelease there.
|
|
217
|
+
*/
|
|
218
|
+
async publishDraft(id: string, tag: string, o: { notes?: string; channel: boolean }): Promise<void> {
|
|
219
|
+
const body: Record<string, unknown> = { draft: false, ...(o.notes !== undefined ? { body: o.notes } : {}) };
|
|
220
|
+
if (this.decl.forge === "github") body.make_latest = String(this.decl.latest ?? !o.channel);
|
|
221
|
+
else if (o.channel) body.prerelease = true;
|
|
167
222
|
const res = await this.call("PATCH", `${this.repoPath}/releases/${id}`, JSON.stringify(body));
|
|
168
223
|
if (res.status !== 200) this.fail(`publishing the draft release ${tag}`, res.status, res.text);
|
|
169
224
|
}
|
|
170
225
|
|
|
171
226
|
/** GitLab: create the release for `tag` at `commit` with a link to each asset. */
|
|
172
|
-
async createWithLinks(tag: string, commit: string, name: string, links: Array<{ name: string; url: string }
|
|
227
|
+
async createWithLinks(tag: string, commit: string, name: string, links: Array<{ name: string; url: string }>, notes?: string): Promise<void> {
|
|
173
228
|
const res = await this.call(
|
|
174
229
|
"POST",
|
|
175
230
|
`${this.repoPath}/releases`,
|
|
176
|
-
JSON.stringify({ tag_name: tag, ref: commit, name, assets: { links: links.map((l) => ({ ...l, link_type: "package" })) } }),
|
|
231
|
+
JSON.stringify({ tag_name: tag, ref: commit, name, ...(notes !== undefined ? { description: notes } : {}), assets: { links: links.map((l) => ({ ...l, link_type: "package" })) } }),
|
|
177
232
|
);
|
|
178
233
|
if (res.status !== 201) this.fail(`creating release ${tag}`, res.status, res.text);
|
|
179
234
|
}
|
|
@@ -231,19 +286,38 @@ export function forgeTarget(decl: ForgePublishDeclaration, deps: PublishDeps): P
|
|
|
231
286
|
checkReleaseDigest(ctx.release, "asset", ctx.cwd, p, [digest]);
|
|
232
287
|
return { path: p, name: basename(p), bytes, digest };
|
|
233
288
|
});
|
|
234
|
-
// #4049: the SBOM and the provenance statement over the assets go on the release with them.
|
|
289
|
+
// #4049: the SBOM and the provenance statement over the assets go on the release with them. A release of notes alone has no asset to state.
|
|
235
290
|
const sbom = memberSbom(ctx, decl.sbom, `${decl.repo}@${tag}`, `the ${decl.forge} target`);
|
|
236
|
-
const provenance =
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
291
|
+
const provenance =
|
|
292
|
+
assets.length > 0
|
|
293
|
+
? releaseProvenance(
|
|
294
|
+
ctx,
|
|
295
|
+
assets.map((a) => ({ name: a.name, digest: a.digest })),
|
|
296
|
+
)
|
|
297
|
+
: null;
|
|
240
298
|
for (const a of [sbom, provenance]) if (a) assets.push({ path: a.name, name: a.name, bytes: a.bytes, digest: a.digest, attachment: a.kind });
|
|
241
299
|
const names = new Set<string>();
|
|
242
300
|
for (const a of assets) {
|
|
243
301
|
if (names.has(a.name)) throw new PublishTargetError("publish-forge-asset-name-taken", `two assets are named ${a.name}, and a release holds one asset per name`);
|
|
244
302
|
names.add(a.name);
|
|
245
303
|
}
|
|
246
|
-
return { tag, api, token, assets };
|
|
304
|
+
return { tag, api, token, assets, notes: releaseNotes(ctx, tag) };
|
|
305
|
+
};
|
|
306
|
+
// #4658: the notes are read when the target is planned, so a missing or empty section refuses before any target publishes.
|
|
307
|
+
const releaseNotes = (ctx: PublishContext, tag: string): string | undefined => {
|
|
308
|
+
const n = decl.notes;
|
|
309
|
+
if (!n) return undefined;
|
|
310
|
+
const label = ctx.label ?? tag;
|
|
311
|
+
const values = { label, version: releaseVersion(ctx.label) ?? label, tag };
|
|
312
|
+
const heading = fillNotesText(n.heading, values);
|
|
313
|
+
let section: string;
|
|
314
|
+
try {
|
|
315
|
+
section = releaseNotesSection(readFileSync(memberFile(ctx.cwd, n.file), "utf8"), heading, n.linkBase);
|
|
316
|
+
} catch (err) {
|
|
317
|
+
const why = (err as NodeJS.ErrnoException).code === "ENOENT" ? "it does not exist" : (err as Error).message;
|
|
318
|
+
throw new PublishTargetError("publish-forge-notes-missing", `the ${decl.forge} release's notes come from ${n.file}, and ${why}`, `Write the "${heading}" section in ${n.file}, or change notes.heading.`);
|
|
319
|
+
}
|
|
320
|
+
return [...(n.before ? [fillNotesText(n.before, values), ""] : []), section, ...(n.after ? ["", fillNotesText(n.after, values)] : [])].join("\n") + "\n";
|
|
247
321
|
};
|
|
248
322
|
const att = (a: Asset): Pick<PublishItem, "attachment"> => (a.attachment ? { attachment: a.attachment } : {});
|
|
249
323
|
const where = (tag: string, name: string) => `${decl.forge} ${decl.repo} release ${tag}, asset ${name}`;
|
|
@@ -260,11 +334,14 @@ export function forgeTarget(decl: ForgePublishDeclaration, deps: PublishDeps): P
|
|
|
260
334
|
credentialEnv: tokenNames,
|
|
261
335
|
key: publishTargetKey(decl),
|
|
262
336
|
async plan(ctx) {
|
|
263
|
-
const { tag, assets } = setup(ctx);
|
|
264
|
-
return
|
|
337
|
+
const { tag, assets, notes } = setup(ctx);
|
|
338
|
+
return [
|
|
339
|
+
...assets.map((a) => ({ name: a.path, destination: where(tag, a.name), digest: a.digest, ...att(a) })),
|
|
340
|
+
...(notes !== undefined ? [{ name: decl.notes!.file, destination: `${decl.forge} ${decl.repo} release ${tag}, notes`, notes }] : []),
|
|
341
|
+
];
|
|
265
342
|
},
|
|
266
343
|
async stage(ctx): Promise<StagedTarget> {
|
|
267
|
-
const { tag, api, token, assets } = setup(ctx);
|
|
344
|
+
const { tag, api, token, assets, notes } = setup(ctx);
|
|
268
345
|
ctx.log(`using the token from ${token.from}`);
|
|
269
346
|
const client = new ForgeClient(decl, api, token, fetchImpl, ctx);
|
|
270
347
|
const done = (items: PublishItem[], state: Record<string, string>): StagedTarget => ({ target: this.name, destination: this.destination, items, state });
|
|
@@ -300,7 +377,7 @@ export function forgeTarget(decl: ForgePublishDeclaration, deps: PublishDeps): P
|
|
|
300
377
|
return done(items, {});
|
|
301
378
|
}
|
|
302
379
|
|
|
303
|
-
const rel = await client.draft(tag, ctx.release.commit, ctx.label ?? tag);
|
|
380
|
+
const rel = await client.draft(tag, ctx.release.commit, ctx.label ?? tag, notes);
|
|
304
381
|
const items: PublishItem[] = [];
|
|
305
382
|
for (const a of assets) {
|
|
306
383
|
if (rel.assets.has(a.name)) {
|
|
@@ -316,18 +393,20 @@ export function forgeTarget(decl: ForgePublishDeclaration, deps: PublishDeps): P
|
|
|
316
393
|
return done(items, { releaseId: rel.id });
|
|
317
394
|
},
|
|
318
395
|
async reveal(ctx, staged) {
|
|
319
|
-
const { tag, api, token } = setup(ctx);
|
|
396
|
+
const { tag, api, token, notes } = setup(ctx);
|
|
320
397
|
const client = new ForgeClient(decl, api, token, fetchImpl, ctx);
|
|
321
398
|
const items = staged.items.map((i) => ({ name: i.name, destination: i.destination, ...(i.digest ? { digest: i.digest } : {}), ...(i.attachment ? { attachment: i.attachment } : {}) }));
|
|
322
399
|
if (staged.state.published === "true") return { target: this.name, destination: this.destination, items: items.map((i) => ({ ...i, present: true })) };
|
|
323
400
|
if (decl.forge === "gitlab") {
|
|
324
401
|
ctx.log(`creating the gitlab release ${tag} at ${ctx.release.commit.slice(0, 12)} with ${items.length} asset link(s)`);
|
|
325
|
-
await client.createWithLinks(tag, ctx.release.commit, ctx.label ?? tag, items.map((i) => ({ name: basename(i.name), url: i.destination })));
|
|
402
|
+
await client.createWithLinks(tag, ctx.release.commit, ctx.label ?? tag, items.map((i) => ({ name: basename(i.name), url: i.destination })), notes);
|
|
326
403
|
} else {
|
|
327
404
|
const id = staged.state.releaseId;
|
|
328
405
|
if (!id) throw new PublishTargetError("publish-forge-failed", `the staged ${decl.forge} release for ${tag} has no draft id to publish`);
|
|
329
|
-
|
|
330
|
-
|
|
406
|
+
const channel = ctx.tag !== null;
|
|
407
|
+
const latest = decl.forge === "github" ? ` with make_latest ${String(decl.latest ?? !channel)}` : channel ? " as a prerelease, since it was cut to a channel" : "";
|
|
408
|
+
ctx.log(`publishing the draft ${decl.forge} release ${tag}${notes !== undefined ? " with its notes" : ""}${latest}`);
|
|
409
|
+
await client.publishDraft(id, tag, { ...(notes !== undefined ? { notes } : {}), channel });
|
|
331
410
|
}
|
|
332
411
|
return { target: this.name, destination: this.destination, items };
|
|
333
412
|
},
|
|
@@ -59,12 +59,13 @@ import { join } from "node:path";
|
|
|
59
59
|
import { packageSbom } from "./publish-attachments";
|
|
60
60
|
import type { NpmPublishDeclaration } from "./publish-declaration";
|
|
61
61
|
import { checkReleaseDigest, fileDigest, isDir, memberFile, publishTargetKey } from "./publish-targets";
|
|
62
|
+
import { readPins, unknownPins } from "./release-images";
|
|
62
63
|
import { NPM_STAGE_TAG, PublishTargetError, type PublishContext, type PublishDeps, type PublishItem, type PublishTarget } from "./release-publish";
|
|
63
64
|
|
|
64
65
|
/** npm's output when a publish could not authenticate, as publish-packages.sh matches it. */
|
|
65
66
|
const NPM_AUTH_FAILED = /ENEEDAUTH|E401|need auth/;
|
|
66
67
|
|
|
67
|
-
interface NpmPackage {
|
|
68
|
+
export interface NpmPackage {
|
|
68
69
|
path: string;
|
|
69
70
|
abs: string;
|
|
70
71
|
name: string;
|
|
@@ -169,6 +170,30 @@ const NPM_VIEW_NOT_YET = /\bE404\b|\b404 Not Found\b|is not in (this|the npm) re
|
|
|
169
170
|
/** npm's errors for a version the registry does not serve yet. */
|
|
170
171
|
const NPM_NOT_SERVED = /\b(ETARGET|ERESOLVE|notarget)\b|No matching version found/;
|
|
171
172
|
|
|
173
|
+
/**
|
|
174
|
+
* #4657: refuse a package whose `pins` file holds an image digest the release
|
|
175
|
+
* does not record, and a target none of whose packages has the file. Read
|
|
176
|
+
* by the plan, so nothing is published, and by `chant release verify`.
|
|
177
|
+
*/
|
|
178
|
+
export function checkPackagePins(decl: Pick<NpmPublishDeclaration, "pins">, release: PublishContext["release"], pkgs: ReadonlyArray<Pick<NpmPackage, "path" | "abs" | "name">>): void {
|
|
179
|
+
if (!decl.pins) return;
|
|
180
|
+
let found = 0;
|
|
181
|
+
for (const pkg of pkgs) {
|
|
182
|
+
const text = readPins(pkg.abs, decl.pins, isDir(pkg.abs));
|
|
183
|
+
if (text === null) continue;
|
|
184
|
+
found++;
|
|
185
|
+
const unknown = unknownPins(text, release);
|
|
186
|
+
if (unknown.length > 0) {
|
|
187
|
+
throw new PublishTargetError(
|
|
188
|
+
"publish-npm-pin-unknown",
|
|
189
|
+
`${pkg.name} (${pkg.path}) pins ${unknown.join(", ")} in ${decl.pins}, which release ${release.releaseDigest} does not record as an image`,
|
|
190
|
+
"Build the package from the digests the cut wrote (CHANT_RELEASE_DIGESTS, or chant release images <label>), or cut a new release.",
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (found === 0) throw new PublishTargetError("publish-npm-pins-missing", `no package of the npm target holds ${decl.pins}, which pins names`, "Build the package so it carries the file, or remove pins.");
|
|
195
|
+
}
|
|
196
|
+
|
|
172
197
|
export function npmTarget(decl: NpmPublishDeclaration, deps: PublishDeps): PublishTarget {
|
|
173
198
|
const bin = deps.npm ?? "npm";
|
|
174
199
|
const sleep = deps.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
|
|
@@ -218,7 +243,11 @@ export function npmTarget(decl: NpmPublishDeclaration, deps: PublishDeps): Publi
|
|
|
218
243
|
rmSync(dir, { recursive: true, force: true });
|
|
219
244
|
}
|
|
220
245
|
};
|
|
221
|
-
const read = (ctx: PublishContext) =>
|
|
246
|
+
const read = (ctx: PublishContext) => {
|
|
247
|
+
const pkgs = decl.packages.map((p) => readPackage(ctx, p, decl.sbom));
|
|
248
|
+
checkPackagePins(decl, ctx.release, pkgs);
|
|
249
|
+
return pkgs;
|
|
250
|
+
};
|
|
222
251
|
const extra = (pkg: NpmPackage) => ({ ...(pkg.digest ? { digest: pkg.digest } : {}), ...(pkg.sbom ? { sbom: pkg.sbom } : {}) });
|
|
223
252
|
const plan = async (ctx: PublishContext): Promise<PublishItem[]> =>
|
|
224
253
|
read(ctx).map((pkg) => ({ name: `${pkg.name}@${pkg.version}`, destination: staging ? `${shown(NPM_STAGE_TAG)}, then ${revealTag(ctx)}` : shown(revealTag(ctx)), ...extra(pkg) }));
|