From 18f6617695ce841e98b53247ff4c9eace31fedb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Wed, 26 Feb 2025 10:48:00 +0100 Subject: [PATCH 1/4] Fail dispatch early --- packages/compass-smoke-tests/src/dispatch.ts | 79 ++++++++++++++------ 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/packages/compass-smoke-tests/src/dispatch.ts b/packages/compass-smoke-tests/src/dispatch.ts index ce0bee999dc..9b352beb8da 100644 --- a/packages/compass-smoke-tests/src/dispatch.ts +++ b/packages/compass-smoke-tests/src/dispatch.ts @@ -1,3 +1,4 @@ +import assert from 'node:assert/strict'; import crypto from 'node:crypto'; import * as github from '@actions/github'; @@ -70,12 +71,58 @@ export async function getRefFromGithubPr({ return ref; } +type PollToCompletionOptions = { + octokit: ReturnType; + runId: number; + watchTimeoutMs: number; + watchPollDelayMs: number; +}; + +async function pollToCompletion({ + octokit, + runId, + watchTimeoutMs, + watchPollDelayMs, +}: PollToCompletionOptions): Promise { + for ( + const start = new Date(); + new Date().getTime() - start.getTime() < watchTimeoutMs; + + ) { + const { + data: { status, conclusion }, + } = await octokit.rest.actions.getWorkflowRun({ + owner: GITHUB_OWNER, + repo: GITHUB_REPO, + run_id: runId, + }); + console.log(`Status: ${status || 'null'}`); + if (status === 'completed') { + assert( + typeof conclusion === 'string', + 'Expected conclusion when completed' + ); + return conclusion; + } + await new Promise((resolve) => setTimeout(resolve, watchPollDelayMs)); + } + + // Cancel the run before timing out + await octokit.rest.actions.cancelWorkflowRun({ + owner: GITHUB_OWNER, + repo: GITHUB_REPO, + run_id: runId, + }); + return 'timeout'; +} + type DispatchOptions = { githubToken: string; ref: string; bucketName: string; bucketKeyPrefix: string; devVersion?: string; + evergreenTaskUrl?: string; /** * Delay in milliseconds to wait between requests when polling while watching the run. @@ -89,6 +136,7 @@ export async function dispatchAndWait({ devVersion, bucketName, bucketKeyPrefix, + evergreenTaskUrl, watchPollDelayMs = 5000, }: DispatchOptions) { const octokit = github.getOctokit(githubToken); @@ -103,6 +151,7 @@ export async function dispatchAndWait({ dev_version: devVersion, bucket_name: bucketName, bucket_key_prefix: bucketKeyPrefix, + evergreen_task_url: evergreenTaskUrl, nonce, }, }); @@ -114,27 +163,13 @@ export async function dispatchAndWait({ ); console.log(`Dispatched run #${run.run_number} (${run.html_url})`); - for ( - const start = new Date(); - new Date().getTime() - start.getTime() < WATCH_POLL_TIMEOUT_MS; + const status = await pollToCompletion({ + octokit, + runId: run.id, + watchTimeoutMs: WATCH_POLL_TIMEOUT_MS, + watchPollDelayMs, + }); - ) { - const { - data: { status, conclusion }, - } = await octokit.rest.actions.getWorkflowRun({ - owner: GITHUB_OWNER, - repo: GITHUB_REPO, - run_id: run.id, - }); - console.log( - `Status = ${status || 'null'}, conclusion = ${conclusion || 'null'}` - ); - if (status === 'completed' && conclusion === 'success') { - return; - } - await new Promise((resolve) => setTimeout(resolve, watchPollDelayMs)); - } - throw new Error( - `Run did not complete successfully within ${WATCH_POLL_TIMEOUT_MS}ms: See ${run.html_url} for details.` - ); + console.log(`Run completed: ${run.html_url}`); + assert.equal(status, 'success', "Expected a 'success' conclusion"); } From ecabf17751156d095759e8b1f16f7938c8a2d937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Wed, 26 Feb 2025 10:48:19 +0100 Subject: [PATCH 2/4] Propagate evergreen task URL to GHA summary --- .evergreen/functions.yml | 1 + .github/workflows/test-installers.yml | 9 +++++++++ packages/compass-smoke-tests/src/cli.ts | 1 + 3 files changed, 11 insertions(+) diff --git a/.evergreen/functions.yml b/.evergreen/functions.yml index 10968ccbc56..a01767ed1bc 100644 --- a/.evergreen/functions.yml +++ b/.evergreen/functions.yml @@ -667,6 +667,7 @@ functions: <<: *compass-env DEBUG: ${debug|} GITHUB_TOKEN: ${generated_token} + EVERGREEN_TASK_URL: https://spruce.mongodb.com/task/${task_id} script: | set -e # Load environment variables diff --git a/.github/workflows/test-installers.yml b/.github/workflows/test-installers.yml index d2aeb5171aa..993cb9ba33b 100644 --- a/.github/workflows/test-installers.yml +++ b/.github/workflows/test-installers.yml @@ -20,10 +20,19 @@ on: nonce: type: string description: 'A random string to track the run from dispatch to watching' + evergreen_task_url: + type: string + description: 'URL to the Evergreen job that triggered this run' run-name: Test Installers ${{ github.event.inputs.dev_version || github.ref_name }} / (nonce = ${{ github.event.inputs.nonce || 'not set' }}) jobs: + summarize: + if: ${{ github.event.inputs.evergreen_task_url }} + runs-on: ubuntu-latest + steps: + - name: Add a summary to the job + run: echo "Triggered by ${{ github.event.inputs.evergreen_task_url }}" >> $GITHUB_STEP_SUMMARY test: name: ${{ matrix.package }} test ${{ matrix.test }} (${{ matrix.hadron-distribution }}) strategy: diff --git a/packages/compass-smoke-tests/src/cli.ts b/packages/compass-smoke-tests/src/cli.ts index e83aef45ec3..8d563b6d523 100755 --- a/packages/compass-smoke-tests/src/cli.ts +++ b/packages/compass-smoke-tests/src/cli.ts @@ -165,6 +165,7 @@ yargs(hideBin(process.argv)) }) : ref, devVersion: process.env.DEV_VERSION_IDENTIFIER, + evergreenTaskUrl: process.env.EVERGREEN_TASK_URL, bucketName, bucketKeyPrefix, }); From 94a8074e4a3c0fabbf73d691220a2bc298920a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Wed, 26 Feb 2025 13:33:04 +0100 Subject: [PATCH 3/4] Stop showing help on failures --- packages/compass-smoke-tests/src/cli.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/compass-smoke-tests/src/cli.ts b/packages/compass-smoke-tests/src/cli.ts index 8d563b6d523..94df54bc711 100755 --- a/packages/compass-smoke-tests/src/cli.ts +++ b/packages/compass-smoke-tests/src/cli.ts @@ -71,6 +71,7 @@ yargs(hideBin(process.argv)) .scriptName('smoke-tests') .detectLocale(false) .version(false) + .showHelpOnFail(false) .strict() .option('bucketName', { type: 'string', From d58ebbe23c95745bf7e1037c5eb6f616629596f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Wed, 26 Feb 2025 16:04:26 +0100 Subject: [PATCH 4/4] Propagate the GitHub PR too --- .evergreen/functions.yml | 1 + .github/workflows/test-installers.yml | 12 +++++++++--- packages/compass-smoke-tests/src/cli.ts | 13 ++++++++++--- packages/compass-smoke-tests/src/dispatch.ts | 3 +++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.evergreen/functions.yml b/.evergreen/functions.yml index a01767ed1bc..b1023484cd2 100644 --- a/.evergreen/functions.yml +++ b/.evergreen/functions.yml @@ -667,6 +667,7 @@ functions: <<: *compass-env DEBUG: ${debug|} GITHUB_TOKEN: ${generated_token} + GITHUB_PR_NUMBER: ${github_pr_number} EVERGREEN_TASK_URL: https://spruce.mongodb.com/task/${task_id} script: | set -e diff --git a/.github/workflows/test-installers.yml b/.github/workflows/test-installers.yml index 993cb9ba33b..92fbf175bef 100644 --- a/.github/workflows/test-installers.yml +++ b/.github/workflows/test-installers.yml @@ -20,6 +20,9 @@ on: nonce: type: string description: 'A random string to track the run from dispatch to watching' + github_pr_number: + type: string + description: 'Number of the PR that triggered this run' evergreen_task_url: type: string description: 'URL to the Evergreen job that triggered this run' @@ -28,11 +31,14 @@ run-name: Test Installers ${{ github.event.inputs.dev_version || github.ref_name jobs: summarize: - if: ${{ github.event.inputs.evergreen_task_url }} runs-on: ubuntu-latest steps: - - name: Add a summary to the job - run: echo "Triggered by ${{ github.event.inputs.evergreen_task_url }}" >> $GITHUB_STEP_SUMMARY + - name: Add URL for the GitHub PR + if: ${{ github.event.inputs.github_pr_number }} + run: echo "[GitHub PR ${{ github.event.inputs.github_pr_number }}](https://github.com/mongodb-js/compass/pull/${{ github.event.inputs.github_pr_number }})" >> $GITHUB_STEP_SUMMARY + - name: Add URL for the Evergreen task + if: ${{ github.event.inputs.evergreen_task_url }} + run: echo "[Evergreen Task](${{ github.event.inputs.evergreen_task_url }})" >> $GITHUB_STEP_SUMMARY test: name: ${{ matrix.package }} test ${{ matrix.test }} (${{ matrix.hadron-distribution }}) strategy: diff --git a/packages/compass-smoke-tests/src/cli.ts b/packages/compass-smoke-tests/src/cli.ts index 94df54bc711..599741f07c8 100755 --- a/packages/compass-smoke-tests/src/cli.ts +++ b/packages/compass-smoke-tests/src/cli.ts @@ -146,7 +146,13 @@ yargs(hideBin(process.argv)) default: getDefaultRef(), }), async ({ bucketName, bucketKeyPrefix, ref, githubPrNumber }) => { - const { GITHUB_TOKEN } = process.env; + const { + GITHUB_TOKEN, + DEV_VERSION_IDENTIFIER, + GITHUB_PR_NUMBER, + EVERGREEN_TASK_URL, + } = process.env; + assert( typeof GITHUB_TOKEN === 'string', 'Expected a GITHUB_TOKEN environment variable' @@ -165,8 +171,9 @@ yargs(hideBin(process.argv)) githubPrNumber, }) : ref, - devVersion: process.env.DEV_VERSION_IDENTIFIER, - evergreenTaskUrl: process.env.EVERGREEN_TASK_URL, + devVersion: DEV_VERSION_IDENTIFIER, + githubPrNumber: GITHUB_PR_NUMBER, + evergreenTaskUrl: EVERGREEN_TASK_URL, bucketName, bucketKeyPrefix, }); diff --git a/packages/compass-smoke-tests/src/dispatch.ts b/packages/compass-smoke-tests/src/dispatch.ts index 9b352beb8da..cade4f3c4f5 100644 --- a/packages/compass-smoke-tests/src/dispatch.ts +++ b/packages/compass-smoke-tests/src/dispatch.ts @@ -122,6 +122,7 @@ type DispatchOptions = { bucketName: string; bucketKeyPrefix: string; devVersion?: string; + githubPrNumber?: string; evergreenTaskUrl?: string; /** @@ -136,6 +137,7 @@ export async function dispatchAndWait({ devVersion, bucketName, bucketKeyPrefix, + githubPrNumber, evergreenTaskUrl, watchPollDelayMs = 5000, }: DispatchOptions) { @@ -151,6 +153,7 @@ export async function dispatchAndWait({ dev_version: devVersion, bucket_name: bucketName, bucket_key_prefix: bucketKeyPrefix, + github_pr_number: githubPrNumber, evergreen_task_url: evergreenTaskUrl, nonce, },