mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
append LF (#151)
* append LF to known_hosts and config * build * update CHANGELOG
This commit is contained in:
parent
c6c7de11ed
commit
34604805aa
4 changed files with 32 additions and 11 deletions
17
lib/main.js
17
lib/main.js
|
@ -43,7 +43,7 @@ function main() {
|
|||
},
|
||||
{
|
||||
name: "known_hosts",
|
||||
contents: prependLf(core.getInput("known_hosts", {
|
||||
contents: insertLf(core.getInput("known_hosts", {
|
||||
required: true,
|
||||
})),
|
||||
options: {
|
||||
|
@ -53,7 +53,7 @@ function main() {
|
|||
},
|
||||
{
|
||||
name: "config",
|
||||
contents: prependLf(core.getInput("config")),
|
||||
contents: insertLf(core.getInput("config")),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
|
@ -103,16 +103,23 @@ function getHomeEnv() {
|
|||
return "HOME";
|
||||
}
|
||||
/**
|
||||
* prepend LF to value if not empty
|
||||
* prepend/append LF to value if not empty
|
||||
* @param value the value to prepend LF
|
||||
* @returns prepended value
|
||||
*/
|
||||
function prependLf(value) {
|
||||
function insertLf(value) {
|
||||
let affectedValue = value;
|
||||
if (value.length === 0) {
|
||||
// do nothing if empty
|
||||
return "";
|
||||
}
|
||||
return `\n${value}`;
|
||||
if (!affectedValue.startsWith("\n")) {
|
||||
affectedValue = `\n${affectedValue}`;
|
||||
}
|
||||
if (!affectedValue.endsWith("\n")) {
|
||||
affectedValue = `${affectedValue}\n`;
|
||||
}
|
||||
return affectedValue;
|
||||
}
|
||||
main();
|
||||
//# sourceMappingURL=main.js.map
|
Loading…
Add table
Add a link
Reference in a new issue