Added createGithubReleases input option (defaults to true) to control whether to create Github releases during publish or not (#130)

* allow skipping creation of Github releases

* fixes for PR review

* minor improvements

* add changeset

* nits

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
This commit is contained in:
An Phi
2022-01-23 11:07:42 +01:00
committed by GitHub
co-authored by Mateusz Burzyński
parent f4afbea27e
commit 5c0997b25e
4 changed files with 28 additions and 12 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@changesets/action": minor
---
Added `createGithubReleases` input option (defaults to `true`) to control whether to create Github releases during publish or not.
+4
View File
@@ -21,6 +21,10 @@ inputs:
description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true` description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
required: false required: false
default: true default: true
createGithubReleases:
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
required: false
default: true
outputs: outputs:
published: published:
description: A boolean value to indicate whether a publishing is happened or not description: A boolean value to indicate whether a publishing is happened or not
+1
View File
@@ -78,6 +78,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
const result = await runPublish({ const result = await runPublish({
script: publishScript, script: publishScript,
githubToken, githubToken,
createGithubReleases: core.getBooleanInput("createGithubReleases"),
}); });
if (result.published) { if (result.published) {
+6
View File
@@ -51,6 +51,7 @@ const createRelease = async (
type PublishOptions = { type PublishOptions = {
script: string; script: string;
githubToken: string; githubToken: string;
createGithubReleases: boolean;
cwd?: string; cwd?: string;
}; };
@@ -68,6 +69,7 @@ type PublishResult =
export async function runPublish({ export async function runPublish({
script, script,
githubToken, githubToken,
createGithubReleases,
cwd = process.cwd(), cwd = process.cwd(),
}: PublishOptions): Promise<PublishResult> { }: PublishOptions): Promise<PublishResult> {
let octokit = github.getOctokit(githubToken); let octokit = github.getOctokit(githubToken);
@@ -104,6 +106,7 @@ export async function runPublish({
releasedPackages.push(pkg); releasedPackages.push(pkg);
} }
if (createGithubReleases) {
await Promise.all( await Promise.all(
releasedPackages.map((pkg) => releasedPackages.map((pkg) =>
createRelease(octokit, { createRelease(octokit, {
@@ -112,6 +115,7 @@ export async function runPublish({
}) })
) )
); );
}
} else { } else {
if (packages.length === 0) { if (packages.length === 0) {
throw new Error( throw new Error(
@@ -127,10 +131,12 @@ export async function runPublish({
if (match) { if (match) {
releasedPackages.push(pkg); releasedPackages.push(pkg);
if (createGithubReleases) {
await createRelease(octokit, { await createRelease(octokit, {
pkg, pkg,
tagName: `v${pkg.packageJson.version}`, tagName: `v${pkg.packageJson.version}`,
}); });
}
break; break;
} }
} }