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:
parent
193316a178
commit
a9aae056f5
4 changed files with 101 additions and 5 deletions
|
@ -161,7 +161,7 @@ rules: # https://eslint.org/docs/rules/
|
||||||
- error
|
- error
|
||||||
- max: 1
|
- max: 1
|
||||||
no-native-reassign: error
|
no-native-reassign: error
|
||||||
no-negated-condition: error
|
no-negated-condition: 'off'
|
||||||
no-negated-in-lhs: error
|
no-negated-in-lhs: error
|
||||||
no-nested-ternary: error
|
no-nested-ternary: error
|
||||||
no-new: error
|
no-new: error
|
||||||
|
|
|
@ -28,3 +28,4 @@ inputs:
|
||||||
runs:
|
runs:
|
||||||
using: "node16"
|
using: "node16"
|
||||||
main: "lib/index.js"
|
main: "lib/index.js"
|
||||||
|
post: "lib/index.js"
|
||||||
|
|
50
lib/index.js
50
lib/index.js
|
@ -2720,6 +2720,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.getSshDirectory = void 0;
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(147));
|
const fs_1 = __importDefault(__nccwpck_require__(147));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(17));
|
const path_1 = __importDefault(__nccwpck_require__(17));
|
||||||
const core = __importStar(__nccwpck_require__(186));
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
|
@ -2738,6 +2739,24 @@ catch (err) {
|
||||||
* main function
|
* main function
|
||||||
*/
|
*/
|
||||||
function main() {
|
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
|
// parameters
|
||||||
const key = core.getInput("key", {
|
const key = core.getInput("key", {
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -2788,19 +2807,46 @@ function main() {
|
||||||
}
|
}
|
||||||
console.log(`SSH key has been stored to ${sshDirName} successfully.`);
|
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
|
* create ".ssh" directory
|
||||||
* @returns directory name
|
* @returns directory name
|
||||||
*/
|
*/
|
||||||
function createSshDirectory() {
|
function createSshDirectory() {
|
||||||
const home = getHomeDirectory();
|
const dirName = getSshDirectory();
|
||||||
const dirName = path_1.default.resolve(home, ".ssh");
|
|
||||||
fs_1.default.mkdirSync(dirName, {
|
fs_1.default.mkdirSync(dirName, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
mode: 0o700,
|
mode: 0o700,
|
||||||
});
|
});
|
||||||
return dirName;
|
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
|
* get home directory
|
||||||
* @returns home directory name
|
* @returns home directory name
|
||||||
|
|
53
src/main.ts
53
src/main.ts
|
@ -25,6 +25,25 @@ try {
|
||||||
* main function
|
* main function
|
||||||
*/
|
*/
|
||||||
function main(): void {
|
function main(): void {
|
||||||
|
if (!isPost()) {
|
||||||
|
setup();
|
||||||
|
} else {
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is post process?
|
||||||
|
* @returns Yes/No
|
||||||
|
*/
|
||||||
|
function isPost(): boolean {
|
||||||
|
return Boolean(core.getState("isPost"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setup function
|
||||||
|
*/
|
||||||
|
function setup(): void {
|
||||||
// parameters
|
// parameters
|
||||||
const key = core.getInput("key", {
|
const key = core.getInput("key", {
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -80,13 +99,22 @@ function main(): void {
|
||||||
console.log(`SSH key has been stored to ${sshDirName} successfully.`);
|
console.log(`SSH key has been stored to ${sshDirName} successfully.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cleanup function
|
||||||
|
*/
|
||||||
|
function cleanup(): void {
|
||||||
|
// remove ".ssh" directory
|
||||||
|
const sshDirName = removeSshDirectory();
|
||||||
|
|
||||||
|
console.log(`SSH keys in ${sshDirName} has been removed successfully.`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create ".ssh" directory
|
* create ".ssh" directory
|
||||||
* @returns directory name
|
* @returns directory name
|
||||||
*/
|
*/
|
||||||
function createSshDirectory(): string {
|
function createSshDirectory(): string {
|
||||||
const home = getHomeDirectory();
|
const dirName = getSshDirectory();
|
||||||
const dirName = path.resolve(home, ".ssh");
|
|
||||||
fs.mkdirSync(dirName, {
|
fs.mkdirSync(dirName, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
mode: 0o700,
|
mode: 0o700,
|
||||||
|
@ -94,6 +122,27 @@ function createSshDirectory(): string {
|
||||||
return dirName;
|
return dirName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove ".ssh" directory
|
||||||
|
* @returns removed directory name
|
||||||
|
*/
|
||||||
|
function removeSshDirectory(): string {
|
||||||
|
const dirName = getSshDirectory();
|
||||||
|
fs.rmSync(dirName, {
|
||||||
|
recursive: true,
|
||||||
|
force: true,
|
||||||
|
});
|
||||||
|
return dirName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get SSH directory
|
||||||
|
* @returns SSH directory name
|
||||||
|
*/
|
||||||
|
export function getSshDirectory(): string {
|
||||||
|
return path.resolve(getHomeDirectory(), ".ssh");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get home directory
|
* get home directory
|
||||||
* @returns home directory name
|
* @returns home directory name
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue