From d57d85f6f9eda334d867656590271e3497633c3d Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 4 Mar 2021 08:44:02 +0000 Subject: [PATCH] Try to kill the ssh-agent upon action termination on Windows as well --- cleanup.js | 10 ++++++---- dist/cleanup.js | 35 +++++++++++++++++++++++++++++++---- dist/index.js | 43 ++++++++++++++++++++++++++----------------- index.js | 18 +----------------- paths.js | 18 ++++++++++++++++++ 5 files changed, 82 insertions(+), 42 deletions(-) create mode 100644 paths.js diff --git a/cleanup.js b/cleanup.js index f90cddd..529fbe8 100644 --- a/cleanup.js +++ b/cleanup.js @@ -1,10 +1,12 @@ -const core = require('@actions/core') -const { execSync } = require('child_process') +const core = require('@actions/core'); +const { execSync } = require('child_process'); +const { sshAgent } = require('./paths.js'); try { // Kill the started SSH agent - console.log('Stopping SSH agent') - execSync('kill ${SSH_AGENT_PID}', { stdio: 'inherit' }) + console.log('Stopping SSH agent'); + execSync(sshAgent, ['-k'], { stdio: 'inherit' }); + } catch (error) { console.log(error.message); console.log('Error stopping the SSH agent, proceeding anyway'); diff --git a/dist/cleanup.js b/dist/cleanup.js index c8081be..49024b4 100644 --- a/dist/cleanup.js +++ b/dist/cleanup.js @@ -122,13 +122,15 @@ module.exports = require("child_process"); /***/ 175: /***/ (function(__unusedmodule, __unusedexports, __webpack_require__) { -const core = __webpack_require__(470) -const { execSync } = __webpack_require__(129) +const core = __webpack_require__(470); +const { execSync } = __webpack_require__(129); +const { sshAgent } = __webpack_require__(972); try { // Kill the started SSH agent - console.log('Stopping SSH agent') - execSync('kill ${SSH_AGENT_PID}', { stdio: 'inherit' }) + console.log('Stopping SSH agent'); + execSync(sshAgent, ['-k'], { stdio: 'inherit' }); + } catch (error) { console.log(error.message); console.log('Error stopping the SSH agent, proceeding anyway'); @@ -480,6 +482,31 @@ module.exports = require("path"); module.exports = require("fs"); +/***/ }), + +/***/ 972: +/***/ (function(module, __unusedexports, __webpack_require__) { + +const os = __webpack_require__(87); + +module.exports = (process.env['OS'] != 'Windows_NT') ? { + + // 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 + home: os.userInfo().homedir, + sshAgent: 'ssh-agent', + sshAdd: 'ssh-add' + +} : { + + home: os.homedir(), + sshAgent: 'c://progra~1//git//usr//bin//ssh-agent.exe', + sshAdd: 'c://progra~1//git//usr//bin//ssh-add.exe' + +}; + + + /***/ }) /******/ }); \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 198776d..d267179 100644 --- a/dist/index.js +++ b/dist/index.js @@ -118,8 +118,8 @@ exports.issueCommand = issueCommand; const core = __webpack_require__(470); const child_process = __webpack_require__(129); const fs = __webpack_require__(747); -const os = __webpack_require__(87); const crypto = __webpack_require__(417); +const { home, sshAgent, sshAdd } = __webpack_require__(972); try { const privateKey = core.getInput('ssh-private-key'); @@ -130,22 +130,6 @@ try { return; } - const { home, sshAgent, sshAdd } = (process.env['OS'] != 'Windows_NT') ? { - - // 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 - home: os.userInfo().homedir, - sshAgent: 'ssh-agent', - sshAdd: 'ssh-add' - - } : { - - home: os.homedir(), - sshAgent: 'c://progra~1//git//usr//bin//ssh-agent.exe', - sshAdd: 'c://progra~1//git//usr//bin//ssh-add.exe' - - }; - const homeSsh = home + '/.ssh'; console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`); @@ -572,6 +556,31 @@ module.exports = require("path"); module.exports = require("fs"); +/***/ }), + +/***/ 972: +/***/ (function(module, __unusedexports, __webpack_require__) { + +const os = __webpack_require__(87); + +module.exports = (process.env['OS'] != 'Windows_NT') ? { + + // 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 + home: os.userInfo().homedir, + sshAgent: 'ssh-agent', + sshAdd: 'ssh-add' + +} : { + + home: os.homedir(), + sshAgent: 'c://progra~1//git//usr//bin//ssh-agent.exe', + sshAdd: 'c://progra~1//git//usr//bin//ssh-add.exe' + +}; + + + /***/ }) /******/ }); \ No newline at end of file diff --git a/index.js b/index.js index 9bf50bb..e0b06ea 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ const core = require('@actions/core'); const child_process = require('child_process'); const fs = require('fs'); -const os = require('os'); const crypto = require('crypto'); +const { home, sshAgent, sshAdd } = require('./paths.js'); try { const privateKey = core.getInput('ssh-private-key'); @@ -13,22 +13,6 @@ try { return; } - const { home, sshAgent, sshAdd } = (process.env['OS'] != 'Windows_NT') ? { - - // 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 - home: os.userInfo().homedir, - sshAgent: 'ssh-agent', - sshAdd: 'ssh-add' - - } : { - - home: os.homedir(), - sshAgent: 'c://progra~1//git//usr//bin//ssh-agent.exe', - sshAdd: 'c://progra~1//git//usr//bin//ssh-add.exe' - - }; - const homeSsh = home + '/.ssh'; console.log(`Adding GitHub.com keys to ${homeSsh}/known_hosts`); diff --git a/paths.js b/paths.js new file mode 100644 index 0000000..8ee7afd --- /dev/null +++ b/paths.js @@ -0,0 +1,18 @@ +const os = require('os'); + +module.exports = (process.env['OS'] != 'Windows_NT') ? { + + // 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 + home: os.userInfo().homedir, + sshAgent: 'ssh-agent', + sshAdd: 'ssh-add' + +} : { + + home: os.homedir(), + sshAgent: 'c://progra~1//git//usr//bin//ssh-agent.exe', + sshAdd: 'c://progra~1//git//usr//bin//ssh-add.exe' + +}; +