From 1606d19f150935adbeb1471c7922d490540218d8 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Mon, 1 Mar 2021 09:24:06 +0000 Subject: [PATCH] Preserve process.env so the PATH (and possibly other) vars are availabe --- dist/index.js | 19 +++++++++---------- index.js | 12 ++---------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/dist/index.js b/dist/index.js index 25a36a6..4dfcbdd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -119,8 +119,7 @@ const core = __webpack_require__(470); const child_process = __webpack_require__(129); const fs = __webpack_require__(747); const os = __webpack_require__(87); -//const token = require('crypto').randomBytes(64).toString('hex'); -const token = 'test'; +const token = __webpack_require__(417).randomBytes(64).toString('hex'); try { const privateKey = core.getInput('ssh-private-key'); @@ -192,14 +191,7 @@ try { } // Load key into agent - let sshAdd = undefined; - - try { - sshAdd = child_process.execSync(`ssh-add ${keyFile}`, { env: { 'DISPLAY': 'fake', 'SSH_PASS': token, 'SSH_ASKPASS': process.cwd() + '/askpass.exe' }, stdio: 'inherit', input: '' }); - } catch (exception) { - console.log(sshAdd, exception); - throw exception; - } + child_process.execFileSync('ssh-add', [keyFile], { env: { ...process.env, ...{ 'DISPLAY': 'fake', 'SSH_PASS': token, 'SSH_ASKPASS': 'D:\\a\\ssh-agent\\ssh-agent\\askpass.exe' } } }); output.toString().split(/\r?\n/).forEach(function(key) { let parts = key.match(/^Key has comment '.*\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+?)(?=\.git|\s|\')/); @@ -244,6 +236,13 @@ module.exports = require("child_process"); /***/ }), +/***/ 417: +/***/ (function(module) { + +module.exports = require("crypto"); + +/***/ }), + /***/ 431: /***/ (function(__unusedmodule, exports, __webpack_require__) { diff --git a/index.js b/index.js index 815a1e7..55e6ff3 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,7 @@ const core = require('@actions/core'); const child_process = require('child_process'); const fs = require('fs'); const os = require('os'); -//const token = require('crypto').randomBytes(64).toString('hex'); -const token = 'test'; +const token = require('crypto').randomBytes(64).toString('hex'); try { const privateKey = core.getInput('ssh-private-key'); @@ -75,14 +74,7 @@ try { } // Load key into agent - let sshAdd = undefined; - - try { - sshAdd = child_process.execSync(`ssh-add ${keyFile}`, { env: { 'DISPLAY': 'fake', 'SSH_PASS': token, 'SSH_ASKPASS': process.cwd() + '/askpass.exe' }, stdio: 'inherit', input: '' }); - } catch (exception) { - console.log(sshAdd, exception); - throw exception; - } + child_process.execFileSync('ssh-add', [keyFile], { env: { ...process.env, ...{ 'DISPLAY': 'fake', 'SSH_PASS': token, 'SSH_ASKPASS': 'D:\\a\\ssh-agent\\ssh-agent\\askpass.exe' } } }); output.toString().split(/\r?\n/).forEach(function(key) { let parts = key.match(/^Key has comment '.*\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+?)(?=\.git|\s|\')/);