From 03a6df310b2b7c631897406b69af9c343732b014 Mon Sep 17 00:00:00 2001 From: deyaaeldeen Date: Thu, 25 Feb 2021 21:52:43 +0000 Subject: [PATCH 1/3] adding a check-format step in CI --- eng/pipelines/templates/steps/analyze.yml | 4 ++++ eng/tools/rush-runner.js | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/eng/pipelines/templates/steps/analyze.yml b/eng/pipelines/templates/steps/analyze.yml index d60b4e452a9d..672ac37757cb 100644 --- a/eng/pipelines/templates/steps/analyze.yml +++ b/eng/pipelines/templates/steps/analyze.yml @@ -48,6 +48,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}}" + displayName: "Check Format in Libraries" + - script: | node eng/tools/rush-runner.js audit "${{parameters.ServiceDirectory}}" condition: and(succeeded(), eq(variables['RunNpmAudit'], 'true')) diff --git a/eng/tools/rush-runner.js b/eng/tools/rush-runner.js index 3e414f362d31..41a20107404d 100644 --- a/eng/tools/rush-runner.js +++ b/eng/tools/rush-runner.js @@ -192,6 +192,11 @@ if (serviceDirs.length === 0) { spawnNode(packageDir, "../../../common/scripts/install-run-rushx.js", action); } break; + case "check-format": + for (const packageDir of packageDirs) { + spawnNode(packageDir, "../../../common/scripts/install-run-rushx.js", action); + } + break; case "build": if (actionComponents[1] === "samples") { From b05ec077910dd1fba55a43288defb67555a89e7e Mon Sep 17 00:00:00 2001 From: deyaaeldeen Date: Tue, 16 Mar 2021 21:43:56 +0000 Subject: [PATCH 2/3] add error message --- eng/tools/rush-runner.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eng/tools/rush-runner.js b/eng/tools/rush-runner.js index 41a20107404d..4af4f34f0e62 100644 --- a/eng/tools/rush-runner.js +++ b/eng/tools/rush-runner.js @@ -153,6 +153,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) => { @@ -194,7 +195,9 @@ if (serviceDirs.length === 0) { break; case "check-format": for (const packageDir of packageDirs) { - spawnNode(packageDir, "../../../common/scripts/install-run-rushx.js", action); + if (spawnNode(packageDir, "../../../common/scripts/install-run-rushx.js", action) !== 0) { + console.log(`Invoke "rushx format" inside ${packageDir} to fix formatting`); + } } break; From e14b35cca54f65ca8cdda78e107962d41b16cae9 Mon Sep 17 00:00:00 2001 From: deyaaeldeen Date: Wed, 17 Mar 2021 17:46:17 +0000 Subject: [PATCH 3/3] use --verbose to print to the CI report --- eng/pipelines/templates/steps/analyze.yml | 2 +- eng/tools/rush-runner.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/templates/steps/analyze.yml b/eng/pipelines/templates/steps/analyze.yml index 672ac37757cb..3ed24872766e 100644 --- a/eng/pipelines/templates/steps/analyze.yml +++ b/eng/pipelines/templates/steps/analyze.yml @@ -49,7 +49,7 @@ steps: displayName: "Build ESLint Plugin and Lint Libraries" - pwsh: | - node eng/tools/rush-runner.js check-format "${{parameters.ServiceDirectory}}" + node eng/tools/rush-runner.js check-format "${{parameters.ServiceDirectory}}" --verbose displayName: "Check Format in Libraries" - script: | diff --git a/eng/tools/rush-runner.js b/eng/tools/rush-runner.js index 4af4f34f0e62..657584f59ba9 100644 --- a/eng/tools/rush-runner.js +++ b/eng/tools/rush-runner.js @@ -177,6 +177,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 { @@ -196,7 +209,7 @@ if (serviceDirs.length === 0) { case "check-format": for (const packageDir of packageDirs) { if (spawnNode(packageDir, "../../../common/scripts/install-run-rushx.js", action) !== 0) { - console.log(`Invoke "rushx format" inside ${packageDir} to fix formatting`); + console.log(`\nInvoke "rushx format" inside ${tryGetPkgRelativePath(packageDir)} to fix formatting\n`); } } break;