Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗 Consolidate glob expansion while determining build targets #34509

Merged
merged 1 commit into from
May 24, 2021
Merged
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
45 changes: 27 additions & 18 deletions build-system/pr-check/build-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ let buildTargets;
/**
* Used to prevent the repeated expansion of globs during PR jobs.
*/
let htmlFixtureFiles;
let invalidWhitespaceFiles;
let linkCheckFiles;
let lintFiles;
let presubmitFiles;
let prettifyFiles;
const fileLists = {};

/***
* All of AMP's build targets that can be tested during CI.
Expand Down Expand Up @@ -177,7 +172,7 @@ const targetMatchers = {
return false;
}
return (
linkCheckFiles.includes(file) ||
fileLists.linkCheckFiles.includes(file) ||
file == 'build-system/tasks/check-links.js' ||
file.startsWith('build-system/tasks/markdown-toc/')
);
Expand All @@ -195,7 +190,7 @@ const targetMatchers = {
},
[Targets.HTML_FIXTURES]: (file) => {
return (
htmlFixtureFiles.includes(file) ||
fileLists.htmlFixtureFiles.includes(file) ||
file == 'build-system/tasks/validate-html-fixtures.js' ||
file.startsWith('build-system/test-configs')
);
Expand All @@ -215,7 +210,7 @@ const targetMatchers = {
},
[Targets.INVALID_WHITESPACES]: (file) => {
return (
invalidWhitespaceFiles.includes(file) ||
fileLists.invalidWhitespaceFiles.includes(file) ||
file == 'build-system/tasks/check-invalid-whitespaces.js' ||
file.startsWith('build-system/test-configs')
);
Expand All @@ -225,7 +220,7 @@ const targetMatchers = {
return false;
}
return (
lintFiles.includes(file) ||
fileLists.lintFiles.includes(file) ||
file == 'build-system/tasks/lint.js' ||
file.startsWith('build-system/test-configs')
);
Expand All @@ -241,15 +236,15 @@ const targetMatchers = {
return false;
}
return (
presubmitFiles.includes(file) ||
fileLists.presubmitFiles.includes(file) ||
file == 'build-system/tasks/presubmit-checks.js' ||
file.startsWith('build-system/test-configs')
);
},
[Targets.PRETTIFY]: (file) => {
// OWNERS files can be prettified.
return (
prettifyFiles.includes(file) ||
fileLists.prettifyFiles.includes(file) ||
file == '.prettierrc' ||
file == '.prettierignore' ||
file == 'build-system/tasks/prettify.js'
Expand Down Expand Up @@ -330,13 +325,8 @@ function determineBuildTargets() {
if (buildTargets != undefined) {
return buildTargets;
}
expandFileLists();
buildTargets = new Set();
htmlFixtureFiles = globby.sync(config.htmlFixtureGlobs);
invalidWhitespaceFiles = globby.sync(config.invalidWhitespaceGlobs);
linkCheckFiles = globby.sync(config.linkCheckGlobs);
lintFiles = globby.sync(config.lintGlobs);
presubmitFiles = globby.sync(config.presubmitGlobs);
prettifyFiles = globby.sync(config.prettifyGlobs);
const filesChanged = gitDiffNameOnlyMain();
for (const file of filesChanged) {
let isRuntimeFile = true;
Expand Down Expand Up @@ -382,6 +372,25 @@ function buildTargetsInclude(...targets) {
return Array.from(targets).some((target) => buildTargets.has(target));
}

/**
* Helper that expands some of the config globs used to match files. Called once
* at the start in order to avoid repeated glob expansion.
*/
function expandFileLists() {
const globNames = [
'htmlFixtureGlobs',
'invalidWhitespaceGlobs',
'linkCheckGlobs',
'lintGlobs',
'presubmitGlobs',
'prettifyGlobs',
];
for (const globName of globNames) {
const fileListName = globName.replace('Globs', 'Files');
fileLists[fileListName] = globby.sync(config[globName], {dot: true});
}
}

module.exports = {
buildTargetsInclude,
determineBuildTargets,
Expand Down