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

adding a check-format step in CI #13983

Merged
4 commits merged into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions eng/pipelines/templates/steps/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ steps:
node eng/tools/rush-runner.js lint "${{parameters.ServiceDirectory}}"
displayName: "Build ESLint Plugin and Lint Libraries"

- pwsh: |
deyaaeldeen marked this conversation as resolved.
Show resolved Hide resolved
node eng/tools/rush-runner.js check-format "${{parameters.ServiceDirectory}}" --verbose
displayName: "Check Format in Libraries"

- script: |
node eng/tools/rush-runner.js audit "${{parameters.ServiceDirectory}}"
condition: and(succeeded(), eq(variables['RunNpmAudit'], 'true'))
Expand Down
21 changes: 21 additions & 0 deletions eng/tools/rush-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const spawnNode = (cwd, ...args) => {
// should ever happen, but if it does it's safer to fail.
process.exitCode = proc.status || 1;
}
return proc.status
};

const flatMap = (arr, f) => {
Expand All @@ -188,6 +189,19 @@ function rushRunAll(direction, packages) {
spawnNode(baseDir, "common/scripts/install-run-rush.js", action, ...params, ...rushParams);
}

/**
* Helper function to get the relative path of a package directory from an absolute
* one
*
* @param {string} absolutePath absolute path to a package
* @returns either the relative path of the package starting from the "sdk" directory
* or the just the absolute path itself if "sdk" if not found
*/
function tryGetPkgRelativePath(absolutePath) {
const sdkDirectoryPathStartIndex = absolutePath.lastIndexOf("sdk");
return sdkDirectoryPathStartIndex === -1 ? absolutePath : absolutePath.substring(sdkDirectoryPathStartIndex);
}

if (serviceDirs.length === 0) {
spawnNode(baseDir, "common/scripts/install-run-rush.js", action, ...rushParams);
} else {
Expand All @@ -204,6 +218,13 @@ if (serviceDirs.length === 0) {
spawnNode(packageDir, "../../../common/scripts/install-run-rushx.js", action);
}
break;
case "check-format":
for (const packageDir of packageDirs) {
if (spawnNode(packageDir, "../../../common/scripts/install-run-rushx.js", action) !== 0) {
console.log(`\nInvoke "rushx format" inside ${tryGetPkgRelativePath(packageDir)} to fix formatting\n`);
}
}
break;

case "build":
if (actionComponents[1] === "samples") {
Expand Down