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

add cleanup process

This commit is contained in:
shimataro 2022-12-18 07:33:07 +09:00
parent 193316a178
commit a9aae056f5
No known key found for this signature in database
GPG key ID: BE92C05736911A9D
4 changed files with 101 additions and 5 deletions

View file

@ -2720,6 +2720,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getSshDirectory = void 0;
const fs_1 = __importDefault(__nccwpck_require__(147));
const path_1 = __importDefault(__nccwpck_require__(17));
const core = __importStar(__nccwpck_require__(186));
@ -2738,6 +2739,24 @@ catch (err) {
* main function
*/
function main() {
if (!isPost()) {
setup();
}
else {
cleanup();
}
}
/**
* is post process?
* @returns Yes/No
*/
function isPost() {
return Boolean(core.getState("isPost"));
}
/**
* setup function
*/
function setup() {
// parameters
const key = core.getInput("key", {
required: true,
@ -2788,19 +2807,46 @@ 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 keys 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");
}
exports.getSshDirectory = getSshDirectory;
/**
* get home directory
* @returns home directory name