Skip to content

Commit 8034be6

Browse files
committed
Add --github-pr-number to derive ref from PR #
1 parent bada622 commit 8034be6

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

.evergreen/functions.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,11 @@ functions:
669669
# Load environment variables
670670
eval $(.evergreen/print-compass-env.sh)
671671
# Start the smoke tests on GitHub Actions and wait for successful completion
672-
npm run --workspace @mongodb-js/compass-smoke-tests start -- dispatch --ref ${trigger_branch}
672+
if [[ "${requester}" == "github_pr" ]]; then
673+
npm run --workspace @mongodb-js/compass-smoke-tests start -- dispatch --github-pr-number ${github_pr_number}
674+
else
675+
npm run --workspace @mongodb-js/compass-smoke-tests start -- dispatch --ref ${branch_name}
676+
fi
673677
674678
test-web-sandbox:
675679
- command: shell.exec

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { testTimeToFirstQuery } from './tests/time-to-first-query';
1313
import { testAutoUpdateFrom } from './tests/auto-update-from';
1414
import { testAutoUpdateTo } from './tests/auto-update-to';
1515
import { deleteSandboxesDirectory } from './directories';
16-
import { dispatchAndWait } from './dispatch';
16+
import { dispatchAndWait, getRefFromGithubPr } from './dispatch';
1717

1818
const debug = createDebug('compass:smoketests');
1919

@@ -135,6 +135,10 @@ yargs(hideBin(process.argv))
135135
'Dispatch smoke tests on GitHub and watch to completion',
136136
(argv) =>
137137
argv
138+
.option('github-pr-number', {
139+
type: 'number',
140+
description: 'GitHub PR number used to determine ref',
141+
})
138142
.option('ref', {
139143
type: 'string',
140144
description: 'Git reference to dispatch the workflow from',
@@ -145,7 +149,7 @@ yargs(hideBin(process.argv))
145149
description: 'Compass version to run tests for',
146150
default: process.env.DEV_VERSION_IDENTIFIER,
147151
}),
148-
async ({ version, bucketName, bucketKeyPrefix, ref }) => {
152+
async ({ version, bucketName, bucketKeyPrefix, ref, githubPrNumber }) => {
149153
const { GITHUB_TOKEN } = process.env;
150154
assert(
151155
typeof GITHUB_TOKEN === 'string',
@@ -161,7 +165,13 @@ yargs(hideBin(process.argv))
161165
);
162166
await dispatchAndWait({
163167
githubToken: GITHUB_TOKEN,
164-
ref,
168+
ref:
169+
typeof githubPrNumber === 'number'
170+
? await getRefFromGithubPr({
171+
githubToken: GITHUB_TOKEN,
172+
githubPrNumber,
173+
})
174+
: ref,
165175
version,
166176
bucketName,
167177
bucketKeyPrefix,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,29 @@ async function getWorkflowRunRetrying(
4747
);
4848
}
4949

50+
type RefFromGithubPrOptions = {
51+
githubToken: string;
52+
githubPrNumber: number;
53+
};
54+
55+
export async function getRefFromGithubPr({
56+
githubToken,
57+
githubPrNumber,
58+
}: RefFromGithubPrOptions) {
59+
const octokit = github.getOctokit(githubToken);
60+
const {
61+
data: {
62+
head: { ref },
63+
},
64+
} = await octokit.rest.pulls.get({
65+
owner: GITHUB_OWNER,
66+
repo: GITHUB_REPO,
67+
pull_number: githubPrNumber,
68+
});
69+
console.log(`Got ref "${ref}" from PR #${githubPrNumber}`);
70+
return ref;
71+
}
72+
5073
type DispatchOptions = {
5174
githubToken: string;
5275
ref: string;

0 commit comments

Comments
 (0)