From 937c78c6f031a88b8a56e93c3c46b4c4ba70b1ec Mon Sep 17 00:00:00 2001 From: shimataro Date: Sat, 15 Aug 2020 10:19:52 +0900 Subject: [PATCH 1/3] append LF to known_hosts and config --- src/main.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index dff8fcd1..43338848 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,7 +30,7 @@ function main(): void }, { name: "known_hosts", - contents: prependLf(core.getInput("known_hosts", { + contents: insertLf(core.getInput("known_hosts", { required: true, })), options: { @@ -40,7 +40,7 @@ function main(): void }, { name: "config", - contents: prependLf(core.getInput("config")), + contents: insertLf(core.getInput("config")), options: { mode: 0o644, 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 * @returns prepended value */ -function prependLf(value: string): string +function insertLf(value: string): string { + let affectedValue = value; + if(value.length === 0) { // do nothing if empty return ""; } + if(!affectedValue.startsWith("\n")) + { + affectedValue = `\n${affectedValue}`; + } + if(!affectedValue.endsWith("\n")) + { + affectedValue = `${affectedValue}\n`; + } - return `\n${value}`; + return affectedValue; } main(); From 59dd1bfa63a2cd2a41cf5697ea0165f1f86a69a7 Mon Sep 17 00:00:00 2001 From: shimataro Date: Sat, 15 Aug 2020 10:21:47 +0900 Subject: [PATCH 2/3] build --- lib/main.js | 17 ++++++++++++----- lib/main.js.map | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 4102d787..268be8f8 100644 --- a/lib/main.js +++ b/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 \ No newline at end of file diff --git a/lib/main.js.map b/lib/main.js.map index b154c368..90ff03b8 100644 --- a/lib/main.js.map +++ b/lib/main.js.map @@ -1 +1 @@ -{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,oDAAsC;AAStC;;GAEG;AACH,SAAS,IAAI;IAEZ,IACA;QACC,MAAM,KAAK,GAAe;YACzB;gBACC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE;oBAC9B,QAAQ,EAAE,IAAI;iBACd,CAAC;gBACF,OAAO,EAAE;oBACR,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,IAAI;iBACV;aACD;YACD;gBACC,IAAI,EAAE,aAAa;gBACnB,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE;oBAChD,QAAQ,EAAE,IAAI;iBACd,CAAC,CAAC;gBACH,OAAO,EAAE;oBACR,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG;iBACT;aACD;YACD;gBACC,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBAC5C,OAAO,EAAE;oBACR,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG;iBACT;aACD;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AACtB,CAAC;AAED,IAAI,EAAE,CAAC"} \ No newline at end of file From 400bdf329709b0bf5afbf50ca47605aefa359dc1 Mon Sep 17 00:00:00 2001 From: shimataro Date: Sat, 15 Aug 2020 10:27:25 +0900 Subject: [PATCH 3/3] update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67040221..28accb72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +* Append LF to `known_hosts` / `config`. + ### Fixed * Typo (thanks [@psbss](https://github.com/psbss))