-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre.js
44 lines (37 loc) · 1.42 KB
/
pre.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
( async function () {
const exec = require( '@actions/exec' );
const core = require( '@actions/core' );
const fs = require( 'fs' );
if ( core.getInput( 'run-pre', { required: true } ) == 'false' ) {
return;
}
await exec.exec( 'mkdir', ['-p', '/home/runner/.ssh'] );
await exec.exec( 'touch', ['/home/runner/.ssh/known_hosts'] );
const remoteHost = core.getInput( 'env-host', { required: false } );
if( remoteHost != '' ) {
const remotePort = core.getInput( 'env-port', { required: false } );
await exec.exec( 'bash', ['-c', 'ssh-keyscan -p "' + remotePort + '" -H "' + remoteHost + '" >> /home/runner/.ssh/known_hosts' ] );
}
const remoteKey = core.getInput( 'env-key', { required: false } );
if( remoteKey != '' ) {
const sock = '/tmp/ssh_agent.sock';
if( ! fs.existsSync( sock ) ) {
core.exportVariable( 'SSH_AUTH_SOCK', sock );
process.env['SSH_AUTH_SOCK'] = sock;
await exec.exec( 'ssh-agent', ['-a', sock] );
}
var i = 0;
var keyPath;
do {
i++;
keyPath = '/home/runner/.ssh/github_actions_' + i;
} while ( fs.existsSync( keyPath ) );
await exec.exec( 'bash', ['-c', 'echo "' + remoteKey + '" > ' + keyPath ] );
await exec.exec( 'chmod', ['600', keyPath] );
await exec.exec( 'bash', ['-c', 'ssh-add ' + keyPath ] );
}
const remotePass = core.getInput( 'env-pass', { required: false } );
if( remotePass != '' ) {
await exec.exec( 'sudo', ['apt-get', 'install', '-y', 'sshpass'] );
}
} )();