Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/silent-tips-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/action": patch
---

Fix the `/version` subaction to not crash on missing `pr-base-branch` input. This input is meant to be optional.
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import fs from "node:fs/promises";
import path from "node:path";
import * as core from "@actions/core";
import { Git } from "./git.ts";
import { setupOctokit } from "./octokit.ts";
import readChangesetState from "./readChangesetState.ts";
import { runPublish, runVersion } from "./run.ts";
import { fileExists } from "./utils.ts";

const getOptionalInput = (name: string) => core.getInput(name) || undefined;
import { fileExists, getOptionalInput } from "./utils.ts";

(async () => {
// to maintain compatibility with workflows created before github-token input was introduced
Expand Down
8 changes: 6 additions & 2 deletions src/pack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import os from "node:os";
import path from "node:path";
import artifact from "@actions/artifact";
import * as core from "@actions/core";
import { downloadArtifact, execChangesetsCli } from "../utils.ts";
import {
downloadArtifact,
execChangesetsCli,
getOptionalInput,
} from "../utils.ts";

try {
await main();
Expand All @@ -12,7 +16,7 @@ try {
}

async function main() {
const publishPlanArtifactId = core.getInput("publish-plan-artifact-id");
const publishPlanArtifactId = getOptionalInput("publish-plan-artifact-id");

// If the user needs to change the cwd, set `working-directory` in the step instead
const cwd = process.cwd();
Expand Down
7 changes: 4 additions & 3 deletions src/pr-comment/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import { getOptionalInput, getRequiredInput } from "../utils.ts";

type Octokit = ReturnType<typeof github.getOctokit>;
type CreateCommentParams = NonNullable<
Expand All @@ -23,9 +24,9 @@ async function main() {
);
}

const githubToken = core.getInput("github-token", { required: true });
const body = core.getInput("body", { required: true });
const updateId = core.getInput("update-id");
const githubToken = getRequiredInput("github-token");
const body = getRequiredInput("body");
const updateId = getOptionalInput("update-id");

const commentMarker = updateId ? getCommentMarker(updateId) : null;
const commentBody = commentMarker ? `${commentMarker}\n\n${body}` : body;
Expand Down
12 changes: 8 additions & 4 deletions src/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import * as core from "@actions/core";
import { Git } from "../git.ts";
import { setupOctokit } from "../octokit.ts";
import { runPublish } from "../run.ts";
import { downloadArtifact } from "../utils.ts";
import {
downloadArtifact,
getOptionalInput,
getRequiredInput,
} from "../utils.ts";

try {
await main();
Expand All @@ -13,9 +17,9 @@ try {
}

async function main() {
const githubToken = core.getInput("github-token", { required: true });
const script = core.getInput("script");
const packDirArtifactId = core.getInput("pack-dir-artifact-id");
const githubToken = getRequiredInput("github-token");
const script = getOptionalInput("script");
const packDirArtifactId = getOptionalInput("pack-dir-artifact-id");
const createGithubReleases = core.getBooleanInput("create-github-releases");

// If the user needs to change the cwd, set `working-directory` in the step instead
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from "node:fs/promises";
import { createRequire } from "node:module";
import path from "node:path";
import artifact from "@actions/artifact";
import * as core from "@actions/core";
import {
exec,
getExecOutput,
Expand Down Expand Up @@ -123,6 +124,17 @@ export function fileExists(filePath: string) {
);
}

export function getOptionalInput(name: string) {
// normalize empty string default return value of `core.getInput` to undefined
return core.getInput(name) || undefined;
}

export function getRequiredInput(name: string) {
// it's just a small utility wrapper, mainly introduced for usage parity with our custom `getOptionalInput`
// note: `core.getBooleanInput` gets used directly as it already normalizes the return value nicely
return core.getInput(name, { required: true });
}

function resolveChangesetsCli(cwd: string) {
return require.resolve("@changesets/cli/bin.js", {
paths: [cwd],
Expand Down
15 changes: 8 additions & 7 deletions src/version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from "@actions/core";
import { Git } from "../git.ts";
import { setupOctokit } from "../octokit.ts";
import { runVersion } from "../run.ts";
import { getOptionalInput, getRequiredInput } from "../utils.ts";

try {
await main();
Expand All @@ -10,13 +11,13 @@ try {
}

async function main() {
const githubToken = core.getInput("github-token", { required: true });
const script = core.getInput("script");
const commitMessage = core.getInput("commit-message", { required: true });
const prTitle = core.getInput("pr-title", { required: true });
const prDraft = core.getInput("pr-draft") || undefined;
const prBaseBranch = core.getInput("pr-base-branch");
const commitMode = core.getInput("commit-mode") || "git-cli";
const githubToken = getRequiredInput("github-token");
const script = getOptionalInput("script");
const commitMessage = getRequiredInput("commit-message");
const prTitle = getRequiredInput("pr-title");
const prDraft = getOptionalInput("pr-draft");
const prBaseBranch = getOptionalInput("pr-base-branch");
const commitMode = getOptionalInput("commit-mode") ?? "git-cli";
const setupGitUser = core.getBooleanInput("setup-git-user");

// Validations
Expand Down