mirror of
https://github.com/actions/create-github-app-token.git
synced 2026-11-16 19:41:09 +00:00
## 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 <[email protected]>
60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
// @ts-check
|
|
|
|
import * as core from "@actions/core";
|
|
import { createAppAuth } from "@octokit/auth-app";
|
|
|
|
import { getPermissionsFromInputs } from "./lib/get-permissions-from-inputs.js";
|
|
import { main } from "./lib/main.js";
|
|
import request, { ensureNativeProxySupport } from "./lib/request.js";
|
|
|
|
if (!process.env.GITHUB_REPOSITORY) {
|
|
throw new Error("GITHUB_REPOSITORY missing, must be set to '<owner>/<repo>'");
|
|
}
|
|
|
|
if (!process.env.GITHUB_REPOSITORY_OWNER) {
|
|
throw new Error("GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'");
|
|
}
|
|
|
|
async function run() {
|
|
ensureNativeProxySupport();
|
|
|
|
const clientId = core.getInput("client-id") || core.getInput("app-id");
|
|
if (!clientId) {
|
|
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");
|
|
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 owner = core.getInput("owner");
|
|
const repositories = core
|
|
.getInput("repositories")
|
|
.split(/[\n,]+/)
|
|
.map((s) => s.trim())
|
|
.filter((x) => x !== "");
|
|
|
|
const skipTokenRevoke = core.getBooleanInput("skip-token-revoke");
|
|
|
|
const permissions = getPermissionsFromInputs(process.env);
|
|
|
|
return main(
|
|
clientId,
|
|
privateKey,
|
|
enterprise,
|
|
owner,
|
|
repositories,
|
|
permissions,
|
|
core,
|
|
createAppAuth,
|
|
request,
|
|
skipTokenRevoke,
|
|
);
|
|
}
|
|
|
|
// Export promise for testing
|
|
export default run().catch((error) => {
|
|
/* c8 ignore next 3 */
|
|
console.error(error);
|
|
core.setFailed(error.message);
|
|
});
|