-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
67 lines (56 loc) · 1.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const core = require("@actions/core");
const proc = require("child_process");
const fs = require("fs");
function run() {
try {
if (!fs.existsSync(`${process.env["HOME"]}/.ssh`)) {
fs.mkdirSync(`${process.env["HOME"]}/.ssh`, { recursive: true });
}
console.log("Building known hosts");
proc.execSync(
`ssh-keyscan -p ${core.getInput("ssh_port")} ${core.getInput(
"domain",
)} >> ${process.env["HOME"]}/.ssh/known_hosts`,
{
stdio: [null, null, null],
timeout: 20000,
},
);
console.log("Finished building known hosts!");
console.log("Starting ssh-agent");
var sshOutput = proc.execFileSync(`ssh-agent`, [
"-a",
core.getInput("ssh_auth_sock"),
]);
sshOutput
.toString()
.split("\n")
.forEach((line) => {
var regexp = /=(.*); /g;
if (line.includes("SSH_AUTH_SOCK")) {
const sock = regexp.exec(line)[1];
core.exportVariable("SSH_AUTH_SOCK", sock);
console.log(`Agent socket is ${sock}`);
}
if (line.includes("SSH_AGENT_PID")) {
const pid = regexp.exec(line)[1];
core.exportVariable("SSH_AGENT_PID", pid);
console.log(`Agent PID is ${pid}`);
}
});
console.log("Exported agent variables");
console.log("Started ssh-agent!");
console.log("Adding identity");
proc.execSync("ssh-add -", {
stdio: [null, null, null],
input: core.getInput("private_key").trim() + "\n",
});
console.log("Added identity!");
console.log("ssh-agent is ready to use");
} catch (error) {
console.log("Encountered an error:");
console.log(error.message);
process.exit(1);
}
}
run();