mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
Merge pull request #156 from tats-u/ssh-key-lf
Make up for LF in last line of SSH key file
This commit is contained in:
commit
0ea914c065
1 changed files with 25 additions and 6 deletions
31
src/main.ts
31
src/main.ts
|
@ -20,9 +20,9 @@ function main(): void
|
|||
const files: FileInfo[] = [
|
||||
{
|
||||
name: core.getInput("name"),
|
||||
contents: core.getInput("key", {
|
||||
contents: insertLfToEnd(core.getInput("key", {
|
||||
required: true,
|
||||
}),
|
||||
})),
|
||||
options: {
|
||||
mode: 0o400,
|
||||
flag: "ax",
|
||||
|
@ -109,6 +109,28 @@ function getHomeEnv(): string
|
|||
return "HOME";
|
||||
}
|
||||
|
||||
/**
|
||||
* append LF to value to the end if not empty
|
||||
* @param value the value to prepend LF
|
||||
* @returns prepended value
|
||||
*/
|
||||
function insertLfToEnd(value: string): string
|
||||
{
|
||||
let affectedValue = value;
|
||||
|
||||
if(value.length === 0)
|
||||
{
|
||||
// do nothing if empty
|
||||
return "";
|
||||
}
|
||||
if(!affectedValue.endsWith("\n"))
|
||||
{
|
||||
affectedValue = `${affectedValue}\n`;
|
||||
}
|
||||
|
||||
return affectedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* prepend/append LF to value if not empty
|
||||
* @param value the value to prepend LF
|
||||
|
@ -127,10 +149,7 @@ function insertLf(value: string): string
|
|||
{
|
||||
affectedValue = `\n${affectedValue}`;
|
||||
}
|
||||
if(!affectedValue.endsWith("\n"))
|
||||
{
|
||||
affectedValue = `${affectedValue}\n`;
|
||||
}
|
||||
affectedValue = insertLfToEnd(affectedValue);
|
||||
|
||||
return affectedValue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue