Skip to content

Commit

Permalink
adding "keep_ssh_dir" option
Browse files Browse the repository at this point in the history
  • Loading branch information
shimataro committed Oct 9, 2023
1 parent f5671c0 commit d6eeb85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 29 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
}

/**
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d6eeb85

Please sign in to comment.