fix: validate private-key input (#376)

## Summary

When `private-key` resolves to an empty value, the action currently lets
Octokit fail with `[@octokit/auth-app] privateKey option is required`,
which points at an implementation detail instead of the action input.
This adds action-level validation so users get the same non-empty input
guidance used for missing `client-id` or `app-id`.

- Validate `private-key` before creating app auth
- Add a regression test and snapshot for the missing private key path
- Leave valid private key handling unchanged, including escaped newlines

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Parker BrownandCopilot authored and GitHub committed 2026-05-12 16:05:46 -07:00
1 parent 363531b6d9
commit f24bbd8964
3 files changed
+30

No files matched your search

+3
View File
@@ -23,6 +23,9 @@ async function run() {
throw new Error("The 'client-id' (or deprecated 'app-id') input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context."); throw new Error("The 'client-id' (or deprecated 'app-id') input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.");
} }
const privateKey = core.getInput("private-key"); const privateKey = core.getInput("private-key");
if (!privateKey) {
throw new Error("The 'private-key' input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.");
}
const enterprise = core.getInput("enterprise"); const enterprise = core.getInput("enterprise");
const owner = core.getInput("owner"); const owner = core.getInput("owner");
const repositories = core const repositories = core
+8
View File
@@ -165,6 +165,14 @@ exports[`main-missing-owner.test.js > stderr 1`] = `
GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>' GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'
`; `;
exports[`main-missing-private-key.test.js > stderr 1`] = `
The 'private-key' input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.
`;
exports[`main-missing-private-key.test.js > stdout 1`] = `
::error::The 'private-key' input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.
`;
exports[`main-missing-repository.test.js > stderr 1`] = ` exports[`main-missing-repository.test.js > stderr 1`] = `
GITHUB_REPOSITORY missing, must be set to '<owner>/<repo>' GITHUB_REPOSITORY missing, must be set to '<owner>/<repo>'
`; `;
+19
View File
@@ -0,0 +1,19 @@
import { DEFAULT_ENV } from "./main.js";
for (const [key, value] of Object.entries({
...DEFAULT_ENV,
"INPUT_PRIVATE-KEY": "",
})) {
process.env[key] = value;
}
// Log only the error message, not the full stack trace, because the stack
// trace contains environment-specific paths and ANSI codes that differ
// between local and CI environments.
const _error = console.error;
console.error = (err) => _error(err?.message ?? err);
// Verify `main` exits with an error when `private-key` is not set.
const { default: promise } = await import("../main.js");
await promise;
process.exitCode = 0;