mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Fix the /version subaction to not crash on missing pr-base-branch input (#666)
* use `getOptionalInput` consistently * introduce `getRequiredInput` * add changeset
This commit is contained in:
@@ -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.
|
||||
+1
-4
@@ -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
|
||||
|
||||
+6
-2
@@ -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();
|
||||
@@ -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();
|
||||
|
||||
@@ -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<
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
@@ -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],
|
||||
|
||||
@@ -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();
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user