mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
append LF to known_hosts and config
This commit is contained in:
parent
c6c7de11ed
commit
937c78c6f0
1 changed files with 15 additions and 5 deletions
20
src/main.ts
20
src/main.ts
|
@ -30,7 +30,7 @@ function main(): void
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "known_hosts",
|
name: "known_hosts",
|
||||||
contents: prependLf(core.getInput("known_hosts", {
|
contents: insertLf(core.getInput("known_hosts", {
|
||||||
required: true,
|
required: true,
|
||||||
})),
|
})),
|
||||||
options: {
|
options: {
|
||||||
|
@ -40,7 +40,7 @@ function main(): void
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "config",
|
name: "config",
|
||||||
contents: prependLf(core.getInput("config")),
|
contents: insertLf(core.getInput("config")),
|
||||||
options: {
|
options: {
|
||||||
mode: 0o644,
|
mode: 0o644,
|
||||||
flag: "a",
|
flag: "a",
|
||||||
|
@ -104,19 +104,29 @@ function getHomeEnv(): string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* prepend LF to value if not empty
|
* prepend/append LF to value if not empty
|
||||||
* @param value the value to prepend LF
|
* @param value the value to prepend LF
|
||||||
* @returns prepended value
|
* @returns prepended value
|
||||||
*/
|
*/
|
||||||
function prependLf(value: string): string
|
function insertLf(value: string): string
|
||||||
{
|
{
|
||||||
|
let affectedValue = value;
|
||||||
|
|
||||||
if(value.length === 0)
|
if(value.length === 0)
|
||||||
{
|
{
|
||||||
// do nothing if empty
|
// do nothing if empty
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
if(!affectedValue.startsWith("\n"))
|
||||||
|
{
|
||||||
|
affectedValue = `\n${affectedValue}`;
|
||||||
|
}
|
||||||
|
if(!affectedValue.endsWith("\n"))
|
||||||
|
{
|
||||||
|
affectedValue = `${affectedValue}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
return `\n${value}`;
|
return affectedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue