diff --git a/README.md b/README.md index 86e88f6b..84d961b3 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ permissions: | `github-token` | `string` | `${GITHUB_TOKEN}` | GitHub token (PAT) with _repo_ and _workflow_ permissions. | | `npm-token` | `string` | `${NPM_TOKEN}` | npm access token with the _automation_ role. | | `skip-branch-protections` | `boolean` | `false` | Whether to skip deleting and recreating branch protections. | +| `release-it-args` | `string` | `""` | Any arbitrary arguments to pass to `npx release-it --verbose`. | ### Node API @@ -88,6 +89,7 @@ await releaseItAction({ gitUserName: "YourUsername", npmToken: process.env.NPM_TOKEN, owner: "YourUsername", + releaseItArgs: "--preRelease=beta", repo: "your-repository", }); ``` diff --git a/src/action/runReleaseItAction.test.ts b/src/action/runReleaseItAction.test.ts index 70de9c67..c25a13ce 100644 --- a/src/action/runReleaseItAction.test.ts +++ b/src/action/runReleaseItAction.test.ts @@ -52,6 +52,7 @@ describe("runReleaseItAction", () => { "githubToken": "mock-github-token", "npmToken": "mock-npm-token", "owner": "context-owner", + "releaseItArgs": undefined, "repo": "context-repo", "skipBranchProtections": false, }, @@ -75,6 +76,7 @@ describe("runReleaseItAction", () => { "githubToken": "mock-github-token", "npmToken": "mock-npm-token", "owner": "context-owner", + "releaseItArgs": "mock-release-it-args", "repo": "context-repo", "skipBranchProtections": false, }, diff --git a/src/action/runReleaseItAction.ts b/src/action/runReleaseItAction.ts index 602b1c12..6d2d6f17 100644 --- a/src/action/runReleaseItAction.ts +++ b/src/action/runReleaseItAction.ts @@ -16,6 +16,7 @@ export async function runReleaseItAction(context: typeof github.context) { gitUserName, npmToken: getTokenInput("npm-token", "NPM_TOKEN"), owner: context.repo.owner, + releaseItArgs: core.getInput("release-it-args"), repo: context.repo.repo, skipBranchProtections: core.getBooleanInput("skip-branch-protections"), }); diff --git a/src/index.ts b/src/index.ts index 78f5ef03..7df98667 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ export interface ReleaseItActionOptions { gitUserName: string; npmToken: string; owner: string; + releaseItArgs?: string; repo: string; skipBranchProtections?: boolean; } @@ -26,6 +27,7 @@ export async function releaseItAction({ gitUserName, npmToken, owner, + releaseItArgs, repo, skipBranchProtections, }: ReleaseItActionOptions) { @@ -66,7 +68,7 @@ export async function releaseItAction({ requestData: commonRequestData, }); - await runReleaseIt(); + await runReleaseIt(releaseItArgs); await recreateProtections({ commonRequestData, diff --git a/src/steps/runReleaseIt.test.ts b/src/steps/runReleaseIt.test.ts index fa49a892..d72d8daf 100644 --- a/src/steps/runReleaseIt.test.ts +++ b/src/steps/runReleaseIt.test.ts @@ -100,4 +100,27 @@ describe("runReleaseIt", () => { expect(mockError).not.toHaveBeenCalled(); expect(mockSetFailed).not.toHaveBeenCalled(); }); + + it("does not releaseItArgs when provided as an empty string", async () => { + mock$$.mockResolvedValue({ exitCode: 0 }); + + await runReleaseIt(""); + + expect(mock$$).toHaveBeenCalledWith(["npx release-it --verbose", ""], ""); + expect(mockError).not.toHaveBeenCalled(); + expect(mockSetFailed).not.toHaveBeenCalled(); + }); + + it("includes releaseItArgs when provided as a non-empty string", async () => { + mock$$.mockResolvedValue({ exitCode: 0 }); + + await runReleaseIt("major --preRelease=beta"); + + expect(mock$$).toHaveBeenCalledWith( + ["npx release-it --verbose", ""], + " major --preRelease=beta", + ); + expect(mockError).not.toHaveBeenCalled(); + expect(mockSetFailed).not.toHaveBeenCalled(); + }); }); diff --git a/src/steps/runReleaseIt.ts b/src/steps/runReleaseIt.ts index 848c82da..0b180148 100644 --- a/src/steps/runReleaseIt.ts +++ b/src/steps/runReleaseIt.ts @@ -3,10 +3,12 @@ import * as core from "@actions/core"; import { $$ } from "../execa.js"; import { tryCatchInfoAction } from "../tryCatchInfoAction.js"; -export async function runReleaseIt() { +export async function runReleaseIt(releaseItArgs?: string) { + const args = releaseItArgs ? ` ${releaseItArgs}` : ""; + await tryCatchInfoAction("running release-it", async () => { try { - const { exitCode, stderr } = await $$`npx release-it --verbose`; + const { exitCode, stderr } = await $$`npx release-it --verbose${args}`; if (exitCode || stderr) { throw new Error(stderr || `Exit code ${exitCode.toString()}.`); }