diff --git a/README.md b/README.md index 62e7dd38..57ade254 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ There are also sub-actions hosted in this repository. Check out their respective ### Outputs - published - A boolean value to indicate whether a publishing has happened or not -- publishedPackages - A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]` +- publish-output - The path to the Changesets publish output file in NDJSON format ### Example workflow diff --git a/action.yml b/action.yml index 8f0d342e..26e060c1 100644 --- a/action.yml +++ b/action.yml @@ -52,10 +52,9 @@ inputs: default: true outputs: published: - description: A boolean value to indicate whether a publishing is happened or not - published-packages: - description: > - A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]` + description: A boolean value to indicate whether any release was published + publish-output: + description: The path to the changesets publish output file in NDJSON format has-changesets: description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality. pr-number: diff --git a/publish/action.yml b/publish/action.yml index 809c5509..ea2da08a 100644 --- a/publish/action.yml +++ b/publish/action.yml @@ -26,10 +26,9 @@ inputs: default: true outputs: published: - description: "A boolean value to indicate whether a publishing has happened or not" - published-packages: - description: > - A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]` + description: A boolean value to indicate whether any release was published + output: + description: The path to the Changesets publish output file in NDJSON format branding: icon: package color: blue diff --git a/src/index.ts b/src/index.ts index cde1ebfa..0306e9c6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -68,7 +68,6 @@ import { let hasPublishScript = !!publishScript; core.setOutput("published", "false"); - core.setOutput("published-packages", "[]"); core.setOutput("has-changesets", String(hasChangesets)); switch (true) { @@ -146,19 +145,17 @@ import { cwd, }); - if (result.published) { - core.setOutput("published", "true"); - core.setOutput( - "published-packages", - JSON.stringify(result.publishedPackages), - ); - } + core.setOutput( + "published", + result.releases.length > 0 ? "true" : "false", + ); + core.setOutput("publish-output", result.output); if (result.exitCode !== 0) { core.error( `Publish command exited with code ${result.exitCode}${ - result.published - ? `, but some packages were published: ${result.publishedPackages + result.releases.length + ? `, but some packages were published: ${result.releases .map((p) => `${p.name}@${p.version}`) .join(", ")}` : "" diff --git a/src/publish/index.ts b/src/publish/index.ts index 15bf8ab3..41414d2f 100644 --- a/src/publish/index.ts +++ b/src/publish/index.ts @@ -53,21 +53,14 @@ async function main() { fromPackDir, }); - if (result.published) { - core.setOutput("published", "true"); - core.setOutput( - "published-packages", - JSON.stringify(result.publishedPackages), - ); - } else { - core.setOutput("published", "false"); - } + core.setOutput("published", result.releases.length > 0 ? "true" : "false"); + core.setOutput("output", result.output); if (result.exitCode !== 0) { throw new Error( `Publish command exited with code ${result.exitCode}${ - result.published - ? `, but some packages were published: ${result.publishedPackages + result.releases.length + ? `, but some packages were published: ${result.releases .map((p) => `${p.name}@${p.version}`) .join(", ")}` : "" diff --git a/src/run.ts b/src/run.ts index 6f34e6b7..c4834149 100644 --- a/src/run.ts +++ b/src/run.ts @@ -72,23 +72,19 @@ type PublishOptions = { cwd: string; }; -type PublishedPackage = { name: string; version: string }; +type PackageRelease = { name: string; version: string }; + type ChangesetsOutputEvent = { type: "git-tag"; tag: string; packageName: string; }; -type PublishResult = - | { - published: true; - publishedPackages: PublishedPackage[]; - exitCode: number; - } - | { - published: false; - exitCode: number; - }; +type PublishResult = { + releases: PackageRelease[]; + output: string; + exitCode: number; +}; function isObject(value: unknown) { return typeof value === "object" && value !== null; @@ -227,18 +223,14 @@ export async function runPublish({ ); } - if (releases.length) { - return { - published: true, - publishedPackages: releases.map(({ pkg }) => ({ - name: pkg.packageJson.name, - version: pkg.packageJson.version, - })), - exitCode: changesetPublishOutput.exitCode, - }; - } - - return { published: false, exitCode: changesetPublishOutput.exitCode }; + return { + releases: releases.map(({ pkg }) => ({ + name: pkg.packageJson.name, + version: pkg.packageJson.version, + })), + output: outputFile, + exitCode: changesetPublishOutput.exitCode, + }; } type GetMessageOptions = {