Skip to content

Commit

Permalink
adding a check-format step in CI (#13983)
Browse files Browse the repository at this point in the history
Adds a new analyze step to run `rushx check-format` in the package the opened PR is against. We are doing this after killing the git precommit hook that used to run the formatter here: #13982. I am not very familiar with engineering systems scripts so I might have missed something.
  • Loading branch information
deyaaeldeen authored Mar 17, 2021
1 parent 0ae8bf4 commit 273c3bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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: |
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

0 comments on commit 273c3bd

Please sign in to comment.