diff --git a/semantic-release/src/index.ts b/semantic-release/src/index.ts index a33c7ab..211cd6d 100644 --- a/semantic-release/src/index.ts +++ b/semantic-release/src/index.ts @@ -132,11 +132,13 @@ export async function main() { ); if (result) { const { lastRelease, nextRelease } = result; - setOutput(OUTPUTS.last_release_version, lastRelease.version); - setOutput( - OUTPUTS.last_release_major_version, - semver.major(lastRelease.version), - ); + if (lastRelease.version) { + setOutput(OUTPUTS.last_release_version, lastRelease.version); + setOutput( + OUTPUTS.last_release_major_version, + semver.major(lastRelease.version), + ); + } if (nextRelease) { setOutput(OUTPUTS.new_release_published, "true"); setOutput(OUTPUTS.new_release_type, nextRelease.type); diff --git a/semantic-release/test/index.test.ts b/semantic-release/test/index.test.ts index 408b3e9..f9695ac 100644 --- a/semantic-release/test/index.test.ts +++ b/semantic-release/test/index.test.ts @@ -29,9 +29,9 @@ jest.unstable_mockModule("@actions/core", () => ({ setOutput: setOutputMock, })); -const mockRelease = ( - overrides: Partial>> = {}, -) => { +type SemanticRelease = Awaited>; + +const mockRelease = (overrides: Partial = {}) => { const lastRelease = { channels: [], gitHead: "test", @@ -147,6 +147,44 @@ describe("semantic-release", () => { `); }); + test("doesn't set last release outputs if there is no last release", async () => { + mockNpmInstall(); + mockRelease({ lastRelease: false } as unknown as SemanticRelease); + await callAction(); + expect(setOutputMock.mock.calls).toMatchInlineSnapshot(` + [ + [ + "new-release-published", + "true", + ], + [ + "new-release-type", + "prerelease", + ], + [ + "new-release-notes", + "New Release notes", + ], + [ + "new-release-version", + "1.2.3-test", + ], + [ + "new-release-major-version", + 1, + ], + [ + "new-release-minor-version", + 2, + ], + [ + "new-release-patch-version", + 3, + ], + ] + `); + }); + test("runs semantic release with the extra options", async () => { process.env.SEMANTIC_ACTION_BRANCHES = "test"; process.env.SEMANTIC_ACTION_CI = "true";