From 36fd7e13438f14f5bcb0612ff7b1922d2b71b88f Mon Sep 17 00:00:00 2001 From: Thorben Nissen Date: Fri, 10 Apr 2020 20:02:05 +0200 Subject: [PATCH] [BUGFIX] Not working properly on self-hosted runner * remove fixed default auth socket path * call `ssh-agent` with auth socket path, if not explicitly given, to let the system choose the path * read SSH_AUTH_SOCKET and SSH_AGENT_PID from `ssh-agent` command output and add the as variables --- action.yml | 1 - index.js | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index bdeeaa6..189ac47 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,6 @@ inputs: required: true ssh-auth-sock: description: 'Where to place the SSH Agent auth socket' - default: /tmp/ssh-auth.sock runs: using: 'node12' main: 'dist/index.js' diff --git a/index.js b/index.js index e141876..7ee6fe7 100644 --- a/index.js +++ b/index.js @@ -22,8 +22,21 @@ try { console.log("Starting ssh-agent"); const authSock = core.getInput('ssh-auth-sock'); - child_process.execFileSync('ssh-agent', ['-a', authSock]); - core.exportVariable('SSH_AUTH_SOCK', authSock); + let sshAgentOutput = '' + if (authSock && authSock.length > 0) { + sshAgentOutput = child_process.execFileSync('ssh-agent', ['-a', authSock]); + } else { + sshAgentOutput = child_process.execFileSync('ssh-agent') + } + + // Extract auth socket path and agent pid and set them as job variables + const lines = sshAgentOutput.toString().split("\n") + for (const lineNumber in lines) { + const matches = /^(SSH_AUTH_SOCK|SSH_AGENT_PID)=(.*); export \1/.exec(lines[lineNumber]) + if (matches && matches.length > 0) { + core.exportVariable(matches[1], matches[2]) + } + } console.log("Adding private key to agent"); privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {