2019-09-14 18:28:16 -04:00
const core = require ( '@actions/core' ) ;
const child _process = require ( 'child_process' ) ;
const fs = require ( 'fs' ) ;
try {
2020-01-14 04:29:16 -05:00
2019-09-15 03:32:43 -04:00
const home = process . env [ 'HOME' ] ;
const homeSsh = home + '/.ssh' ;
2020-01-14 04:29:16 -05:00
const privateKey = core . getInput ( 'ssh-private-key' ) . trim ( ) ;
if ( ! privateKey ) {
core . setFailed ( "The ssh-private-key argument is empty. Maybe the secret has not been configured, or you are using a wrong secret name in your workflow file." ) ;
return ;
}
2019-09-15 03:32:43 -04:00
console . log ( ` Adding GitHub.com keys to ${ homeSsh } /known_hosts ` ) ;
fs . mkdirSync ( homeSsh , { recursive : true } ) ;
fs . appendFileSync ( ` ${ homeSsh } /known_hosts ` , '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n' ) ;
fs . appendFileSync ( ` ${ homeSsh } /known_hosts ` , '\ngithub.com ssh-dss AAAAB3NzaC1kc3MAAACBANGFW2P9xlGU3zWrymJgI/lKo//ZW2WfVtmbsUZJ5uyKArtlQOT2+WRhcg4979aFxgKdcsqAYW3/LS1T2km3jYW/vr4Uzn+dXWODVk5VlUiZ1HFOHf6s6ITcZvjvdbp6ZbpM+DuJT7Bw+h5Fx8Qt8I16oCZYmAPJRtu46o9C2zk1AAAAFQC4gdFGcSbp5Gr0Wd5Ay/jtcldMewAAAIATTgn4sY4Nem/FQE+XJlyUQptPWMem5fwOcWtSXiTKaaN0lkk2p2snz+EJvAGXGq9dTSWHyLJSM2W6ZdQDqWJ1k+cL8CARAqL+UMwF84CR0m3hj+wtVGD/J4G5kW2DBAf4/bqzP4469lT+dF2FRQ2L9JKXrCWcnhMtJUvua8dvnwAAAIB6C4nQfAA7x8oLta6tT+oCk2WQcydNsyugE8vLrHlogoWEicla6cWPk7oXSspbzUcfkjN3Qa6e74PhRkc7JdSdAlFzU3m7LMkXo1MHgkqNX8glxWNVqBSc0YRdbFdTkL0C6gtpklilhvuHQCdbgB3LBAikcRkDp+FCVkUgPC/7Rw==\n' ) ;
2019-09-14 18:28:16 -04:00
console . log ( "Starting ssh-agent" ) ;
const authSock = core . getInput ( 'ssh-auth-sock' ) ;
child _process . execFileSync ( 'ssh-agent' , [ '-a' , authSock ] ) ;
core . exportVariable ( 'SSH_AUTH_SOCK' , authSock ) ;
console . log ( "Adding private key to agent" ) ;
2020-01-14 04:29:16 -05:00
privateKey . split ( /(?=-----BEGIN)/ ) . forEach ( function ( key ) {
2020-01-14 04:21:11 -05:00
child _process . execSync ( 'ssh-add -' , { input : key . trim ( ) + "\n" } ) ;
} ) ;
2020-01-14 04:29:16 -05:00
2020-01-14 04:21:11 -05:00
console . log ( "Keys added:" ) ;
child _process . execSync ( 'ssh-add -l' , { stdio : 'inherit' } ) ;
2020-01-14 04:29:16 -05:00
2019-09-14 18:28:16 -04:00
} catch ( error ) {
core . setFailed ( error . message ) ;
}