Skip to content

Commit

Permalink
improvements from @peterbe
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebonsignori committed Aug 18, 2022
1 parent abcf940 commit 931bb63
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/actions-scripts/content-changes-table-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand Down
34 changes: 11 additions & 23 deletions .github/actions-scripts/lib/wait-until-url-is-healthy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion .github/workflows/content-changes-table-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit 931bb63

Please sign in to comment.