deployphp/index.js

68 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2020-11-10 22:03:10 +00:00
const core = require('@actions/core')
const fs = require('fs')
const execa = require('execa')
2021-10-15 20:41:21 +00:00
void async function main() {
2020-11-10 22:05:39 +00:00
try {
2021-10-15 20:41:21 +00:00
await ssh()
await dep()
2020-11-10 22:05:39 +00:00
} catch (err) {
core.setFailed(err.message)
}
2020-11-10 22:03:10 +00:00
}()
2021-10-15 20:41:21 +00:00
async function ssh() {
2020-11-10 22:03:10 +00:00
let ssh = `${process.env['HOME']}/.ssh`
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`, '600')
2021-05-01 09:32:31 +00:00
} else {
fs.appendFileSync(`${ssh}/config`, `StrictHostKeyChecking no`)
fs.chmodSync(`${ssh}/config`, '600')
2021-05-01 09:32:31 +00:00
}
const sshConfig = core.getInput('ssh-config')
if (sshConfig !== '') {
2021-10-15 20:41:21 +00:00
fs.writeFileSync(`${ssh}/config`, sshConfig)
fs.chmodSync(`${ssh}/config`, '600')
2020-11-10 22:03:10 +00:00
}
}
2021-10-15 20:41:21 +00:00
async function dep() {
2020-11-10 22:03:10 +00:00
let dep
2021-10-15 20:41:21 +00:00
for (let c of ['vendor/bin/dep', 'deployer.phar']) {
2020-11-10 22:03:10 +00:00
if (fs.existsSync(c)) {
dep = c
break
}
}
if (!dep) {
execa.commandSync('curl -LO https://deployer.org/deployer.phar')
execa.commandSync('sudo chmod +x deployer.phar')
2021-10-15 20:41:21 +00:00
dep = 'deployer.phar'
2020-11-10 22:03:10 +00:00
}
2021-10-15 20:41:21 +00:00
let p = execa.command(`php ${dep} ${core.getInput('dep')}`)
p.stdout.pipe(process.stdout)
p.stderr.pipe(process.stderr)
try {
await p
} catch (err) {
core.setFailed(err.shortMessage)
2021-10-15 20:41:21 +00:00
}
2020-11-10 22:03:10 +00:00
}