diff --git a/.changeset/famous-cooks-learn.md b/.changeset/famous-cooks-learn.md new file mode 100644 index 00000000..80816bc7 --- /dev/null +++ b/.changeset/famous-cooks-learn.md @@ -0,0 +1,5 @@ +--- +"@changesets/action": patch +--- + +Updated the output to add GitHub release details diff --git a/README.md b/README.md index 2bd15d31..23c8ee01 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This action for [Changesets](https://github.com/atlassian/changesets) creates a ### Outputs - published - A boolean value to indicate whether a publishing is 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"}]` +- publishedPackages - A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0", "githubRelease": {"id":123, "upload_url": "..."}}, {"name": "@xx/xy", "version": "0.8.9"}]`. `githubRelease` is the Github release object with `id` and `upload_url` if `createGithubReleases` is `true` ### Example workflow: diff --git a/action.yml b/action.yml index 36dfeafb..334c685d 100644 --- a/action.yml +++ b/action.yml @@ -33,7 +33,7 @@ outputs: description: A boolean value to indicate whether a publishing is happened or not publishedPackages: 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"}]` + A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0", "githubRelease": {"id":123, "upload_url": "..."}}, {"name": "@xx/xy", "version": "0.8.9"}]` hasChangesets: description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality. pullRequestNumber: diff --git a/src/run.ts b/src/run.ts index 67d70f09..75118c41 100644 --- a/src/run.ts +++ b/src/run.ts @@ -76,13 +76,15 @@ const createRelease = async ( ); } - await octokit.rest.repos.createRelease({ + const { data: release } = await octokit.rest.repos.createRelease({ name: tagName, tag_name: tagName, body: changelogEntry.content, prerelease: pkg.packageJson.version.includes("-"), ...github.context.repo, }); + + return release; } catch (err) { // if we can't find a changelog, the user has probably disabled changelogs if ( @@ -114,6 +116,11 @@ type PublishResult = published: false; }; +type GitHubRelease = { + id: number; + upload_url: string; +}; + export async function runPublish({ script, githubToken, @@ -133,7 +140,7 @@ export async function runPublish({ await gitUtils.pushTags(); let { packages, tool } = await getPackages(cwd); - let releasedPackages: Package[] = []; + let releasedPackages: (Package & { githubRelease?: GitHubRelease })[] = []; if (tool !== "root") { let newTagRegex = /New tag:\s+(@[^/]+\/[^@]+|[^/]+)@([^\s]+)/; @@ -156,13 +163,23 @@ export async function runPublish({ } if (createGithubReleases) { - await Promise.all( - releasedPackages.map((pkg) => - createRelease(octokit, { + releasedPackages = await Promise.all( + releasedPackages.map(async (pkg) => { + const release = await createRelease(octokit, { pkg, tagName: `${pkg.packageJson.name}@${pkg.packageJson.version}`, - }) - ) + }); + + return { + ...pkg, + githubRelease: release + ? { + id: release.id, + upload_url: release.upload_url, + } + : undefined, + }; + }) ); } } else { @@ -179,12 +196,21 @@ export async function runPublish({ let match = line.match(newTagRegex); if (match) { - releasedPackages.push(pkg); if (createGithubReleases) { - await createRelease(octokit, { + const release = await createRelease(octokit, { pkg, tagName: `v${pkg.packageJson.version}`, }); + const githubRelease = release + ? { + id: release.id, + upload_url: release.upload_url, + } + : undefined; + + releasedPackages.push({ ...pkg, githubRelease }); + } else { + releasedPackages.push(pkg); } break; } @@ -197,6 +223,7 @@ export async function runPublish({ publishedPackages: releasedPackages.map((pkg) => ({ name: pkg.packageJson.name, version: pkg.packageJson.version, + githubRelease: pkg.githubRelease, })), }; }