mirror of
https://github.com/webfactory/ssh-agent.git
synced 2025-04-24 23:12:13 +00:00
[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:
parent
716fbacac2
commit
36fd7e1343
2 changed files with 15 additions and 3 deletions
|
@ -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'
|
||||
|
|
17
index.js
17
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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue