Skip to content

Commit c74e1ce

Browse files
authored
chore(smoke-test): fail early and propagate task url (#6752)
* Fail dispatch early * Propagate evergreen task URL to GHA summary * Stop showing help on failures * Propagate the GitHub PR too
1 parent bc69d47 commit c74e1ce

File tree

4 files changed

+88
-24
lines changed

4 files changed

+88
-24
lines changed

.evergreen/functions.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,8 @@ functions:
667667
<<: *compass-env
668668
DEBUG: ${debug|}
669669
GITHUB_TOKEN: ${generated_token}
670+
GITHUB_PR_NUMBER: ${github_pr_number}
671+
EVERGREEN_TASK_URL: https://spruce.mongodb.com/task/${task_id}
670672
script: |
671673
set -e
672674
# Load environment variables

.github/workflows/test-installers.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,25 @@ on:
2020
nonce:
2121
type: string
2222
description: 'A random string to track the run from dispatch to watching'
23+
github_pr_number:
24+
type: string
25+
description: 'Number of the PR that triggered this run'
26+
evergreen_task_url:
27+
type: string
28+
description: 'URL to the Evergreen job that triggered this run'
2329

2430
run-name: Test Installers ${{ github.event.inputs.dev_version || github.ref_name }} / (nonce = ${{ github.event.inputs.nonce || 'not set' }})
2531

2632
jobs:
33+
summarize:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Add URL for the GitHub PR
37+
if: ${{ github.event.inputs.github_pr_number }}
38+
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
39+
- name: Add URL for the Evergreen task
40+
if: ${{ github.event.inputs.evergreen_task_url }}
41+
run: echo "[Evergreen Task](${{ github.event.inputs.evergreen_task_url }})" >> $GITHUB_STEP_SUMMARY
2742
test:
2843
name: ${{ matrix.package }} test ${{ matrix.test }} (${{ matrix.hadron-distribution }})
2944
strategy:

packages/compass-smoke-tests/src/cli.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ yargs(hideBin(process.argv))
7171
.scriptName('smoke-tests')
7272
.detectLocale(false)
7373
.version(false)
74+
.showHelpOnFail(false)
7475
.strict()
7576
.option('bucketName', {
7677
type: 'string',
@@ -145,7 +146,13 @@ yargs(hideBin(process.argv))
145146
default: getDefaultRef(),
146147
}),
147148
async ({ bucketName, bucketKeyPrefix, ref, githubPrNumber }) => {
148-
const { GITHUB_TOKEN } = process.env;
149+
const {
150+
GITHUB_TOKEN,
151+
DEV_VERSION_IDENTIFIER,
152+
GITHUB_PR_NUMBER,
153+
EVERGREEN_TASK_URL,
154+
} = process.env;
155+
149156
assert(
150157
typeof GITHUB_TOKEN === 'string',
151158
'Expected a GITHUB_TOKEN environment variable'
@@ -164,7 +171,9 @@ yargs(hideBin(process.argv))
164171
githubPrNumber,
165172
})
166173
: ref,
167-
devVersion: process.env.DEV_VERSION_IDENTIFIER,
174+
devVersion: DEV_VERSION_IDENTIFIER,
175+
githubPrNumber: GITHUB_PR_NUMBER,
176+
evergreenTaskUrl: EVERGREEN_TASK_URL,
168177
bucketName,
169178
bucketKeyPrefix,
170179
});

packages/compass-smoke-tests/src/dispatch.ts

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'node:assert/strict';
12
import crypto from 'node:crypto';
23

34
import * as github from '@actions/github';
@@ -70,12 +71,59 @@ export async function getRefFromGithubPr({
7071
return ref;
7172
}
7273

74+
type PollToCompletionOptions = {
75+
octokit: ReturnType<typeof github.getOctokit>;
76+
runId: number;
77+
watchTimeoutMs: number;
78+
watchPollDelayMs: number;
79+
};
80+
81+
async function pollToCompletion({
82+
octokit,
83+
runId,
84+
watchTimeoutMs,
85+
watchPollDelayMs,
86+
}: PollToCompletionOptions): Promise<string> {
87+
for (
88+
const start = new Date();
89+
new Date().getTime() - start.getTime() < watchTimeoutMs;
90+
91+
) {
92+
const {
93+
data: { status, conclusion },
94+
} = await octokit.rest.actions.getWorkflowRun({
95+
owner: GITHUB_OWNER,
96+
repo: GITHUB_REPO,
97+
run_id: runId,
98+
});
99+
console.log(`Status: ${status || 'null'}`);
100+
if (status === 'completed') {
101+
assert(
102+
typeof conclusion === 'string',
103+
'Expected conclusion when completed'
104+
);
105+
return conclusion;
106+
}
107+
await new Promise((resolve) => setTimeout(resolve, watchPollDelayMs));
108+
}
109+
110+
// Cancel the run before timing out
111+
await octokit.rest.actions.cancelWorkflowRun({
112+
owner: GITHUB_OWNER,
113+
repo: GITHUB_REPO,
114+
run_id: runId,
115+
});
116+
return 'timeout';
117+
}
118+
73119
type DispatchOptions = {
74120
githubToken: string;
75121
ref: string;
76122
bucketName: string;
77123
bucketKeyPrefix: string;
78124
devVersion?: string;
125+
githubPrNumber?: string;
126+
evergreenTaskUrl?: string;
79127

80128
/**
81129
* Delay in milliseconds to wait between requests when polling while watching the run.
@@ -89,6 +137,8 @@ export async function dispatchAndWait({
89137
devVersion,
90138
bucketName,
91139
bucketKeyPrefix,
140+
githubPrNumber,
141+
evergreenTaskUrl,
92142
watchPollDelayMs = 5000,
93143
}: DispatchOptions) {
94144
const octokit = github.getOctokit(githubToken);
@@ -103,6 +153,8 @@ export async function dispatchAndWait({
103153
dev_version: devVersion,
104154
bucket_name: bucketName,
105155
bucket_key_prefix: bucketKeyPrefix,
156+
github_pr_number: githubPrNumber,
157+
evergreen_task_url: evergreenTaskUrl,
106158
nonce,
107159
},
108160
});
@@ -114,27 +166,13 @@ export async function dispatchAndWait({
114166
);
115167

116168
console.log(`Dispatched run #${run.run_number} (${run.html_url})`);
117-
for (
118-
const start = new Date();
119-
new Date().getTime() - start.getTime() < WATCH_POLL_TIMEOUT_MS;
169+
const status = await pollToCompletion({
170+
octokit,
171+
runId: run.id,
172+
watchTimeoutMs: WATCH_POLL_TIMEOUT_MS,
173+
watchPollDelayMs,
174+
});
120175

121-
) {
122-
const {
123-
data: { status, conclusion },
124-
} = await octokit.rest.actions.getWorkflowRun({
125-
owner: GITHUB_OWNER,
126-
repo: GITHUB_REPO,
127-
run_id: run.id,
128-
});
129-
console.log(
130-
`Status = ${status || 'null'}, conclusion = ${conclusion || 'null'}`
131-
);
132-
if (status === 'completed' && conclusion === 'success') {
133-
return;
134-
}
135-
await new Promise((resolve) => setTimeout(resolve, watchPollDelayMs));
136-
}
137-
throw new Error(
138-
`Run did not complete successfully within ${WATCH_POLL_TIMEOUT_MS}ms: See ${run.html_url} for details.`
139-
);
176+
console.log(`Run completed: ${run.html_url}`);
177+
assert.equal(status, 'success', "Expected a 'success' conclusion");
140178
}

0 commit comments

Comments
 (0)