iw4_bot_warfare/deploy.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-06-18 00:29:49 -06:00
// nodejs 14+
const exec = require('util').promisify(require('child_process').exec)
const repo_name = 'iw4x_bot_warfare'
const repo_url = `https://github.com/ineedbots/${repo_name}`
const deploy_check_rate = 60000
2021-06-18 13:53:52 -06:00
const title = 'IW4x Bot Warfare Git Deployer'
2021-06-18 00:29:49 -06:00
2021-06-18 13:53:52 -06:00
function printToConsole(what, error = false)
2021-06-18 00:34:10 -06:00
{
2021-06-18 13:53:52 -06:00
log = error ? console.error : console.log
2021-06-18 00:34:10 -06:00
2021-06-18 13:53:52 -06:00
log(`[${new Date().toISOString()}]:`, what)
}
2021-06-18 00:34:10 -06:00
2021-06-18 00:29:49 -06:00
async function doDeploy() {
try {
const { stdout, stderr } = await exec(`cd ${repo_name} && git fetch`)
if (stderr.length <= 0)
return
if (stderr.startsWith('From '))
{
2021-06-18 13:53:52 -06:00
printToConsole('git fetched! Pulling...')
2021-06-18 00:29:49 -06:00
await exec(`cd ${repo_name} && git pull && git submodule update --init --recursive`)
2021-06-18 13:53:52 -06:00
printToConsole('Deploying...')
2021-06-18 00:29:49 -06:00
await exec('deploy.bat')
2021-06-18 13:53:52 -06:00
printToConsole('Deployed!')
2021-06-18 00:29:49 -06:00
}
} catch (e) {
2021-06-18 13:53:52 -06:00
printToConsole(e, true)
2021-06-18 00:29:49 -06:00
2021-06-18 13:53:52 -06:00
if (!e.stderr.startsWith('The system cannot find the path specified'))
return
printToConsole('Cloning repo...')
2021-06-18 00:29:49 -06:00
try {
await exec(`git clone ${repo_url} && cd ${repo_name} && git submodule update --init --recursive`)
2021-06-18 13:53:52 -06:00
printToConsole('Cloned!')
2021-06-18 00:29:49 -06:00
} catch (f) {
2021-06-18 13:53:52 -06:00
printToConsole(f, true)
2021-06-18 00:29:49 -06:00
}
}
}
2021-06-18 13:53:52 -06:00
process.stdout.write(`${String.fromCharCode(27)}]0;${title}${String.fromCharCode(7)}`)
doDeploy()
2021-06-18 00:29:49 -06:00
setInterval(doDeploy, deploy_check_rate)