-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (39 loc) · 1.33 KB
/
index.js
File metadata and controls
48 lines (39 loc) · 1.33 KB
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
/**
* Setup Secure Shell (SSH)
*
* @package SetupSSH
*/
// Node Dependencies
const fs = require( 'fs' );
const path = require( 'path' );
// External Dependencies
const core = require( '@actions/core' );
const exec = require( '@actions/exec' );
const io = require( '@actions/io' );
async function run() {
try {
const SSH_AUTH_SOCK = '/tmp/ssh-auth.sock';
const SSH_DIR = path.join( process.env['HOME'], '.ssh' );
const CONFIG = core.getInput( 'ssh-config' );
const KNOWN_HOSTS = core.getInput( 'ssh-known-hosts' );
const PRIVATE_KEY = core.getInput( 'ssh-private-key' );
// Set the default write options for files.
const WRITE_OPTIONS = {
mode: 0o600,
};
// First, ensure the ~/.ssh exists.
await io.mkdirP( SSH_DIR );
// If the user has passed a configuration file, add it.
if ( CONFIG ) {
await fs.writeFileSync( path.join( SSH_DIR, 'config' ), CONFIG, WRITE_OPTIONS );
}
fs.writeFileSync( path.join( SSH_DIR, 'known_hosts' ), KNOWN_HOSTS, WRITE_OPTIONS );
fs.writeFileSync( path.join( SSH_DIR, 'id_rsa' ), PRIVATE_KEY, WRITE_OPTIONS );
await exec.exec( 'ssh-agent', [ '-a', SSH_AUTH_SOCK ] );
await core.exportVariable( 'SSH_AUTH_SOCK', SSH_AUTH_SOCK );
await exec.exec( `ssh-add ${ path.join( SSH_DIR, 'id_rsa' ) }` );
} catch ( error ) {
core.setFailed( error.message );
}
}
run()