Skip to content

Commit

Permalink
feat: add release-it-args option (#392)
Browse files Browse the repository at this point in the history
## PR Checklist

- [x] Addresses an existing open issue: fixes #390
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/release-it-action/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/release-it-action/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Adds a `release-it-args` option.

💖
  • Loading branch information
JoshuaKGoldberg authored Jan 6, 2025
1 parent 5f7c163 commit 9ea94dd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -88,6 +89,7 @@ await releaseItAction({
gitUserName: "YourUsername",
npmToken: process.env.NPM_TOKEN,
owner: "YourUsername",
releaseItArgs: "--preRelease=beta",
repo: "your-repository",
});
```
Expand Down
2 changes: 2 additions & 0 deletions src/action/runReleaseItAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe("runReleaseItAction", () => {
"githubToken": "mock-github-token",
"npmToken": "mock-npm-token",
"owner": "context-owner",
"releaseItArgs": undefined,
"repo": "context-repo",
"skipBranchProtections": false,
},
Expand All @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions src/action/runReleaseItAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
});
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ReleaseItActionOptions {
gitUserName: string;
npmToken: string;
owner: string;
releaseItArgs?: string;
repo: string;
skipBranchProtections?: boolean;
}
Expand All @@ -26,6 +27,7 @@ export async function releaseItAction({
gitUserName,
npmToken,
owner,
releaseItArgs,
repo,
skipBranchProtections,
}: ReleaseItActionOptions) {
Expand Down Expand Up @@ -66,7 +68,7 @@ export async function releaseItAction({
requestData: commonRequestData,
});

await runReleaseIt();
await runReleaseIt(releaseItArgs);

await recreateProtections({
commonRequestData,
Expand Down
23 changes: 23 additions & 0 deletions src/steps/runReleaseIt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
6 changes: 4 additions & 2 deletions src/steps/runReleaseIt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.`);
}
Expand Down

0 comments on commit 9ea94dd

Please sign in to comment.