1
0
Fork 0
mirror of https://github.com/shimataro/ssh-key-action.git synced 2025-06-19 22:52:10 +10:00
This commit is contained in:
shimataro 2023-10-10 22:34:36 +09:00
parent 711063ca38
commit f2e872a48a
No known key found for this signature in database
GPG key ID: BE92C05736911A9D
6 changed files with 23 additions and 33 deletions

12
dist/main.js vendored

File diff suppressed because one or more lines are too long

6
dist/main.js.map vendored

File diff suppressed because one or more lines are too long

6
dist/post.js vendored

File diff suppressed because one or more lines are too long

2
dist/post.js.map vendored

File diff suppressed because one or more lines are too long

View file

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

View file

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