1
0
Fork 0
mirror of https://github.com/shimataro/ssh-key-action.git synced 2025-06-19 22:52:10 +10:00

adding "keep_ssh_dir" option

This commit is contained in:
shimataro 2023-10-09 17:50:35 +09:00
parent f5671c022c
commit d6eeb85df6
No known key found for this signature in database
GPG key ID: BE92C05736911A9D
2 changed files with 33 additions and 3 deletions

View file

@ -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"

View file

@ -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