mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
refactor
This commit is contained in:
parent
711063ca38
commit
f2e872a48a
6 changed files with 23 additions and 33 deletions
12
dist/main.js
vendored
12
dist/main.js
vendored
File diff suppressed because one or more lines are too long
6
dist/main.js.map
vendored
6
dist/main.js.map
vendored
File diff suppressed because one or more lines are too long
6
dist/post.js
vendored
6
dist/post.js
vendored
File diff suppressed because one or more lines are too long
2
dist/post.js.map
vendored
2
dist/post.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -7,13 +7,13 @@ import * as core from "@actions/core";
|
|||
const STATE_BACKUP_SUFFIX = "backup-suffix";
|
||||
|
||||
/**
|
||||
* generate backup suffix name
|
||||
* create backup suffix name
|
||||
* @param dirName directory to back up
|
||||
* @returns backup suffix
|
||||
*/
|
||||
export function generateBackupSuffix(): string {
|
||||
const dirName = getSshDirectory();
|
||||
export function createBackupSuffix(dirName: string): string {
|
||||
if (!fs.existsSync(dirName)) {
|
||||
// do nothing if .ssh does not exist
|
||||
// do nothing if directory does not exist
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
22
src/main.ts
22
src/main.ts
|
@ -34,8 +34,6 @@ try {
|
|||
* main function
|
||||
*/
|
||||
export function main(): void {
|
||||
const backupSuffix = common.generateBackupSuffix();
|
||||
|
||||
// parameters
|
||||
const key = core.getInput("key", {
|
||||
required: true,
|
||||
|
@ -48,7 +46,12 @@ export function main(): void {
|
|||
const ifKeyExists = core.getInput("if_key_exists");
|
||||
|
||||
// create ".ssh" directory
|
||||
const sshDirName = createSshDirectory();
|
||||
const sshDirName = common.getSshDirectory();
|
||||
const backupSuffix = common.createBackupSuffix(sshDirName);
|
||||
fs.mkdirSync(sshDirName, {
|
||||
recursive: true,
|
||||
mode: 0o700,
|
||||
});
|
||||
|
||||
// files to be created
|
||||
const files: FileInfo[] = [
|
||||
|
@ -127,19 +130,6 @@ function backup(fileName: string, backupSuffix: string, removeOrig: boolean): bo
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* create ".ssh" directory
|
||||
* @returns directory name
|
||||
*/
|
||||
function createSshDirectory(): string {
|
||||
const dirName = common.getSshDirectory();
|
||||
fs.mkdirSync(dirName, {
|
||||
recursive: true,
|
||||
mode: 0o700,
|
||||
});
|
||||
return dirName;
|
||||
}
|
||||
|
||||
/**
|
||||
* prepend/append LF to value if not empty
|
||||
* @param value the value to insert LF
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue