[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
This commit is contained in:
Thorben Nissen 2020-04-10 20:02:05 +02:00
parent 716fbacac2
commit 36fd7e1343
2 changed files with 15 additions and 3 deletions

View file

@ -6,7 +6,6 @@ inputs:
required: true required: true
ssh-auth-sock: ssh-auth-sock:
description: 'Where to place the SSH Agent auth socket' description: 'Where to place the SSH Agent auth socket'
default: /tmp/ssh-auth.sock
runs: runs:
using: 'node12' using: 'node12'
main: 'dist/index.js' main: 'dist/index.js'

View file

@ -22,8 +22,21 @@ try {
console.log("Starting ssh-agent"); console.log("Starting ssh-agent");
const authSock = core.getInput('ssh-auth-sock'); const authSock = core.getInput('ssh-auth-sock');
child_process.execFileSync('ssh-agent', ['-a', authSock]); let sshAgentOutput = ''
core.exportVariable('SSH_AUTH_SOCK', authSock); 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"); console.log("Adding private key to agent");
privateKey.split(/(?=-----BEGIN)/).forEach(function(key) { privateKey.split(/(?=-----BEGIN)/).forEach(function(key) {