@@ -24962,11 +24962,18 @@ function run() {
2496224962 return __awaiter(this, void 0, void 0, function* () {
2496324963 try {
2496424964 // const githubToken = core.getInput('token', { required: true });
24965- const scriptId = core.getInput('script_id', { required: true });
24966- const deployKey = core.getInput('deploy_key', { required: true });
24967- const base = core.getInput('base', { required: false });
24968- const client = Bunny.createClient(base, deployKey);
24969- const file_path = core.getInput('file', { required: true });
24965+ const scriptId = core.getInput("script_id", { required: true });
24966+ const deployKey = core.getInput("deploy_key", { required: false });
24967+ const base = core.getInput("base", { required: false });
24968+ let token;
24969+ if (deployKey == "") {
24970+ token = Bunny.newOIDCToken(yield core.getIDToken());
24971+ }
24972+ else {
24973+ token = Bunny.newDeployKey(deployKey);
24974+ }
24975+ const client = Bunny.createClient(base, token);
24976+ const file_path = core.getInput("file", { required: true });
2497024977 const fileContent = yield fs.readFile(file_path, { encoding: "utf-8" });
2497124978 yield Bunny.deployScript(client)(scriptId, fileContent);
2497224979 }
@@ -24995,18 +25002,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2499525002 });
2499625003};
2499725004Object.defineProperty(exports, "__esModule", ({ value: true }));
24998- exports.createClient = exports.deployScript = void 0;
25005+ exports.newOIDCToken = exports.newDeployKey = exports.createClient = exports.deployScript = void 0;
25006+ const newDeployKey = (token) => ({ _internal: "deploy", token });
25007+ exports.newDeployKey = newDeployKey;
25008+ const newOIDCToken = (token) => ({ _internal: "oidc", token });
25009+ exports.newOIDCToken = newOIDCToken;
2499925010const createClient = (base, token) => { return ({ base, token }); };
2500025011exports.createClient = createClient;
2500125012const deployScript = (client) => (scriptId, code) => __awaiter(void 0, void 0, void 0, function* () {
25013+ const headers = {
25014+ "Accept": "application/json",
25015+ "Content-Type": "application/json",
25016+ };
25017+ switch (client.token._internal) {
25018+ case "deploy":
25019+ headers["DeploymentKey"] = client.token.token;
25020+ break;
25021+ case "oidc":
25022+ headers["GithubToken"] = client.token.token;
25023+ break;
25024+ }
2500225025 const endpoint_save = `${client.base}/compute/script/${scriptId}/code`;
2500325026 const response = yield fetch(endpoint_save, {
2500425027 method: "POST",
25005- headers: {
25006- "Accept": "application/json",
25007- "Content-Type": "application/json",
25008- "DeploymentKey": client.token,
25009- },
25028+ headers,
2501025029 body: JSON.stringify({ Code: code }),
2501125030 });
2501225031 if (!response.ok) {
@@ -25017,11 +25036,7 @@ const deployScript = (client) => (scriptId, code) => __awaiter(void 0, void 0, v
2501725036 const endpoint_publish = `${client.base}/compute/script/${scriptId}/publish`;
2501825037 const responsePublish = yield fetch(endpoint_publish, {
2501925038 method: "POST",
25020- headers: {
25021- "Accept": "application/json",
25022- "Content-Type": "application/json",
25023- "DeploymentKey": client.token,
25024- },
25039+ headers,
2502525040 });
2502625041 if (!responsePublish.ok) {
2502725042 console.error(`Failed to publish script: ${response.statusText}`);
0 commit comments