Skip to content

Commit 8311014

Browse files
authored
Merge branch 'main' into changeset-release/main
2 parents baa878c + 16bc1b4 commit 8311014

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

apps/cli/tests/unit/scripts/release-alpha-train.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,64 @@ describe("release-alpha-train script", () => {
192192
});
193193
});
194194

195+
it("blocks GoReleaser when Changesets did not publish npm packages", async () => {
196+
const cwd = await fixtureRepo();
197+
198+
await expect(
199+
releaseAlphaTrain.inspectAlphaReleaseTrain({
200+
cwd,
201+
execFile: commandMock(),
202+
published: false,
203+
remote: false,
204+
}),
205+
).resolves.toMatchObject({
206+
shouldComplete: false,
207+
skipReason: "npm publish did not run",
208+
});
209+
});
210+
211+
it("rejects prepare when Changesets did not publish npm packages", async () => {
212+
const cwd = await fixtureRepo();
213+
214+
await expect(
215+
releaseAlphaTrain.prepareAlphaReleaseTrain({
216+
cwd,
217+
execFile: commandMock(),
218+
published: false,
219+
}),
220+
).rejects.toThrow("alpha release train is not ready to complete: npm publish did not run");
221+
});
222+
223+
it("allows GoReleaser recovery when npm did not publish but the release tag exists", async () => {
224+
const cwd = await fixtureRepo();
225+
226+
const result = await releaseAlphaTrain.prepareAlphaReleaseTrain({
227+
cwd,
228+
execFile: commandMock({ tagCommit: "head-commit" }),
229+
published: false,
230+
});
231+
232+
expect(result.shouldCreateTag).toBe(false);
233+
expect(result.shouldRunGoreleaser).toBe(true);
234+
expect(result.shouldUpdateRelease).toBe(true);
235+
});
236+
237+
it("allows completion after Changesets publishes npm packages", async () => {
238+
const cwd = await fixtureRepo();
239+
240+
await expect(
241+
releaseAlphaTrain.inspectAlphaReleaseTrain({
242+
cwd,
243+
execFile: commandMock(),
244+
published: true,
245+
remote: false,
246+
}),
247+
).resolves.toMatchObject({
248+
shouldComplete: true,
249+
skipReason: "",
250+
});
251+
});
252+
195253
it("prunes empty changesets before Changesets decides whether to publish", async () => {
196254
const cwd = await fixtureRepo({
197255
changesets: {

scripts/release-alpha-train.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export async function inspectAlphaReleaseTrain(options = {}) {
8787
const readFileFn = options.readFile ?? readFile;
8888
const readdirFn = options.readdir ?? readdir;
8989
const execFileFn = options.execFile ?? execFile;
90+
const publishedWasSpecified = options.published !== undefined;
9091
const published = normalizeBoolean(options.published);
9192
const remote = options.remote === undefined ? true : normalizeBoolean(options.remote);
9293

@@ -117,6 +118,28 @@ export async function inspectAlphaReleaseTrain(options = {}) {
117118
const tagExists = Boolean(tagCommit);
118119
const tagMatchesHead = tagCommit === headCommit;
119120

121+
if (publishedWasSpecified && !published && !tagExists) {
122+
return {
123+
version,
124+
tagName,
125+
title,
126+
image,
127+
packages,
128+
activeChangesets,
129+
headCommit,
130+
tagCommit,
131+
tagExists,
132+
tagMatchesHead,
133+
releaseExists: false,
134+
imageExists: false,
135+
shouldComplete: false,
136+
shouldCreateTag: false,
137+
shouldRunGoreleaser: false,
138+
shouldUpdateRelease: false,
139+
skipReason: "npm publish did not run",
140+
};
141+
}
142+
120143
if (!published && activeChangesets.length > 0) {
121144
return {
122145
version,

0 commit comments

Comments
 (0)