Skip to content

Commit

Permalink
Configure E2E tests to run on a commit that contains #run-e2e-tests (#…
Browse files Browse the repository at this point in the history
…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: #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
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Nov 8, 2023
1 parent 5abaf38 commit bb4e940
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions scripts/circleci/pipeline_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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()
Expand All @@ -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`;

Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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'],
};

Expand Down Expand Up @@ -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);
}

0 comments on commit bb4e940

Please sign in to comment.