Skip to content

Commit

Permalink
Added createGithubReleases input option (defaults to true) to con…
Browse files Browse the repository at this point in the history
…trol 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>
  • Loading branch information
akphi and Andarist authored Jan 23, 2022
1 parent f4afbea commit 5c0997b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-frogs-knock.md
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ inputs:
description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
required: false
default: true
createGithubReleases:
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
required: false
default: true
outputs:
published:
description: A boolean value to indicate whether a publishing is happened or not
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
const result = await runPublish({
script: publishScript,
githubToken,
createGithubReleases: core.getBooleanInput("createGithubReleases"),
});

if (result.published) {
Expand Down
30 changes: 18 additions & 12 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const createRelease = async (
type PublishOptions = {
script: string;
githubToken: string;
createGithubReleases: boolean;
cwd?: string;
};

Expand All @@ -68,6 +69,7 @@ type PublishResult =
export async function runPublish({
script,
githubToken,
createGithubReleases,
cwd = process.cwd(),
}: PublishOptions): Promise<PublishResult> {
let octokit = github.getOctokit(githubToken);
Expand Down Expand Up @@ -104,14 +106,16 @@ export async function runPublish({
releasedPackages.push(pkg);
}

await Promise.all(
releasedPackages.map((pkg) =>
createRelease(octokit, {
pkg,
tagName: `${pkg.packageJson.name}@${pkg.packageJson.version}`,
})
)
);
if (createGithubReleases) {
await Promise.all(
releasedPackages.map((pkg) =>
createRelease(octokit, {
pkg,
tagName: `${pkg.packageJson.name}@${pkg.packageJson.version}`,
})
)
);
}
} else {
if (packages.length === 0) {
throw new Error(
Expand All @@ -127,10 +131,12 @@ export async function runPublish({

if (match) {
releasedPackages.push(pkg);
await createRelease(octokit, {
pkg,
tagName: `v${pkg.packageJson.version}`,
});
if (createGithubReleases) {
await createRelease(octokit, {
pkg,
tagName: `v${pkg.packageJson.version}`,
});
}
break;
}
}
Expand Down

0 comments on commit 5c0997b

Please sign in to comment.