From 4a589722a89da695fd0f8fb9e765cea62b19050c Mon Sep 17 00:00:00 2001 From: Howard Braham Date: Fri, 13 Dec 2024 00:21:44 +0530 Subject: [PATCH] ci: add flags.circleci.timeoutMinutes --- .circleci/config.yml | 1 + .circleci/scripts/git-diff-default-branch.ts | 13 +++++++---- .../scripts/test-run-e2e-timeout-minutes.ts | 23 +++++++++++++++---- app/scripts/lib/manifestFlags.ts | 4 ++++ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 37da32cf59f3..552aa3305509 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -224,6 +224,7 @@ workflows: - test-api-specs: requires: - prep-build-test + - get-changed-files-with-git-diff - test-e2e-chrome-multiple-providers: requires: - prep-build-test diff --git a/.circleci/scripts/git-diff-default-branch.ts b/.circleci/scripts/git-diff-default-branch.ts index 8db64e0f7058..269de912dafd 100644 --- a/.circleci/scripts/git-diff-default-branch.ts +++ b/.circleci/scripts/git-diff-default-branch.ts @@ -123,9 +123,7 @@ async function storeGitDiffOutputAndPrBody() { // even if we want to skip this step. fs.mkdirSync(CHANGED_FILES_DIR, { recursive: true }); - console.log( - `Determining whether to run git diff...`, - ); + console.log(`Determining whether to run git diff...`); if (!PR_NUMBER) { console.log('Not a PR, skipping git diff'); return; @@ -141,7 +139,9 @@ async function storeGitDiffOutputAndPrBody() { console.log(`This is for a PR targeting '${baseRef}', skipping git diff`); writePrBodyToFile(prInfo.body); return; - } else if (prInfo.labels.some(label => label.name === 'skip-e2e-quality-gate')) { + } else if ( + prInfo.labels.some((label) => label.name === 'skip-e2e-quality-gate') + ) { console.log('PR has the skip-e2e-quality-gate label, skipping git diff'); return; } @@ -164,4 +164,7 @@ async function storeGitDiffOutputAndPrBody() { } } -storeGitDiffOutputAndPrBody(); +// If main module (i.e. this is the TS file that was run directly) +if (require.main === module) { + storeGitDiffOutputAndPrBody(); +} diff --git a/.circleci/scripts/test-run-e2e-timeout-minutes.ts b/.circleci/scripts/test-run-e2e-timeout-minutes.ts index c539133b0c60..c486224139c3 100644 --- a/.circleci/scripts/test-run-e2e-timeout-minutes.ts +++ b/.circleci/scripts/test-run-e2e-timeout-minutes.ts @@ -1,8 +1,23 @@ +import { fetchManifestFlagsFromPRAndGit } from '../../development/lib/get-manifest-flag'; import { filterE2eChangedFiles } from '../../test/e2e/changedFilesUtil'; -const changedOrNewTests = filterE2eChangedFiles(); +fetchManifestFlagsFromPRAndGit().then((manifestFlags) => { + let timeout; -// 20 minutes, plus 3 minutes for every changed file, up to a maximum of 30 minutes -const extraTime = Math.min(20 + changedOrNewTests.length * 3, 30); + if (manifestFlags.circleci?.timeoutMinutes) { + timeout = manifestFlags.circleci?.timeoutMinutes; + } else { + const changedOrNewTests = filterE2eChangedFiles(); -console.log(extraTime); + // 20 minutes, plus 3 minutes for every changed file, up to a maximum of 30 minutes + timeout = Math.min(20 + changedOrNewTests.length * 3, 30); + } + + // If this is the Merge Queue, add 10 minutes + if (process.env.CIRCLE_BRANCH?.startsWith('gh-readonly-queue')) { + timeout += 10; + } + + // This is an essential log, that feeds into a bash script + console.log(timeout); +}); diff --git a/app/scripts/lib/manifestFlags.ts b/app/scripts/lib/manifestFlags.ts index 5804c7391973..a5be5be7e61c 100644 --- a/app/scripts/lib/manifestFlags.ts +++ b/app/scripts/lib/manifestFlags.ts @@ -8,6 +8,10 @@ export type ManifestFlags = { job?: string; nodeIndex?: number; prNumber?: number; + /** + * The number of minutes to allow the E2E tests to run before timing out + */ + timeoutMinutes?: number; }; sentry?: { tracesSampleRate?: number;