Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add release-it-args option #392

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading