From 6d285f5b6b29e2feb6bc12b67a37aac54a65b8e3 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 12 Feb 2021 17:09:58 +0000 Subject: [PATCH 1/5] Try different home dir detection as suggested in #38 --- dist/index.js | 9 +++++++-- index.js | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 173d8ea..8f07a29 100644 --- a/dist/index.js +++ b/dist/index.js @@ -118,12 +118,12 @@ exports.issueCommand = issueCommand; const core = __webpack_require__(470); const child_process = __webpack_require__(129); const fs = __webpack_require__(747); +const os = __webpack_require__(87); try { - const home = process.env['HOME']; + const home = os.homedir(); const homeSsh = home + '/.ssh'; - const privateKey = core.getInput('ssh-private-key'); if (!privateKey) { @@ -132,6 +132,11 @@ try { return; } + if (process.env['OS'] == 'Windows_NT') { + console.log('Preparing ssh-agent service on Windows'); + child_process.execSync('sc config ssh-agent start=demand', { stdio: 'inherit' }); + } + console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`); fs.mkdirSync(homeSsh, { recursive: true }); fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n'); diff --git a/index.js b/index.js index 7ee6fe7..52dbb1c 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,12 @@ const core = require('@actions/core'); const child_process = require('child_process'); const fs = require('fs'); +const os = require('os'); try { - const home = process.env['HOME']; + const home = os.homedir(); const homeSsh = home + '/.ssh'; - const privateKey = core.getInput('ssh-private-key'); if (!privateKey) { @@ -15,6 +15,11 @@ try { return; } + if (process.env['OS'] == 'Windows_NT') { + console.log('Preparing ssh-agent service on Windows'); + child_process.execSync('sc config ssh-agent start=demand', { stdio: 'inherit' }); + } + console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`); fs.mkdirSync(homeSsh, { recursive: true }); fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n'); From e20d8b470b1a6ff5efccbf1b42dee66e00858fe0 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 12 Feb 2021 17:12:27 +0000 Subject: [PATCH 2/5] Setup demo windows-latest run --- .github/workflows/demo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index 5fb24b6..91daa2a 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -4,7 +4,7 @@ jobs: single_key_demo: strategy: matrix: - os: [ubuntu-latest, macOS-latest] + os: [ubuntu-latest, macOS-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v1 From 60ca2a5b53a4caeb7cb228f648090b447fe5a6d2 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 12 Feb 2021 17:56:37 +0000 Subject: [PATCH 3/5] Try running a container-based demo as well --- .github/workflows/demo.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index 91daa2a..cec28ad 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -26,3 +26,16 @@ jobs: uses: ./ with: ssh-private-key: ${{ secrets.DEMO_KEY }} + + docker_demo: + runs-on: ubuntu-latest + container: + image: ubuntu:latest + steps: + - uses: actions/checkout@v1 + - name: Setup key + uses: ./ + with: + ssh-private-key: | + ${{ secrets.DEMO_KEY }} + ${{ secrets.DEMO_KEY_2 }} From c95dfdcede04db6a7ae7816a2c0db096170732c7 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 12 Feb 2021 20:12:28 +0000 Subject: [PATCH 4/5] Use os.userInfo() to obtain the getpwent()-based home directory --- dist/index.js | 13 ++++++++++--- index.js | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8f07a29..e90c339 100644 --- a/dist/index.js +++ b/dist/index.js @@ -121,9 +121,6 @@ const fs = __webpack_require__(747); const os = __webpack_require__(87); try { - - const home = os.homedir(); - const homeSsh = home + '/.ssh'; const privateKey = core.getInput('ssh-private-key'); if (!privateKey) { @@ -132,11 +129,21 @@ try { return; } + var home; + if (process.env['OS'] == 'Windows_NT') { console.log('Preparing ssh-agent service on Windows'); child_process.execSync('sc config ssh-agent start=demand', { stdio: 'inherit' }); + + home = os.homedir(); + } else { + // Use getent() system call, since this is what ssh does; makes a difference in Docker-based + // Action runs, where $HOME is different from the pwent + var { homedir: home } = os.userInfo(); } + const homeSsh = home + '/.ssh'; + console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`); fs.mkdirSync(homeSsh, { recursive: true }); fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n'); diff --git a/index.js b/index.js index 52dbb1c..c4f5049 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,6 @@ const fs = require('fs'); const os = require('os'); try { - - const home = os.homedir(); - const homeSsh = home + '/.ssh'; const privateKey = core.getInput('ssh-private-key'); if (!privateKey) { @@ -15,11 +12,21 @@ try { return; } + var home; + if (process.env['OS'] == 'Windows_NT') { console.log('Preparing ssh-agent service on Windows'); child_process.execSync('sc config ssh-agent start=demand', { stdio: 'inherit' }); + + home = os.homedir(); + } else { + // Use getent() system call, since this is what ssh does; makes a difference in Docker-based + // Action runs, where $HOME is different from the pwent + var { homedir: home } = os.userInfo(); } + const homeSsh = home + '/.ssh'; + console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`); fs.mkdirSync(homeSsh, { recursive: true }); fs.appendFileSync(`${homeSsh}/known_hosts`, '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n'); From 028a5ccee47eb3071d7482b6abdda9171c8beceb Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Sat, 13 Feb 2021 13:12:02 +0000 Subject: [PATCH 5/5] Install SSH in the Docker container to test Docker-based Action runs --- .github/workflows/demo.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index cec28ad..2b34888 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -33,6 +33,7 @@ jobs: image: ubuntu:latest steps: - uses: actions/checkout@v1 + - run: apt update && apt install -y openssh-client - name: Setup key uses: ./ with: