mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
add cleanup process (#224)
* add cleanup process * save state * update README/CHANGELOG * fix message * `getSshDirectory()` should not be exported
This commit is contained in:
parent
193316a178
commit
7cccbd3065
6 changed files with 122 additions and 6 deletions
55
lib/index.js
55
lib/index.js
|
@ -2738,6 +2738,31 @@ catch (err) {
|
|||
* main function
|
||||
*/
|
||||
function main() {
|
||||
if (!isPost()) {
|
||||
setup();
|
||||
setPost();
|
||||
}
|
||||
else {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* is post process?
|
||||
* @returns Yes/No
|
||||
*/
|
||||
function isPost() {
|
||||
return Boolean(core.getState("isPost"));
|
||||
}
|
||||
/**
|
||||
* update post state
|
||||
*/
|
||||
function setPost() {
|
||||
core.saveState("isPost", "true");
|
||||
}
|
||||
/**
|
||||
* setup function
|
||||
*/
|
||||
function setup() {
|
||||
// parameters
|
||||
const key = core.getInput("key", {
|
||||
required: true,
|
||||
|
@ -2788,19 +2813,45 @@ function main() {
|
|||
}
|
||||
console.log(`SSH key has been stored to ${sshDirName} successfully.`);
|
||||
}
|
||||
/**
|
||||
* cleanup function
|
||||
*/
|
||||
function cleanup() {
|
||||
// remove ".ssh" directory
|
||||
const sshDirName = removeSshDirectory();
|
||||
console.log(`SSH key in ${sshDirName} has been removed successfully.`);
|
||||
}
|
||||
/**
|
||||
* create ".ssh" directory
|
||||
* @returns directory name
|
||||
*/
|
||||
function createSshDirectory() {
|
||||
const home = getHomeDirectory();
|
||||
const dirName = path_1.default.resolve(home, ".ssh");
|
||||
const dirName = getSshDirectory();
|
||||
fs_1.default.mkdirSync(dirName, {
|
||||
recursive: true,
|
||||
mode: 0o700,
|
||||
});
|
||||
return dirName;
|
||||
}
|
||||
/**
|
||||
* remove ".ssh" directory
|
||||
* @returns removed directory name
|
||||
*/
|
||||
function removeSshDirectory() {
|
||||
const dirName = getSshDirectory();
|
||||
fs_1.default.rmSync(dirName, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
return dirName;
|
||||
}
|
||||
/**
|
||||
* get SSH directory
|
||||
* @returns SSH directory name
|
||||
*/
|
||||
function getSshDirectory() {
|
||||
return path_1.default.resolve(getHomeDirectory(), ".ssh");
|
||||
}
|
||||
/**
|
||||
* get home directory
|
||||
* @returns home directory name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue