From 931bb63733a2d765be7a6073475ee86d4e1c1cd9 Mon Sep 17 00:00:00 2001 From: Evan Bonsignori Date: Thu, 18 Aug 2022 11:15:20 -0700 Subject: [PATCH] improvements from @peterbe --- .../content-changes-table-comment.js | 2 +- .../lib/wait-until-url-is-healthy.js | 34 ++++++------------- .../content-changes-table-comment.yml | 2 +- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/.github/actions-scripts/content-changes-table-comment.js b/.github/actions-scripts/content-changes-table-comment.js index 223dc19491..9e4e77960f 100755 --- a/.github/actions-scripts/content-changes-table-comment.js +++ b/.github/actions-scripts/content-changes-table-comment.js @@ -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}`) } diff --git a/.github/actions-scripts/lib/wait-until-url-is-healthy.js b/.github/actions-scripts/lib/wait-until-url-is-healthy.js index 6ed9b10581..d2b5781ff3 100644 --- a/.github/actions-scripts/lib/wait-until-url-is-healthy.js +++ b/.github/actions-scripts/lib/wait-until-url-is-healthy.js @@ -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)) -} diff --git a/.github/workflows/content-changes-table-comment.yml b/.github/workflows/content-changes-table-comment.yml index b3ee20b4a8..c64f8b12dc 100644 --- a/.github/workflows/content-changes-table-comment.yml +++ b/.github/workflows/content-changes-table-comment.yml @@ -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 }}