Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}