forked from deployphp/action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (42 loc) · 1.14 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
const core = require('@actions/core')
const fs = require('fs')
const execa = require('execa')
const split = require('argv-split')
void function main() {
try {
ssh()
dep()
} catch (err) {
core.setFailed(err.message)
}
}()
function ssh() {
let ssh = `${process.env['HOME']}/.ssh`
fs.mkdirSync(ssh)
let authSock = '/tmp/ssh-auth.sock'
execa.sync('ssh-agent', ['-a', authSock])
core.exportVariable('SSH_AUTH_SOCK', authSock)
let privateKey = core.getInput('private-key').replace('/\r/g', '').trim() + '\n'
execa.sync('ssh-add', ['-'], {input: privateKey})
let knownHosts = core.getInput('known-hosts')
if (knownHosts === '') {
fs.appendFileSync(`${ssh}/config`, `StrictHostKeyChecking no`)
} else {
fs.appendFileSync(`${ssh}/known_hosts`, knownHosts)
fs.chmodSync(`${ssh}/known_hosts`, '644')
}
}
function dep() {
let dep
for (let c of ['vendor/bin/dep', 'bin/dep', 'deployer.phar']) {
if (fs.existsSync(c)) {
dep = c
break
}
}
if (!dep) {
execa.commandSync('curl -LO https://deployer.org/deployer.phar')
dep = 'deployer.phar'
}
execa.sync(dep, split(core.getInput('dep')))
}