@caelo-cms/provisioning 0.12.4 → 0.12.5-rc.1
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/agent-db.js +8 -3
- package/dist/cli-routing.d.ts.map +1 -1
- package/dist/cli-routing.js +6 -5
- package/dist/cli-routing.js.map +1 -1
- package/dist/cli.js +18 -1
- package/dist/cli.js.map +1 -1
- package/dist/gcp-names.d.ts +51 -0
- package/dist/gcp-names.d.ts.map +1 -1
- package/dist/gcp-names.js +75 -0
- package/dist/gcp-names.js.map +1 -1
- package/dist/infra-contract.d.ts +1 -1
- package/dist/infra-contract.d.ts.map +1 -1
- package/dist/infra-contract.js +42 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/install-state.d.ts +8 -0
- package/dist/install-state.d.ts.map +1 -1
- package/dist/install-state.js +12 -0
- package/dist/install-state.js.map +1 -1
- package/dist/install-version.d.ts +110 -0
- package/dist/install-version.d.ts.map +1 -0
- package/dist/install-version.js +162 -0
- package/dist/install-version.js.map +1 -0
- package/dist/lifecycle.d.ts +6 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +46 -1
- package/dist/lifecycle.js.map +1 -1
- package/dist/release-candidate.d.ts +67 -0
- package/dist/release-candidate.d.ts.map +1 -0
- package/dist/release-candidate.js +138 -0
- package/dist/release-candidate.js.map +1 -0
- package/dist/reporting-job-setup.d.ts +102 -0
- package/dist/reporting-job-setup.d.ts.map +1 -0
- package/dist/reporting-job-setup.js +347 -0
- package/dist/reporting-job-setup.js.map +1 -0
- package/dist/self-hosted-upgrade.d.ts.map +1 -1
- package/dist/self-hosted-upgrade.js +18 -3
- package/dist/self-hosted-upgrade.js.map +1 -1
- package/dist/stack-contract.d.ts +30 -5
- package/dist/stack-contract.d.ts.map +1 -1
- package/dist/stack-contract.js +74 -10
- package/dist/stack-contract.js.map +1 -1
- package/dist/upgrade/admin-image-jobs.d.ts +13 -5
- package/dist/upgrade/admin-image-jobs.d.ts.map +1 -1
- package/dist/upgrade/admin-image-jobs.js +22 -2
- package/dist/upgrade/admin-image-jobs.js.map +1 -1
- package/dist/upgrade/converge.d.ts.map +1 -1
- package/dist/upgrade/converge.js +99 -9
- package/dist/upgrade/converge.js.map +1 -1
- package/dist/upgrade/release-images.d.ts +6 -2
- package/dist/upgrade/release-images.d.ts.map +1 -1
- package/dist/upgrade/release-images.js +5 -5
- package/dist/upgrade/release-images.js.map +1 -1
- package/dist/upgrader-iam-preflight.d.ts.map +1 -1
- package/dist/upgrader-iam-preflight.js +19 -1
- package/dist/upgrader-iam-preflight.js.map +1 -1
- package/dist/upgrader-setup.d.ts.map +1 -1
- package/dist/upgrader-setup.js +16 -1
- package/dist/upgrader-setup.js.map +1 -1
- package/dist/wizard.d.ts +7 -0
- package/dist/wizard.d.ts.map +1 -1
- package/dist/wizard.js +20 -5
- package/dist/wizard.js.map +1 -1
- package/dist/wizards/gcp-cost.d.ts +7 -11
- package/dist/wizards/gcp-cost.d.ts.map +1 -1
- package/dist/wizards/gcp-cost.js +47 -36
- package/dist/wizards/gcp-cost.js.map +1 -1
- package/dist/wizards/gcp-firebase.d.ts +4 -0
- package/dist/wizards/gcp-firebase.d.ts.map +1 -1
- package/dist/wizards/gcp-firebase.js +2 -0
- package/dist/wizards/gcp-firebase.js.map +1 -1
- package/dist/wizards/gcp-install-job.d.ts +10 -0
- package/dist/wizards/gcp-install-job.d.ts.map +1 -1
- package/dist/wizards/gcp-install-job.js +41 -10
- package/dist/wizards/gcp-install-job.js.map +1 -1
- package/dist/wizards/gcp.d.ts +7 -0
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +191 -9
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/cli-routing.test.ts +1 -1
- package/src/cli-routing.ts +6 -5
- package/src/cli.ts +18 -1
- package/src/cpu-idle.test.ts +7 -2
- package/src/gcp-names.ts +87 -0
- package/src/infra-contract.test.ts +6 -3
- package/src/infra-contract.ts +42 -1
- package/src/install-state.ts +12 -0
- package/src/install-version.test.ts +366 -0
- package/src/install-version.ts +205 -0
- package/src/lifecycle.ts +65 -3
- package/src/release-candidate.test.ts +191 -0
- package/src/release-candidate.ts +172 -0
- package/src/reporting-job-setup.test.ts +392 -0
- package/src/reporting-job-setup.ts +431 -0
- package/src/self-hosted-upgrade.ts +18 -3
- package/src/stack-contract.test.ts +24 -0
- package/src/stack-contract.ts +87 -9
- package/src/stack-converge-secrets.test.ts +2 -0
- package/src/stack-converge.test.ts +3 -3
- package/src/upgrade/admin-image-jobs.ts +35 -6
- package/src/upgrade/converge.ts +137 -8
- package/src/upgrade/release-images.test.ts +2 -2
- package/src/upgrade/release-images.ts +6 -4
- package/src/upgrade/upgrade.test.ts +165 -4
- package/src/upgrader-iam-preflight.test.ts +58 -0
- package/src/upgrader-iam-preflight.ts +21 -0
- package/src/upgrader-job.test.ts +3 -0
- package/src/upgrader-setup.test.ts +6 -0
- package/src/upgrader-setup.ts +18 -0
- package/src/wizard.ts +30 -5
- package/src/wizards/gcp-cost.test.ts +11 -13
- package/src/wizards/gcp-cost.ts +49 -36
- package/src/wizards/gcp-firebase.ts +6 -0
- package/src/wizards/gcp-install-job.ts +46 -12
- package/src/wizards/gcp.ts +250 -7
- package/stacks/aws/index.ts +10 -0
- package/stacks/azure/index.ts +10 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "bun:test";
|
|
4
|
+
import {
|
|
5
|
+
ACCEPT_RELEASE_CANDIDATE_FLAG,
|
|
6
|
+
confirmReleaseCandidate,
|
|
7
|
+
isPrereleaseVersion,
|
|
8
|
+
RELEASE_CANDIDATE_RETENTION_DAYS,
|
|
9
|
+
releaseCandidateWarning,
|
|
10
|
+
resolveChannelVersion,
|
|
11
|
+
} from "./release-candidate.js";
|
|
12
|
+
|
|
13
|
+
/** A prompt fake: records what was shown and asked, answers `answer`. */
|
|
14
|
+
function fakePrompt(answer: boolean) {
|
|
15
|
+
const warned: string[][] = [];
|
|
16
|
+
const asked: string[] = [];
|
|
17
|
+
return {
|
|
18
|
+
warned,
|
|
19
|
+
asked,
|
|
20
|
+
prompt: {
|
|
21
|
+
warn: (lines: readonly string[]) => {
|
|
22
|
+
warned.push([...lines]);
|
|
23
|
+
},
|
|
24
|
+
confirm: async (message: string) => {
|
|
25
|
+
asked.push(message);
|
|
26
|
+
return answer;
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("isPrereleaseVersion", () => {
|
|
33
|
+
it("is true for a version with a pre-release part, with or without a v", () => {
|
|
34
|
+
for (const v of ["0.12.5-rc.1", "v0.12.5-rc.1", "0.13.0-beta.2", "1.0.0-alpha"]) {
|
|
35
|
+
expect(isPrereleaseVersion(v)).toBe(true);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("is false for a stable release and for anything that is not a version", () => {
|
|
40
|
+
for (const v of ["0.12.4", "v0.12.4", "latest", "rc", "rc-0.12.5-rc.1", ""]) {
|
|
41
|
+
expect(isPrereleaseVersion(v)).toBe(false);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("releaseCandidateWarning", () => {
|
|
47
|
+
const text = releaseCandidateWarning("v0.12.5-rc.1").join("\n");
|
|
48
|
+
|
|
49
|
+
it("names the release and when its images are deleted", () => {
|
|
50
|
+
expect(text).toContain("v0.12.5-rc.1 is a release candidate");
|
|
51
|
+
expect(text).toContain(`${RELEASE_CANDIDATE_RETENTION_DAYS} days after it was published`);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("says what stops working: the jobs, not the services", () => {
|
|
55
|
+
// Cloud Run services import a copy of their image at deploy time; jobs
|
|
56
|
+
// pull theirs on every run (#1558 correction).
|
|
57
|
+
expect(text).toContain("services keep running on their own copy");
|
|
58
|
+
for (const job of ["update", "converge", "quality audit", "page capture"]) {
|
|
59
|
+
expect(text).toContain(job);
|
|
60
|
+
}
|
|
61
|
+
expect(text).toContain("Settings → Updates");
|
|
62
|
+
expect(text).toContain("audit a Stage");
|
|
63
|
+
expect(text).not.toContain("new instances");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("confirmReleaseCandidate", () => {
|
|
68
|
+
const rc = { version: "0.12.5-rc.1", action: "install" as const };
|
|
69
|
+
|
|
70
|
+
it("lets a stable release through without a word", async () => {
|
|
71
|
+
const f = fakePrompt(false);
|
|
72
|
+
const r = await confirmReleaseCandidate(
|
|
73
|
+
{ version: "0.12.4", action: "upgrade", interactive: true, accepted: false },
|
|
74
|
+
f.prompt,
|
|
75
|
+
);
|
|
76
|
+
expect(r).toEqual({ ok: true });
|
|
77
|
+
expect(f.warned).toEqual([]);
|
|
78
|
+
expect(f.asked).toEqual([]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("asks in a terminal, defaulting to the operator's answer", async () => {
|
|
82
|
+
const yes = fakePrompt(true);
|
|
83
|
+
expect(
|
|
84
|
+
await confirmReleaseCandidate({ ...rc, interactive: true, accepted: false }, yes.prompt),
|
|
85
|
+
).toEqual({ ok: true });
|
|
86
|
+
expect(yes.warned).toHaveLength(1);
|
|
87
|
+
expect(yes.asked).toEqual(["Install release candidate v0.12.5-rc.1 anyway?"]);
|
|
88
|
+
|
|
89
|
+
const no = fakePrompt(false);
|
|
90
|
+
const declined = await confirmReleaseCandidate(
|
|
91
|
+
{ version: "v0.12.5-rc.1", action: "upgrade", interactive: true, accepted: false },
|
|
92
|
+
no.prompt,
|
|
93
|
+
);
|
|
94
|
+
expect(declined.ok).toBe(false);
|
|
95
|
+
expect(declined.ok === false && declined.reason).toBe("declined");
|
|
96
|
+
expect(declined.ok === false && declined.message).toContain("upgrade to a stable release");
|
|
97
|
+
expect(no.asked).toEqual(["Upgrade to release candidate v0.12.5-rc.1 anyway?"]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("refuses where no prompt can ask, naming the flag that confirms", async () => {
|
|
101
|
+
const f = fakePrompt(true);
|
|
102
|
+
const r = await confirmReleaseCandidate(
|
|
103
|
+
{ ...rc, interactive: false, accepted: false },
|
|
104
|
+
f.prompt,
|
|
105
|
+
);
|
|
106
|
+
expect(r.ok).toBe(false);
|
|
107
|
+
expect(r.ok === false && r.reason).toBe("needs-flag");
|
|
108
|
+
expect(r.ok === false && r.message).toContain(ACCEPT_RELEASE_CANDIDATE_FLAG);
|
|
109
|
+
expect(r.ok === false && r.message).toContain("To install it without a prompt");
|
|
110
|
+
// The warning is shown either way; nothing is asked.
|
|
111
|
+
expect(f.warned).toHaveLength(1);
|
|
112
|
+
expect(f.asked).toEqual([]);
|
|
113
|
+
const upgrade = await confirmReleaseCandidate(
|
|
114
|
+
{ version: "0.12.5-rc.1", action: "upgrade", interactive: false, accepted: false },
|
|
115
|
+
fakePrompt(true).prompt,
|
|
116
|
+
);
|
|
117
|
+
expect(upgrade.ok === false && upgrade.message).toContain("To upgrade to it without a prompt");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("takes the flag as the confirmation, still showing the warning", async () => {
|
|
121
|
+
const f = fakePrompt(false);
|
|
122
|
+
expect(
|
|
123
|
+
await confirmReleaseCandidate({ ...rc, interactive: false, accepted: true }, f.prompt),
|
|
124
|
+
).toEqual({ ok: true });
|
|
125
|
+
expect(f.warned).toHaveLength(1);
|
|
126
|
+
expect(f.asked).toEqual([]);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
/** A fetch fake answering the GitHub releases list with `releases`. */
|
|
131
|
+
function releasesFetch(releases: unknown, status = 200) {
|
|
132
|
+
const urls: string[] = [];
|
|
133
|
+
const impl = (async (input: string | URL | Request) => {
|
|
134
|
+
urls.push(String(input));
|
|
135
|
+
return Response.json(releases, { status });
|
|
136
|
+
}) as typeof fetch;
|
|
137
|
+
return { impl, urls };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const rel = (tag_name: string, draft = false) => ({ tag_name, draft });
|
|
141
|
+
|
|
142
|
+
describe("resolveChannelVersion", () => {
|
|
143
|
+
it("picks the newest release candidate while it is newer than the newest stable", async () => {
|
|
144
|
+
const f = releasesFetch([rel("v0.12.5-rc.2"), rel("v0.12.5-rc.1"), rel("v0.12.4")]);
|
|
145
|
+
expect(await resolveChannelVersion("rc", f.impl)).toEqual({
|
|
146
|
+
ok: true,
|
|
147
|
+
version: "0.12.5-rc.2",
|
|
148
|
+
});
|
|
149
|
+
expect(f.urls).toEqual([
|
|
150
|
+
"https://api.github.com/repos/caelo-cms/caelo-cms/releases?per_page=100",
|
|
151
|
+
]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("picks the final release once it is out, never the older candidate", async () => {
|
|
155
|
+
const f = releasesFetch([rel("v0.12.5"), rel("v0.12.5-rc.1"), rel("v0.12.4")]);
|
|
156
|
+
expect(await resolveChannelVersion("rc", f.impl)).toEqual({ ok: true, version: "0.12.5" });
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("keeps rc away from betas, and lets beta take rc and stable releases", async () => {
|
|
160
|
+
const list = [rel("v0.13.0-beta.1"), rel("v0.12.5-rc.1"), rel("v0.12.4")];
|
|
161
|
+
expect(await resolveChannelVersion("rc", releasesFetch(list).impl)).toEqual({
|
|
162
|
+
ok: true,
|
|
163
|
+
version: "0.12.5-rc.1",
|
|
164
|
+
});
|
|
165
|
+
expect(await resolveChannelVersion("beta", releasesFetch(list).impl)).toEqual({
|
|
166
|
+
ok: true,
|
|
167
|
+
version: "0.13.0-beta.1",
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("ignores drafts, malformed tags and unknown pre-release channels", async () => {
|
|
172
|
+
const f = releasesFetch([
|
|
173
|
+
rel("v0.13.0-rc.1", true),
|
|
174
|
+
rel("not-a-version"),
|
|
175
|
+
rel("v0.13.0-nightly.1"),
|
|
176
|
+
{ draft: false },
|
|
177
|
+
rel("v0.12.4"),
|
|
178
|
+
]);
|
|
179
|
+
expect(await resolveChannelVersion("rc", f.impl)).toEqual({ ok: true, version: "0.12.4" });
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("reports GitHub failures and an empty answer instead of guessing", async () => {
|
|
183
|
+
const down = await resolveChannelVersion("rc", releasesFetch({}, 503).impl);
|
|
184
|
+
expect(down.ok).toBe(false);
|
|
185
|
+
expect(down.ok === false && down.reason).toContain("503");
|
|
186
|
+
const notList = await resolveChannelVersion("rc", releasesFetch({ message: "x" }).impl);
|
|
187
|
+
expect(notList.ok).toBe(false);
|
|
188
|
+
const none = await resolveChannelVersion("rc", releasesFetch([]).impl);
|
|
189
|
+
expect(none).toEqual({ ok: false, reason: "no rc or stable release on GitHub" });
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Release candidates on Google Cloud installs (#1558).
|
|
5
|
+
*
|
|
6
|
+
* A release candidate (`vX.Y.Z-rc.N`, any version with a pre-release part)
|
|
7
|
+
* is cut to test a release on a scratch install before any install is
|
|
8
|
+
* offered it. In Caelo's Google Cloud registry, the mirror Cloud Run pulls
|
|
9
|
+
* from, its images carry the marker tag `rc-<version>` and a cleanup rule
|
|
10
|
+
* deletes them once they are {@link RELEASE_CANDIDATE_RETENTION_DAYS} days
|
|
11
|
+
* old (docs/maintainer-ar-cleanup-policy.json; the registry's keep-10 rule
|
|
12
|
+
* can only hold one longer, never shorter). Cloud Run
|
|
13
|
+
* services keep running on the copy they imported at deploy time, but Cloud
|
|
14
|
+
* Run jobs pull their image each time they run, so from then on such an
|
|
15
|
+
* install loses its in-product updates (the upgrader's first stage runs the
|
|
16
|
+
* installed release's image), its converge job, its quality audit and its
|
|
17
|
+
* page captures. Installing or upgrading to one therefore warns and needs a
|
|
18
|
+
* confirmation.
|
|
19
|
+
*
|
|
20
|
+
* Self-hosted installs pull from GHCR, which keeps release candidates, so
|
|
21
|
+
* none of this applies to them.
|
|
22
|
+
*
|
|
23
|
+
* `--channel rc|beta` resolves here too: the pipeline publishes no moving
|
|
24
|
+
* channel tag, so a channel becomes an exact version before anything is
|
|
25
|
+
* resolved, and is then treated like `--version`.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { channelForVersion, compareSemver, type ReleaseChannel } from "./release-manifest.js";
|
|
29
|
+
import { canonicalReleaseTag } from "./upgrade/release-images.js";
|
|
30
|
+
|
|
31
|
+
/** Days a release candidate's images stay in the Google Cloud registry (the cleanup rule's `olderThan`). */
|
|
32
|
+
export const RELEASE_CANDIDATE_RETENTION_DAYS = 14;
|
|
33
|
+
|
|
34
|
+
/** The prefix of the marker tag a release candidate's images and manifest carry in that registry. */
|
|
35
|
+
export const RELEASE_CANDIDATE_TAG_PREFIX = "rc-";
|
|
36
|
+
|
|
37
|
+
/** The flag that confirms a release candidate where no prompt can ask (a script, CI). */
|
|
38
|
+
export const ACCEPT_RELEASE_CANDIDATE_FLAG = "--accept-release-candidate";
|
|
39
|
+
|
|
40
|
+
const PRERELEASE = /^v?\d+\.\d+\.\d+-[0-9A-Za-z.-]+$/;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether `version` is a pre-release (`0.12.5-rc.1`, `v0.13.0-beta.2`): the
|
|
44
|
+
* versions the release pipeline publishes as release candidates.
|
|
45
|
+
*/
|
|
46
|
+
export function isPrereleaseVersion(version: string): boolean {
|
|
47
|
+
return PRERELEASE.test(version);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** What the operator is about to do with a release candidate. */
|
|
51
|
+
export type ReleaseCandidateAction = "install" | "upgrade";
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Why a release candidate is for test installs only, in the words the CLI
|
|
55
|
+
* prints before it asks.
|
|
56
|
+
*
|
|
57
|
+
* @param version - the release candidate, with or without a leading `v`.
|
|
58
|
+
*/
|
|
59
|
+
export function releaseCandidateWarning(version: string): string[] {
|
|
60
|
+
const v = version.replace(/^v/, "");
|
|
61
|
+
return [
|
|
62
|
+
`v${v} is a release candidate, meant for test installs only.`,
|
|
63
|
+
`Caelo's Google Cloud registry keeps a release candidate's images for ${RELEASE_CANDIDATE_RETENTION_DAYS} days after it was published, then deletes them.`,
|
|
64
|
+
"The Cloud Run services keep running on their own copy of the image, but the install's Cloud Run jobs (update, converge, quality audit, page capture) pull their image each time they run.",
|
|
65
|
+
"From then on the install can no longer update from Settings → Updates or audit a Stage; only an upgrade from a terminal moves it on to a newer release.",
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The side effects of {@link confirmReleaseCandidate}, injectable for tests. */
|
|
70
|
+
export interface ReleaseCandidatePrompt {
|
|
71
|
+
/** Show the warning lines. */
|
|
72
|
+
readonly warn: (lines: readonly string[]) => void;
|
|
73
|
+
/** Ask a yes/no question (default no); false also for a cancelled prompt. */
|
|
74
|
+
readonly confirm: (message: string) => Promise<boolean>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** How {@link confirmReleaseCandidate} decided. */
|
|
78
|
+
export type ReleaseCandidateDecision =
|
|
79
|
+
| { readonly ok: true }
|
|
80
|
+
| {
|
|
81
|
+
readonly ok: false;
|
|
82
|
+
/** `declined`: the operator said no. `needs-flag`: no prompt could ask. */
|
|
83
|
+
readonly reason: "declined" | "needs-flag";
|
|
84
|
+
readonly message: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Let a release candidate through only once the operator confirmed it: in a
|
|
89
|
+
* terminal by answering the prompt, elsewhere by passing
|
|
90
|
+
* {@link ACCEPT_RELEASE_CANDIDATE_FLAG}. A stable version passes untouched.
|
|
91
|
+
*
|
|
92
|
+
* @param opts.interactive - whether a prompt can be shown (a TTY, and no `--non-interactive`).
|
|
93
|
+
* @param opts.accepted - whether {@link ACCEPT_RELEASE_CANDIDATE_FLAG} was passed.
|
|
94
|
+
*/
|
|
95
|
+
export async function confirmReleaseCandidate(
|
|
96
|
+
opts: {
|
|
97
|
+
readonly version: string;
|
|
98
|
+
readonly action: ReleaseCandidateAction;
|
|
99
|
+
readonly interactive: boolean;
|
|
100
|
+
readonly accepted: boolean;
|
|
101
|
+
},
|
|
102
|
+
prompt: ReleaseCandidatePrompt,
|
|
103
|
+
): Promise<ReleaseCandidateDecision> {
|
|
104
|
+
if (!isPrereleaseVersion(opts.version)) return { ok: true };
|
|
105
|
+
const v = opts.version.replace(/^v/, "");
|
|
106
|
+
prompt.warn(releaseCandidateWarning(v));
|
|
107
|
+
if (opts.accepted) return { ok: true };
|
|
108
|
+
const verb = opts.action === "install" ? "install" : "upgrade to";
|
|
109
|
+
if (!opts.interactive) {
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
reason: "needs-flag",
|
|
113
|
+
message: `Nothing was changed: v${v} is a release candidate. To ${verb} it without a prompt, pass ${ACCEPT_RELEASE_CANDIDATE_FLAG}.`,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const question =
|
|
117
|
+
opts.action === "install"
|
|
118
|
+
? `Install release candidate v${v} anyway?`
|
|
119
|
+
: `Upgrade to release candidate v${v} anyway?`;
|
|
120
|
+
if (await prompt.confirm(question)) return { ok: true };
|
|
121
|
+
return {
|
|
122
|
+
ok: false,
|
|
123
|
+
reason: "declined",
|
|
124
|
+
message: `Nothing was changed. For an install you keep, ${verb} a stable release.`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The channels `--channel` names, from the most to the least stable. */
|
|
129
|
+
const CHANNEL_ORDER: readonly ReleaseChannel[] = ["stable", "rc", "beta", "alpha"];
|
|
130
|
+
|
|
131
|
+
/** Caelo's GitHub releases, newest first (one page: the newest stable release is always on it). */
|
|
132
|
+
const RELEASES_URL = "https://api.github.com/repos/caelo-cms/caelo-cms/releases?per_page=100";
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The exact version `--channel <channel>` installs: the newest release on
|
|
136
|
+
* that channel or a more stable one, so an rc subscriber whose release
|
|
137
|
+
* candidate became final gets the final release, never the older candidate.
|
|
138
|
+
* Read from the GitHub releases (the registry has no moving channel tag);
|
|
139
|
+
* the tags are rebuilt from a constant alphabet before anything uses them.
|
|
140
|
+
*
|
|
141
|
+
* @example await resolveChannelVersion("rc") // → { ok: true, version: "0.12.5-rc.1" }
|
|
142
|
+
*/
|
|
143
|
+
export async function resolveChannelVersion(
|
|
144
|
+
channel: "rc" | "beta",
|
|
145
|
+
fetchImpl: typeof fetch = fetch,
|
|
146
|
+
): Promise<{ ok: true; version: string } | { ok: false; reason: string }> {
|
|
147
|
+
const allowed = new Set(CHANNEL_ORDER.slice(0, CHANNEL_ORDER.indexOf(channel) + 1));
|
|
148
|
+
let releases: unknown;
|
|
149
|
+
try {
|
|
150
|
+
const res = await fetchImpl(RELEASES_URL, {
|
|
151
|
+
headers: { Accept: "application/vnd.github+json" },
|
|
152
|
+
});
|
|
153
|
+
if (!res.ok) return { ok: false, reason: `GitHub API HTTP ${res.status} ${res.statusText}` };
|
|
154
|
+
releases = await res.json();
|
|
155
|
+
} catch (e) {
|
|
156
|
+
return { ok: false, reason: e instanceof Error ? e.message : String(e) };
|
|
157
|
+
}
|
|
158
|
+
if (!Array.isArray(releases)) return { ok: false, reason: "GitHub returned no release list" };
|
|
159
|
+
let newest: string | null = null;
|
|
160
|
+
for (const r of releases as { tag_name?: unknown; draft?: unknown }[]) {
|
|
161
|
+
if (r.draft === true || typeof r.tag_name !== "string") continue;
|
|
162
|
+
const tag = canonicalReleaseTag(r.tag_name);
|
|
163
|
+
const version = tag?.replace(/^v/, "") ?? null;
|
|
164
|
+
if (!version) continue;
|
|
165
|
+
const onChannel = channelForVersion(version);
|
|
166
|
+
if (!onChannel || !allowed.has(onChannel)) continue;
|
|
167
|
+
if (newest === null || compareSemver(version, newest) > 0) newest = version;
|
|
168
|
+
}
|
|
169
|
+
return newest
|
|
170
|
+
? { ok: true, version: newest }
|
|
171
|
+
: { ok: false, reason: `no ${channel} or stable release on GitHub` };
|
|
172
|
+
}
|