From d6eeb85df625ebd3195d494941c35191fd571766 Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 9 Oct 2023 17:50:35 +0900 Subject: [PATCH] adding "keep_ssh_dir" option --- action.yml | 4 ++++ src/main.ts | 32 +++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 7c9fd9e..58d5eb2 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,10 @@ inputs: description: "replace / ignore / fail" required: false default: "fail" + keep_ssh_dir: + description: "Set true if you DO NOT want to remove .ssh directory" + required: false + default: "" runs: using: "node16" main: "lib/index.js" diff --git a/src/main.ts b/src/main.ts index 6b7e84f..d78eb5e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -111,10 +111,14 @@ function setup(): void { * cleanup function */ function cleanup(): void { - // remove ".ssh" directory - const sshDirName = removeSshDirectory(); + if (shouldRemoveSshDirectory()) { + // remove ".ssh" directory + const sshDirName = removeSshDirectory(); - console.log(`SSH key in ${sshDirName} has been removed successfully.`); + console.log(`SSH key in ${sshDirName} has been removed successfully.`); + } else { + console.log(`Skip directory deletion.`); + } } /** @@ -236,6 +240,28 @@ function shouldCreateKeyFile(keyFilePath: string, ifKeyExists: string): boolean } } +/** + * should remove SSH directory? + * @returns Yes/No + */ +function shouldRemoveSshDirectory(): boolean { + const keepsSshDir = core.getInput("keep_ssh_dir", { + required: true, + }); + + // empty string or falsy value in YAML + switch (keepsSshDir.toLowerCase()) { + case "": + case "false": + case "no": + case "off": + return true; + + default: + return false; + } +} + /** * build array of known_hosts * @param knownHosts known_hosts