Skip to content

Commit 617984c

Browse files
authored
Merge pull request #6 from sourcetoad/pmw-41-add-ssh-port
Add ssh port option
2 parents 74f2139 + c19a682 commit 617984c

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Setup an SSH socket with a private key.
66
#### `host`
77
**Required** Remote hostname
88

9+
#### `port`
10+
**Optional** SSH port
11+
12+
This is only necessary if the SSH server does not listen on port 22. It is used to retrieve the host key so it can be trusted for host key verification.
13+
914
#### `socket-path`
1015
**Required** Path at which to create socket.
1116

@@ -29,6 +34,7 @@ Path at which socket was created.
2934
uses: sourcetoad/[email protected]
3035
with:
3136
host: github.com
37+
port: 22 # optional
3238
socket-path: /tmp/ssh_agent.sock
3339
key: {BASE64_SECRET_KEY}
3440

action.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ description: 'Setup an SSH socket with a private key'
33
inputs:
44
host:
55
description: 'remote hostname'
6-
require: true
6+
required: true
7+
port:
8+
description: 'ssh port'
9+
required: false
710
socket-path:
811
description: 'path at which to create socket'
912
required: true

dist/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -301,27 +301,29 @@ const core = __webpack_require__(68);
301301
const { execSync } = __webpack_require__(129);
302302

303303
const host = core.getInput('host');
304+
const port = core.getInput('port');
304305
const socketPath = core.getInput('socket-path');
305306
const key = core.getInput('key');
306307

307308
console.log(`Attempting to create ${socketPath}...`);
308309
try {
309310
execSync(
310311
'mkdir ~/.ssh && ' +
311-
`ssh-keyscan "${host}" >> ~/.ssh/known_hosts && ` +
312+
`ssh-keyscan${port ? ` -p ${port}` : ''} "${host}" >> ~/.ssh/known_hosts && ` +
312313
`eval $(ssh-agent -a "${socketPath}") && ` +
313314
`echo "${key}" | base64 -d | ssh-add -`
314315
);
315316
} catch (e) {
316317
console.error(e.message);
317-
process.exit();
318+
process.exit(1);
318319
}
319320

320321
console.log(`Created ${socketPath}`);
321322
core.setOutput('socket-path', socketPath);
322323

323324
console.log('Done; exiting.');
324325

326+
325327
/***/ }),
326328

327329
/***/ 955:

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ const core = require('@actions/core');
33
const { execSync } = require('child_process');
44

55
const host = core.getInput('host');
6+
const port = core.getInput('port');
67
const socketPath = core.getInput('socket-path');
78
const key = core.getInput('key');
89

910
console.log(`Attempting to create ${socketPath}...`);
1011
try {
1112
execSync(
1213
'mkdir ~/.ssh && ' +
13-
`ssh-keyscan "${host}" >> ~/.ssh/known_hosts && ` +
14+
`ssh-keyscan${port ? ` -p ${port}` : ''} "${host}" >> ~/.ssh/known_hosts && ` +
1415
`eval $(ssh-agent -a "${socketPath}") && ` +
1516
`echo "${key}" | base64 -d | ssh-add -`
1617
);

0 commit comments

Comments
 (0)