Skip to content

Commit 66ce3b4

Browse files
committed
Reuse existing SSH agent socket
1 parent a1b46c2 commit 66ce3b4

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

dist/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36644,9 +36644,13 @@ async function ssh() {
3664436644
if (getBooleanInput("skip-ssh-setup")) return;
3664536645
const sshHomeDir = `${process.env["HOME"]}/.ssh`;
3664636646
if (!fs.existsSync(sshHomeDir)) fs.mkdirSync(sshHomeDir);
36647-
const authSock = "/tmp/ssh-auth.sock";
36648-
await $`ssh-agent -a ${authSock}`;
36649-
exportVariable("SSH_AUTH_SOCK", authSock);
36647+
const existingAuthSock = process.env["SSH_AUTH_SOCK"];
36648+
if (existingAuthSock !== void 0 && existingAuthSock !== "" && fs.existsSync(existingAuthSock)) console.log(`Using existing SSH agent socket at ${existingAuthSock}.`);
36649+
else {
36650+
const authSock = "/tmp/ssh-auth.sock";
36651+
await $`ssh-agent -a ${authSock}`;
36652+
exportVariable("SSH_AUTH_SOCK", authSock);
36653+
}
3665036654
let privateKey = getInput("private-key");
3665136655
if (privateKey !== "") {
3665236656
privateKey = privateKey.replace(/\r/g, "").trim() + "\n";

src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ async function ssh(): Promise<void> {
3333
fs.mkdirSync(sshHomeDir)
3434
}
3535

36-
const authSock = '/tmp/ssh-auth.sock'
37-
await $`ssh-agent -a ${authSock}`
38-
core.exportVariable('SSH_AUTH_SOCK', authSock)
36+
const existingAuthSock = process.env['SSH_AUTH_SOCK']
37+
if (existingAuthSock !== undefined && existingAuthSock !== '' && fs.existsSync(existingAuthSock)) {
38+
console.log(`Using existing SSH agent socket at ${existingAuthSock}.`)
39+
} else {
40+
const authSock = '/tmp/ssh-auth.sock'
41+
await $`ssh-agent -a ${authSock}`
42+
core.exportVariable('SSH_AUTH_SOCK', authSock)
43+
}
3944

4045
let privateKey = core.getInput('private-key')
4146
if (privateKey !== '') {

0 commit comments

Comments
 (0)