improvements from @peterbe
This commit is contained in:
@@ -31,7 +31,7 @@ const PROD_URL = 'https://docs.github.com'
|
||||
run()
|
||||
|
||||
async function run() {
|
||||
const isHealthy = await waitUntilUrlIsHealthy(APP_URL)
|
||||
const isHealthy = await waitUntilUrlIsHealthy(new URL('/healthz', APP_URL).toString())
|
||||
if (!isHealthy) {
|
||||
return core.setFailed(`Timeout waiting for preview environment: ${APP_URL}`)
|
||||
}
|
||||
|
||||
@@ -6,29 +6,17 @@ const DELAY_SECONDS = 15
|
||||
|
||||
/*
|
||||
* Promise resolves once url is healthy or fails if timeout has passed
|
||||
* @param {string} url - path to server
|
||||
* @param {string} [healthPath] - endpoint to health check, e.g. "healthz"
|
||||
* @param {string} url - health url, e.g. docs.com/healthz
|
||||
*/
|
||||
export async function waitUntilUrlIsHealthy(url, healthPath = 'healthz') {
|
||||
let attempt = 1
|
||||
while (attempt < RETRIES) {
|
||||
try {
|
||||
const res = await got.head(`${url}/${healthPath}`)
|
||||
if (res.statusCode === 200) {
|
||||
return true
|
||||
}
|
||||
} catch (err) {}
|
||||
// Delay before next attempt
|
||||
await sleep(DELAY_SECONDS)
|
||||
attempt++
|
||||
}
|
||||
export async function waitUntilUrlIsHealthy(url) {
|
||||
try {
|
||||
await got.head(url, {
|
||||
retry: {
|
||||
limit: RETRIES,
|
||||
calculateDelay: () => DELAY_SECONDS * 1000,
|
||||
},
|
||||
})
|
||||
return true
|
||||
} catch {}
|
||||
return false
|
||||
}
|
||||
|
||||
/*
|
||||
* Async-await sleep
|
||||
* @param {string} seconds - Seconds to sleep
|
||||
*/
|
||||
export async function sleep(seconds) {
|
||||
return new Promise((resolve) => setTimeout(resolve, seconds * 1000))
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ jobs:
|
||||
|
||||
- name: Get changes table
|
||||
id: changes
|
||||
timeout-minutes: 20
|
||||
timeout-minutes: 30
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
APP_URL: ${{ env.APP_URL }}
|
||||
|
||||
Reference in New Issue
Block a user