From 0673b3776febd7d9b0230b3b63cc8086d90d3f64 Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 8 Mar 2021 17:09:37 +0900 Subject: [PATCH 1/8] test no_known_hosts parameter --- .github/workflows/verify-on-ubuntu.yml | 24 ++++++++++++++++++++++++ action.yml | 4 ++++ lib/index.js | 3 +++ src/main.ts | 4 ++++ 4 files changed, 35 insertions(+) diff --git a/.github/workflows/verify-on-ubuntu.yml b/.github/workflows/verify-on-ubuntu.yml index 7117eaf..5839b0b 100644 --- a/.github/workflows/verify-on-ubuntu.yml +++ b/.github/workflows/verify-on-ubuntu.yml @@ -257,3 +257,27 @@ jobs: run: ls -l ~/.ssh - name: git clone through SSH run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + no_known_hosts: + name: no known_hosts file + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + steps: + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + no_known_hosts: true + - name: print created files + run: ls -l ~/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp diff --git a/action.yml b/action.yml index 6fab2b1..6608df2 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,10 @@ inputs: description: "replace / ignore / fail" required: false default: "fail" + no_known_hosts: + description: "enables not providing known_hosts file" + required: false + default: "0" runs: using: "node12" main: "lib/index.js" diff --git a/lib/index.js b/lib/index.js index 8817986..b7f6a6f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -437,6 +437,9 @@ function main() { }); const config = core.getInput("config"); const ifKeyExists = core.getInput("if_key_exists"); + // test + const noKnownHosts = core.getInput("no_known_hosts"); + console.log(noKnownHosts); // create ".ssh" directory const home = getHomeDirectory(); const dirName = path_1.default.resolve(home, ".ssh"); diff --git a/src/main.ts b/src/main.ts index 0764350..429be53 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,6 +28,10 @@ function main(): void const config = core.getInput("config"); const ifKeyExists = core.getInput("if_key_exists"); + // test + const noKnownHosts = core.getInput("no_known_hosts"); + console.log(noKnownHosts); + // create ".ssh" directory const home = getHomeDirectory(); const dirName = path.resolve(home, ".ssh"); From 169acaed937a77d0160dca84cf1811e11dcb815a Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 8 Mar 2021 17:40:09 +0900 Subject: [PATCH 2/8] implement --- .github/workflows/verify-on-ubuntu.yml | 3 --- lib/index.js | 27 +++++++++++++++++--- src/main.ts | 34 ++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/.github/workflows/verify-on-ubuntu.yml b/.github/workflows/verify-on-ubuntu.yml index 5839b0b..28aab71 100644 --- a/.github/workflows/verify-on-ubuntu.yml +++ b/.github/workflows/verify-on-ubuntu.yml @@ -275,9 +275,6 @@ jobs: uses: ./. with: key: ${{ secrets.SSH_KEY_PEM }} - known_hosts: ${{ secrets.KNOWN_HOSTS }} no_known_hosts: true - name: print created files run: ls -l ~/.ssh - - name: git clone through SSH - run: git clone git@github.com:shimataro/ssh-key-action.git tmp diff --git a/lib/index.js b/lib/index.js index b7f6a6f..5c07890 100644 --- a/lib/index.js +++ b/lib/index.js @@ -428,18 +428,16 @@ const core = __importStar(__nccwpck_require__(186)); function main() { try { // parameters + const noKnownHosts = string2boolean(core.getInput("no_known_hosts")); const key = core.getInput("key", { required: true, }); const name = core.getInput("name"); const knownHosts = core.getInput("known_hosts", { - required: true, + required: !noKnownHosts, // optional if no_known_hosts is true }); const config = core.getInput("config"); const ifKeyExists = core.getInput("if_key_exists"); - // test - const noKnownHosts = core.getInput("no_known_hosts"); - console.log(noKnownHosts); // create ".ssh" directory const home = getHomeDirectory(); const dirName = path_1.default.resolve(home, ".ssh"); @@ -487,6 +485,27 @@ function main() { core.setFailed(err.message); } } +/** + * convert string to boolean + * @param value string value + * @returns boolean value + */ +function string2boolean(value) { + // true if "true" / "yes" / "on" + switch (value.trim().toLowerCase()) { + case "true": + case "yes": + case "on": + return true; + } + // true if number and non-zero + const numberValue = Number(value); + if (!isNaN(numberValue) && numberValue !== 0) { + return true; + } + // false otherwise + return false; +} /** * get home directory * @returns home directory diff --git a/src/main.ts b/src/main.ts index 429be53..3670892 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,20 +18,17 @@ function main(): void try { // parameters + const noKnownHosts = string2boolean(core.getInput("no_known_hosts")); const key = core.getInput("key", { required: true, }); const name = core.getInput("name"); const knownHosts = core.getInput("known_hosts", { - required: true, + required: !noKnownHosts, // optional if no_known_hosts is true }); const config = core.getInput("config"); const ifKeyExists = core.getInput("if_key_exists"); - // test - const noKnownHosts = core.getInput("no_known_hosts"); - console.log(noKnownHosts); - // create ".ssh" directory const home = getHomeDirectory(); const dirName = path.resolve(home, ".ssh"); @@ -86,6 +83,33 @@ function main(): void } } +/** + * convert string to boolean + * @param value string value + * @returns boolean value + */ +function string2boolean(value: string): boolean +{ + // true if "true" / "yes" / "on" + switch(value.trim().toLowerCase()) + { + case "true": + case "yes": + case "on": + return true; + } + + // true if number and non-zero + const numberValue = Number(value); + if(!isNaN(numberValue) && numberValue !== 0) + { + return true; + } + + // false otherwise + return false; +} + /** * get home directory * @returns home directory From 74af40b44a4970c3d68136a6dce43bf7dea36331 Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 8 Mar 2021 17:53:38 +0900 Subject: [PATCH 3/8] ignore known_hosts if no_known_hosts is true --- lib/index.js | 18 ++++++++++-------- src/main.ts | 19 +++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/index.js b/lib/index.js index 5c07890..5d3bb87 100644 --- a/lib/index.js +++ b/lib/index.js @@ -447,14 +447,6 @@ function main() { }); // files to be created const files = [ - { - name: "known_hosts", - contents: insertLf(knownHosts, true, true), - options: { - mode: 0o644, - flag: "a", - }, - }, { name: "config", contents: insertLf(config, true, true), @@ -474,6 +466,16 @@ function main() { }, }); } + if (!noKnownHosts) { + files.push({ + name: "known_hosts", + contents: insertLf(knownHosts, true, true), + options: { + mode: 0o644, + flag: "a", + }, + }); + } // create files for (const file of files) { const fileName = path_1.default.join(dirName, file.name); diff --git a/src/main.ts b/src/main.ts index 3670892..75ab350 100644 --- a/src/main.ts +++ b/src/main.ts @@ -39,14 +39,6 @@ function main(): void // files to be created const files: FileInfo[] = [ - { - name: "known_hosts", - contents: insertLf(knownHosts, true, true), - options: { - mode: 0o644, - flag: "a", - }, - }, { name: "config", contents: insertLf(config, true, true), @@ -67,6 +59,17 @@ function main(): void }, }); } + if(!noKnownHosts) + { + files.push({ + name: "known_hosts", + contents: insertLf(knownHosts, true, true), + options: { + mode: 0o644, + flag: "a", + }, + }); + } // create files for(const file of files) From 91f978d59078df27b51cc5c1f06e0eb277d6339f Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 8 Mar 2021 18:02:01 +0900 Subject: [PATCH 4/8] refactor --- lib/index.js | 23 ++++++++++++----------- src/main.ts | 24 +++++++++++++----------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/index.js b/lib/index.js index 5d3bb87..3b1f766 100644 --- a/lib/index.js +++ b/lib/index.js @@ -446,16 +446,7 @@ function main() { mode: 0o700, }); // files to be created - const files = [ - { - name: "config", - contents: insertLf(config, true, true), - options: { - mode: 0o644, - flag: "a", - }, - }, - ]; + const files = []; if (shouldCreateKeyFile(path_1.default.join(dirName, name), ifKeyExists)) { files.push({ name: name, @@ -466,7 +457,7 @@ function main() { }, }); } - if (!noKnownHosts) { + if (knownHosts !== "") { files.push({ name: "known_hosts", contents: insertLf(knownHosts, true, true), @@ -476,6 +467,16 @@ function main() { }, }); } + if (config !== "") { + files.push({ + name: "config", + contents: insertLf(config, true, true), + options: { + mode: 0o644, + flag: "a", + }, + }); + } // create files for (const file of files) { const fileName = path_1.default.join(dirName, file.name); diff --git a/src/main.ts b/src/main.ts index 75ab350..c040087 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,16 +38,7 @@ function main(): void }); // files to be created - const files: FileInfo[] = [ - { - name: "config", - contents: insertLf(config, true, true), - options: { - mode: 0o644, - flag: "a", - }, - }, - ]; + const files: FileInfo[] = []; if(shouldCreateKeyFile(path.join(dirName, name), ifKeyExists)) { files.push({ @@ -59,7 +50,7 @@ function main(): void }, }); } - if(!noKnownHosts) + if(knownHosts !== "") { files.push({ name: "known_hosts", @@ -70,6 +61,17 @@ function main(): void }, }); } + if(config !== "") + { + files.push({ + name: "config", + contents: insertLf(config, true, true), + options: { + mode: 0o644, + flag: "a", + }, + }); + } // create files for(const file of files) From 206d310c5c4825281c60454081c0599c645ba64d Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 8 Mar 2021 18:10:18 +0900 Subject: [PATCH 5/8] no_known_hosts is false --- .github/workflows/verify-on-ubuntu.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/verify-on-ubuntu.yml b/.github/workflows/verify-on-ubuntu.yml index 28aab71..4762bb3 100644 --- a/.github/workflows/verify-on-ubuntu.yml +++ b/.github/workflows/verify-on-ubuntu.yml @@ -278,3 +278,23 @@ jobs: no_known_hosts: true - name: print created files run: ls -l ~/.ssh + without-no_known_hosts: + name: no known_hosts file + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + steps: + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + continue-on-error: true + - name: print created files + run: ls -l ~/.ssh From 667d0dd08117ba5bf6dcb58afacd2fe7fc77f768 Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 8 Mar 2021 18:15:26 +0900 Subject: [PATCH 6/8] Revert "no_known_hosts is false" This reverts commit 206d310c5c4825281c60454081c0599c645ba64d. --- .github/workflows/verify-on-ubuntu.yml | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/.github/workflows/verify-on-ubuntu.yml b/.github/workflows/verify-on-ubuntu.yml index 4762bb3..28aab71 100644 --- a/.github/workflows/verify-on-ubuntu.yml +++ b/.github/workflows/verify-on-ubuntu.yml @@ -278,23 +278,3 @@ jobs: no_known_hosts: true - name: print created files run: ls -l ~/.ssh - without-no_known_hosts: - name: no known_hosts file - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-16.04 - - ubuntu-18.04 - - ubuntu-20.04 - steps: - - name: Checkout source codes - uses: actions/checkout@v2 - - name: Install SSH key - uses: ./. - with: - key: ${{ secrets.SSH_KEY_PEM }} - continue-on-error: true - - name: print created files - run: ls -l ~/.ssh From 1b0997cf76e5bbf0ec84c3978a0ec9591f414f6c Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 8 Mar 2021 18:16:24 +0900 Subject: [PATCH 7/8] test on Windows / macOS --- .github/workflows/verify-on-macos.yml | 21 +++++++++++++++++++++ .github/workflows/verify-on-windows.yml | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/.github/workflows/verify-on-macos.yml b/.github/workflows/verify-on-macos.yml index 87b836f..5e8aabf 100644 --- a/.github/workflows/verify-on-macos.yml +++ b/.github/workflows/verify-on-macos.yml @@ -237,3 +237,24 @@ jobs: run: ls -l ~/.ssh - name: git clone through SSH run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + no_known_hosts: + name: no known_hosts file + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + steps: + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + no_known_hosts: true + - name: print created files + run: ls -l ~/.ssh diff --git a/.github/workflows/verify-on-windows.yml b/.github/workflows/verify-on-windows.yml index 9a155bb..328c932 100644 --- a/.github/workflows/verify-on-windows.yml +++ b/.github/workflows/verify-on-windows.yml @@ -237,3 +237,24 @@ jobs: run: ls -l ~/.ssh - name: git clone through SSH run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + no_known_hosts: + name: no known_hosts file + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + steps: + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + no_known_hosts: true + - name: print created files + run: ls -l ~/.ssh From e4c51328fab5f61b88af017473f3556da20e1489 Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 8 Mar 2021 18:22:58 +0900 Subject: [PATCH 8/8] test on Docker containers --- .../workflows/verify-on-container-centos.yml | 227 +++++++++++++++++ .../workflows/verify-on-container-ubuntu.yml | 241 ++++++++++++++++++ 2 files changed, 468 insertions(+) diff --git a/.github/workflows/verify-on-container-centos.yml b/.github/workflows/verify-on-container-centos.yml index 6163c8a..547a997 100644 --- a/.github/workflows/verify-on-container-centos.yml +++ b/.github/workflows/verify-on-container-centos.yml @@ -93,3 +93,230 @@ jobs: run: ls -l /root/.ssh - name: git clone through SSH run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + key_if_exists_replace-key_exists: + name: if_key_exists=replace / key exists + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - centos:7 + - centos:8 + steps: + - name: Install packages + run: | + yum install -y git openssh-clients + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (dummy) + uses: ./. + with: + key: "dummy" # replaced + known_hosts: ${{ secrets.KNOWN_HOSTS }} + - name: Install SSH key (replace) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: replace + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + key_if_exists_replace-key_doesnt_exist: + name: if_key_exists=replace / key doesn't exist + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - centos:7 + - centos:8 + steps: + - name: Install packages + run: | + yum install -y git openssh-clients + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (replace) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: replace + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + key_if_exists_ignore-key_exists: + name: if_key_exists=ignore / key exists + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - centos:7 + - centos:8 + steps: + - name: Install packages + run: | + yum install -y git openssh-clients + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (dummy) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + - name: Install SSH key (replace) + uses: ./. + with: + key: "dummy" # ignored + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: ignore + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + key_if_exists_ignore-key_doesnt_exist: + name: if_key_exists=ignore / key doesn't exist + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - centos:7 + - centos:8 + steps: + - name: Install packages + run: | + yum install -y git openssh-clients + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (replace) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: ignore + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + key_if_exists_fail-key_exists: + name: if_key_exists=fail / key exists + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - centos:7 + - centos:8 + steps: + - name: Install packages + run: | + yum install -y git openssh-clients + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (dummy) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + - name: Install SSH key (replace) + uses: ./. + with: + key: "dummy" # ignored + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: fail + continue-on-error: true + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + key_if_exists_fail-key_doesnt_exist: + name: if_key_exists=fail / key doesn't exist + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - centos:7 + - centos:8 + steps: + - name: Install packages + run: | + yum install -y git openssh-clients + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (replace) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: fail + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + no_known_hosts: + name: no known_hosts file + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - centos:7 + - centos:8 + steps: + - name: Install packages + run: | + yum install -y git openssh-clients + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + no_known_hosts: true + - name: print created files + run: ls -l /root/.ssh diff --git a/.github/workflows/verify-on-container-ubuntu.yml b/.github/workflows/verify-on-container-ubuntu.yml index d290bba..af30c3a 100644 --- a/.github/workflows/verify-on-container-ubuntu.yml +++ b/.github/workflows/verify-on-container-ubuntu.yml @@ -99,3 +99,244 @@ jobs: run: ls -l /root/.ssh - name: git clone through SSH run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + key_if_exists_replace-key_exists: + name: if_key_exists=replace / key exists + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - ubuntu:16.04 + - ubuntu:18.04 + - ubuntu:20.04 + steps: + - name: Install packages + run: | + apt update + apt -y install openssh-client git + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (dummy) + uses: ./. + with: + key: "dummy" # replaced + known_hosts: ${{ secrets.KNOWN_HOSTS }} + - name: Install SSH key (replace) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: replace + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + key_if_exists_replace-key_doesnt_exist: + name: if_key_exists=replace / key doesn't exist + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - ubuntu:16.04 + - ubuntu:18.04 + - ubuntu:20.04 + steps: + - name: Install packages + run: | + apt update + apt -y install openssh-client git + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (replace) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: replace + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + key_if_exists_ignore-key_exists: + name: if_key_exists=ignore / key exists + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - ubuntu:16.04 + - ubuntu:18.04 + - ubuntu:20.04 + steps: + - name: Install packages + run: | + apt update + apt -y install openssh-client git + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (dummy) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + - name: Install SSH key (replace) + uses: ./. + with: + key: "dummy" # ignored + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: ignore + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + key_if_exists_ignore-key_doesnt_exist: + name: if_key_exists=ignore / key doesn't exist + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - ubuntu:16.04 + - ubuntu:18.04 + - ubuntu:20.04 + steps: + - name: Install packages + run: | + apt update + apt -y install openssh-client git + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (replace) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: ignore + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + key_if_exists_fail-key_exists: + name: if_key_exists=fail / key exists + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - ubuntu:16.04 + - ubuntu:18.04 + - ubuntu:20.04 + steps: + - name: Install packages + run: | + apt update + apt -y install openssh-client git + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (dummy) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + - name: Install SSH key (replace) + uses: ./. + with: + key: "dummy" # ignored + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: fail + continue-on-error: true + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + key_if_exists_fail-key_doesnt_exist: + name: if_key_exists=fail / key doesn't exist + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - ubuntu:16.04 + - ubuntu:18.04 + - ubuntu:20.04 + steps: + - name: Install packages + run: | + apt update + apt -y install openssh-client git + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key (replace) + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + known_hosts: ${{ secrets.KNOWN_HOSTS }} + if_key_exists: fail + - name: print created files + run: ls -l /root/.ssh + - name: git clone through SSH + run: git clone git@github.com:shimataro/ssh-key-action.git tmp + + no_known_hosts: + name: no known_hosts file + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-16.04 + - ubuntu-18.04 + - ubuntu-20.04 + container: + - ubuntu:16.04 + - ubuntu:18.04 + - ubuntu:20.04 + steps: + - name: Install packages + run: | + apt update + apt -y install openssh-client git + - name: Checkout source codes + uses: actions/checkout@v2 + - name: Install SSH key + uses: ./. + with: + key: ${{ secrets.SSH_KEY_PEM }} + no_known_hosts: true + - name: print created files + run: ls -l /root/.ssh