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() {
|
2021-10-15 21:07:42 +00:00
|
|
|
let sshHomeDir = `${process.env['HOME']}/.ssh`
|
2021-03-07 10:45:33 +00:00
|
|
|
|
2021-10-15 21:07:42 +00:00
|
|
|
if (!fs.existsSync(sshHomeDir)) {
|
|
|
|
fs.mkdirSync(sshHomeDir)
|
2021-03-07 10:45:33 +00:00
|
|
|
}
|
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 !== '') {
|
2021-10-15 21:07:42 +00:00
|
|
|
fs.appendFileSync(`${sshHomeDir}/known_hosts`, knownHosts)
|
|
|
|
fs.chmodSync(`${sshHomeDir}/known_hosts`, '600')
|
2021-05-01 09:32:31 +00:00
|
|
|
} else {
|
2021-10-15 21:07:42 +00:00
|
|
|
fs.appendFileSync(`${sshHomeDir}/config`, `StrictHostKeyChecking no`)
|
|
|
|
fs.chmodSync(`${sshHomeDir}/config`, '600')
|
2021-05-01 09:32:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 21:07:42 +00:00
|
|
|
let sshConfig = core.getInput('ssh-config')
|
2021-05-01 09:32:31 +00:00
|
|
|
if (sshConfig !== '') {
|
2021-10-15 21:07:42 +00:00
|
|
|
fs.writeFileSync(`${sshHomeDir}/config`, sshConfig)
|
|
|
|
fs.chmodSync(`${sshHomeDir}/config`, '600')
|
2020-11-10 22:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-15 20:41:21 +00:00
|
|
|
async function dep() {
|
2021-10-21 20:08:17 +00:00
|
|
|
let dep = core.getInput('deployer-binary')
|
|
|
|
|
|
|
|
if (dep === '')
|
2022-03-19 17:21:46 +00:00
|
|
|
for (let c of ['vendor/bin/deployer.phar', 'vendor/bin/dep', 'deployer.phar']) {
|
2020-11-10 22:03:10 +00:00
|
|
|
if (fs.existsSync(c)) {
|
|
|
|
dep = c
|
2021-10-15 21:34:50 +00:00
|
|
|
console.log(`Using "${c}".`)
|
2020-11-10 22:03:10 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:08:17 +00:00
|
|
|
if (dep === '') {
|
2021-10-15 21:07:42 +00:00
|
|
|
let version = core.getInput('deployer-version')
|
|
|
|
if (version === '') {
|
2021-10-15 21:34:50 +00:00
|
|
|
console.log(`Downloading "https://deployer.org/deployer.phar".`)
|
2021-10-15 21:07:42 +00:00
|
|
|
execa.commandSync('curl -LO https://deployer.org/deployer.phar')
|
|
|
|
} else {
|
2021-10-24 17:26:47 +00:00
|
|
|
version = version.replace(/^v/, '')
|
|
|
|
let {stdout} = execa.commandSync(`curl -L https://deployer.org/manifest.json`)
|
|
|
|
let manifest = JSON.parse(stdout)
|
|
|
|
let url
|
|
|
|
for (let asset of manifest) {
|
|
|
|
if (asset.version === version) {
|
|
|
|
url = asset.url
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (url === null) {
|
2022-03-19 15:21:18 +00:00
|
|
|
console.error(`The version "${version}"" does not exist in the "https://deployer.org/manifest.json" file."`)
|
2021-10-24 17:26:47 +00:00
|
|
|
} else {
|
|
|
|
console.log(`Downloading "${url}".`)
|
|
|
|
execa.commandSync(`curl -LO ${url}`)
|
2021-10-15 21:07:42 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-14 18:04:09 +00:00
|
|
|
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 21:20:14 +00:00
|
|
|
let cmd = core.getInput('dep')
|
2022-08-17 13:46:44 +00:00
|
|
|
let ansi = core.getBooleanInput('ansi') ? '--ansi' : '--no-ansi';
|
|
|
|
let verbosity = core.getInput('verbosity');
|
2021-10-15 21:20:14 +00:00
|
|
|
|
2022-08-17 13:46:44 +00:00
|
|
|
let p = execa.command(`php ${dep} --no-interaction ${ansi} ${verbosity} ${cmd}`)
|
2021-10-15 20:41:21 +00:00
|
|
|
p.stdout.pipe(process.stdout)
|
|
|
|
p.stderr.pipe(process.stderr)
|
2021-10-15 21:20:14 +00:00
|
|
|
|
2021-10-15 20:41:21 +00:00
|
|
|
try {
|
|
|
|
await p
|
|
|
|
} catch (err) {
|
2021-10-15 21:20:14 +00:00
|
|
|
core.setFailed(`Failed: dep ${cmd}`)
|
2021-10-15 20:41:21 +00:00
|
|
|
}
|
2020-11-10 22:03:10 +00:00
|
|
|
}
|