Skip to content

Commit

Permalink
chore: wait service update before test
Browse files Browse the repository at this point in the history
  • Loading branch information
georgelima committed Apr 12, 2020
1 parent 9cff5ea commit 925e2b3
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const core = require('@actions/core')
const child_process = require('child_process')

try {
const entrypoint = core.getInput('entrypoint')
const asSu = core.getInput('run-as-su')
const serviceName = core.getInput('service-name')

const updateStatus = child_process
const getStatus = ({ entrypoint, asSu, serviceName }) =>
child_process
.execSync(
`${entrypoint || ''} ${
asSu ? 'sudo' : ''
Expand All @@ -15,11 +11,47 @@ try {
.toString()
.trim()

if (updateStatus !== 'completed') {
return core.setFailed(`${serviceName} update status is: ${updateStatus}, please verify your deployment!`)
}
const awaitUpdate = ({ entrypoint, asSu, serviceName }) =>
new Promise((resolve, reject) => {
let interval

try {
interval = setInterval(() => {
const updateStatus = getStatus({ entrypoint, asSu, serviceName })
if (updateStatus === 'updating') {
console.log(`Service status: ${updateStatus}`)
return
}

clearInterval(interval)
resolve()
}, 3000)
} catch (err) {
if (interval) clearInterval(interval)
reject(err)
}
})

async function run() {
try {
const entrypoint = core.getInput('entrypoint')
const asSu = core.getInput('run-as-su')
const serviceName = core.getInput('service-name')

console.log('Waiting service update...')

console.log('All good!')
} catch (err) {
core.setFailed(err.message)
await awaitUpdate({ entrypoint, asSu, serviceName })

const updateStatus = getStatus({ entrypoint, asSu, serviceName })

if (updateStatus !== 'completed') {
return core.setFailed(`${serviceName} update status is: ${updateStatus}, please verify your deployment!`)
}

console.log('All good!')
} catch (err) {
core.setFailed(err.message)
}
}

run()

0 comments on commit 925e2b3

Please sign in to comment.