2020-11-10 22:03:10 +00:00
|
|
|
const core = require('@actions/core')
|
|
|
|
const fs = require('fs')
|
|
|
|
const execa = require('execa')
|
2020-12-03 23:05:51 +00:00
|
|
|
const split = require('argv-split')
|
2020-11-10 22:03:10 +00:00
|
|
|
|
|
|
|
void function main() {
|
2020-11-10 22:05:39 +00:00
|
|
|
try {
|
|
|
|
ssh()
|
|
|
|
dep()
|
|
|
|
} catch (err) {
|
|
|
|
core.setFailed(err.message)
|
|
|
|
}
|
2020-11-10 22:03:10 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
function ssh() {
|
|
|
|
let ssh = `${process.env['HOME']}/.ssh`
|
2021-03-07 10:45:33 +00:00
|
|
|
|
|
|
|
if (!fs.existsSync(ssh)) {
|
|
|
|
fs.mkdirSync(ssh)
|
|
|
|
}
|
2020-11-10 22:03:10 +00:00
|
|
|
|
|
|
|
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})
|
|
|
|
|
2021-05-01 09:32:31 +00:00
|
|
|
const knownHosts = core.getInput('known-hosts')
|
|
|
|
if (knownHosts !== '') {
|
2020-11-10 22:03:10 +00:00
|
|
|
fs.appendFileSync(`${ssh}/known_hosts`, knownHosts)
|
|
|
|
fs.chmodSync(`${ssh}/known_hosts`, '644')
|
2021-05-01 09:32:31 +00:00
|
|
|
} else {
|
|
|
|
fs.appendFileSync(`${ssh}/config`, `StrictHostKeyChecking no`)
|
|
|
|
}
|
|
|
|
|
|
|
|
const sshConfig = core.getInput('ssh-config')
|
|
|
|
if (sshConfig !== '') {
|
|
|
|
fs.writeFile(`${ssh}/config`, sshConfig)
|
2020-11-10 22:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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')
|
2021-04-14 18:04:09 +00:00
|
|
|
execa.commandSync('sudo chmod +x deployer.phar')
|
2020-11-10 22:03:10 +00:00
|
|
|
dep = 'deployer.phar'
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:05:51 +00:00
|
|
|
execa.sync(dep, split(core.getInput('dep')))
|
2020-11-10 22:03:10 +00:00
|
|
|
}
|