Configure E2E tests to run on a commit that contains #run-e2e-tests (#41308)

Summary:
This change allow our CI to run E2E tests using a specific tag in the commit message

## Changelog:
[Internal] - Allow to run e2e test using a specific tag in the last commit message

Pull Request resolved: https://github.com/facebook/react-native/pull/41308

Test Plan:
CircleCI is green
Tested interacting with the PR/branch

Reviewed By: NickGerleman

Differential Revision: D50975588

Pulled By: cipolleschi

fbshipit-source-id: 6318800d7e86e1cab394af2b320e280304189dd2
This commit is contained in:
Riccardo Cipolleschi
2023-11-08 02:03:52 -08:00
committed by Facebook GitHub Bot
parent 5abaf388cd
commit bb4e940b6d
+32 -15
View File
@@ -54,10 +54,6 @@ const mapping = [
name: 'RUN_ANDROID',
filterFN: name => name.indexOf('ReactAndroid/') > -1,
},
// {
// name: 'RUN_E2E',
// filterFN: name => name.indexOf('rn-tester-e2e/') > -1,
// },
{
name: 'RUN_JS',
filterFN: name => isJSChange(name),
@@ -109,8 +105,7 @@ yargs
'filter-jobs',
'Filters the jobs based on the list of chaged files in the PR',
filterJobsOptions,
argv =>
filterJobs(argv.output_path).then(() => console.info('Filtering done!')),
argv => filterJobs(argv.output_path),
)
.demandCommand()
.strict()
@@ -135,7 +130,23 @@ function _getFilesFromGit() {
}
}
async function _computeAndSavePipelineParameters(pipelineType, outputPath) {
function _shouldRunE2E() {
try {
const gitCommand = 'git log -1 --pretty=format:"%B" | head -n 1';
const commitMessage = String(execSync(gitCommand)).trim();
console.log(`commitMessage: ${commitMessage}`);
return commitMessage.includes('#run-e2e-tests');
} catch (error) {
console.error(error);
return false;
}
}
function _computeAndSavePipelineParameters(
pipelineType,
outputPath,
shouldRunE2E,
) {
fs.mkdirSync(outputPath, {recursive: true});
const filePath = `${outputPath}/pipeline_config.json`;
@@ -144,8 +155,12 @@ async function _computeAndSavePipelineParameters(pipelineType, outputPath) {
return;
}
console.log(`Should run e2e? ${shouldRunE2E}`);
if (pipelineType === 'ALL') {
fs.writeFileSync(filePath, JSON.stringify({run_all: true}, null, 2));
fs.writeFileSync(
filePath,
JSON.stringify({run_all: true, run_e2e: shouldRunE2E}, null, 2),
);
return;
}
@@ -154,7 +169,7 @@ async function _computeAndSavePipelineParameters(pipelineType, outputPath) {
run_ios: pipelineType === 'RUN_IOS',
run_android: pipelineType === 'RUN_ANDROID',
run_js: pipelineType === 'RUN_JS',
// run_e2e: pipelineType === 'RUN_E2E' || pipelineType === 'RUN_JS',
run_e2e: shouldRunE2E,
};
const stringifiedParams = JSON.stringify(params, null, 2);
@@ -180,8 +195,8 @@ function createConfigs(inputPath, outputPath, configFile) {
const testConfigs = {
run_ios: ['testIOS.yml'],
run_android: ['testAndroid.yml'],
// run_e2e: ['testE2E.yml'],
run_all: [/*'testE2E.yml',*/ 'testJS.yml', 'testAll.yml'],
run_e2e: ['testE2E.yml'],
run_all: ['testJS.yml', 'testAll.yml'],
run_js: ['testJS.yml'],
};
@@ -211,20 +226,22 @@ function createConfigs(inputPath, outputPath, configFile) {
);
}
async function filterJobs(outputPath) {
function filterJobs(outputPath) {
const fileList = _getFilesFromGit();
if (fileList.length === 0) {
await _computeAndSavePipelineParameters('SKIP', outputPath);
_computeAndSavePipelineParameters('SKIP', outputPath);
return;
}
const shouldRunE2E = _shouldRunE2E();
for (const filter of mapping) {
const found = fileList.every(filter.filterFN);
if (found) {
await _computeAndSavePipelineParameters(filter.name, outputPath);
_computeAndSavePipelineParameters(filter.name, outputPath, shouldRunE2E);
return;
}
}
await _computeAndSavePipelineParameters('ALL', outputPath);
_computeAndSavePipelineParameters('ALL', outputPath, shouldRunE2E);
}