Skip to content

Commit

Permalink
ci: add flags.circleci.timeoutMinutes (#29156)
Browse files Browse the repository at this point in the history
## **Description**

1. Allows you to customize the E2E timeout by writing this in the PR
description:

`flags = {"circleci": {"timeoutMinutes": 35}}`

2. change to git-diff-default-branch.ts to be able to run it as a direct
script or as a library
3. changes the default value for the merge queue
4. increases runAll.js's time-default from 30s to 50s

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29156?quickstart=1)

<!--## **Related issues**
## **Manual testing steps**
## **Screenshots/Recordings**
### **Before**
### **After**
## **Pre-merge author checklist**
## **Pre-merge reviewer checklist**
-->

---------

Co-authored-by: Mark Stacey <[email protected]>
  • Loading branch information
HowardBraham and Gudahtt authored Dec 16, 2024
1 parent 45c7bfd commit 78ea51a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions .circleci/scripts/git-diff-default-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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();
}
23 changes: 19 additions & 4 deletions .circleci/scripts/test-run-e2e-timeout-minutes.ts
Original file line number Diff line number Diff line change
@@ -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);
});
4 changes: 4 additions & 0 deletions app/scripts/lib/manifestFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export type ManifestFlags = {
* The number of the pull request that triggered the current run
*/
prNumber?: number;
/**
* The number of minutes to allow the E2E tests to run before timing out
*/
timeoutMinutes?: number;
};
/**
* Sentry flags
Expand Down
1 change: 0 additions & 1 deletion development/lib/get-manifest-flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ async function getFlagsFromPrBody(): Promise<ManifestFlags> {
hasProperty(error, 'code') &&
error.code === 'ENOENT'
) {
console.debug('No pr-body.txt, ignoring flags');
return {};
}
throw error;
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/run-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function runningOnCircleCI(testPaths) {
// 1. split the test files into chunks based on how long they take to run
// 2. support "Rerun failed tests" on CircleCI
const result = execSync(
'circleci tests run --command=">test/test-results/myTestList.txt xargs echo" --split-by=timings --timings-type=filename --time-default=30s < test/test-results/fullTestList.txt',
'circleci tests run --command=">test/test-results/myTestList.txt xargs echo" --split-by=timings --timings-type=filename --time-default=50s < test/test-results/fullTestList.txt',
).toString('utf8');

// Report if no tests found, exit gracefully
Expand Down

0 comments on commit 78ea51a

Please sign in to comment.