1
0
Fork 0
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:
shimataro 2021-02-21 15:57:19 +09:00 committed by GitHub
commit 0ea914c065
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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