diff --git a/eng/pipelines/templates/steps/analyze.yml b/eng/pipelines/templates/steps/analyze.yml index b404bd56bff..dd3d425d5b3 100644 --- a/eng/pipelines/templates/steps/analyze.yml +++ b/eng/pipelines/templates/steps/analyze.yml @@ -62,12 +62,16 @@ steps: parameters: ServiceDirectory: ${{ parameters.ServiceDirectory }} + - template: /eng/pipelines/templates/steps/set-artifact-packages.yml + parameters: + Artifacts: ${{ parameters.Artifacts }} + - pwsh: | - node eng/tools/rush-runner.js check-format "${{parameters.ServiceDirectory}}" --verbose + node eng/tools/rush-runner.js check-format "${{parameters.ServiceDirectory}}" -packages "$(ArtifactPackageNames)" --verbose displayName: "Check Format in Libraries" - script: | - node eng/tools/rush-runner.js audit "${{parameters.ServiceDirectory}}" + node eng/tools/rush-runner.js audit "${{parameters.ServiceDirectory}}" -packages "$(ArtifactPackageNames)" condition: and(succeeded(), eq(variables['RunNpmAudit'], 'true')) displayName: "Audit libraries" diff --git a/eng/pipelines/templates/steps/build.yml b/eng/pipelines/templates/steps/build.yml index 54f3a52256f..58ac2527ad2 100644 --- a/eng/pipelines/templates/steps/build.yml +++ b/eng/pipelines/templates/steps/build.yml @@ -45,13 +45,17 @@ steps: condition: and(succeeded(),ne(variables['SetDevVersion'],'true')) displayName: "Install dependencies" + - template: /eng/pipelines/templates/steps/set-artifact-packages.yml + parameters: + Artifacts: ${{ parameters.Artifacts }} + # Option "-p max" ensures parallelism is set to the number of cores on all platforms, which improves build times. # The default on Windows is "cores - 1" (microsoft/rushstack#436). - script: | - node eng/tools/rush-runner.js build "${{parameters.ServiceDirectory}}" --verbose -p max + node eng/tools/rush-runner.js build "${{parameters.ServiceDirectory}}" -packages "$(ArtifactPackageNames)" --verbose -p max displayName: "Build libraries" - script: | - node eng/tools/rush-runner.js build:samples "${{parameters.ServiceDirectory}}" --verbose + node eng/tools/rush-runner.js build:samples "${{parameters.ServiceDirectory}}" -packages "$(ArtifactPackageNames)" --verbose displayName: "Build samples" - pwsh: | @@ -59,7 +63,7 @@ steps: displayName: "Check api extractor output changes" - script: | - node eng/tools/rush-runner.js pack "${{parameters.ServiceDirectory}}" --verbose + node eng/tools/rush-runner.js pack "${{parameters.ServiceDirectory}}" -packages "$(ArtifactPackageNames)" --verbose displayName: "Pack libraries" # Unlink node_modules folders to significantly improve performance of subsequent tasks diff --git a/eng/pipelines/templates/steps/set-artifact-packages.yml b/eng/pipelines/templates/steps/set-artifact-packages.yml new file mode 100644 index 00000000000..50090c8258d --- /dev/null +++ b/eng/pipelines/templates/steps/set-artifact-packages.yml @@ -0,0 +1,12 @@ +parameters: + Artifacts: [] +steps: + - pwsh: | + $artifacts = '${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json + $packages = "" + foreach ($artifact in $artifacts) + { + $packages += "$($artifact.name)," + } + echo "##vso[task.setvariable variable=ArtifactPackageNames]$packages" + displayName: "Find Packages to build" diff --git a/eng/pipelines/templates/steps/test.yml b/eng/pipelines/templates/steps/test.yml index 5a778b44c1b..9993cd5b9bf 100644 --- a/eng/pipelines/templates/steps/test.yml +++ b/eng/pipelines/templates/steps/test.yml @@ -12,16 +12,20 @@ steps: node common/scripts/install-run-rush.js install displayName: "Install dependencies" + - template: /eng/pipelines/templates/steps/set-artifact-packages.yml + parameters: + Artifacts: ${{ parameters.Artifacts }} + # Option "-p max" ensures parallelism is set to the number of cores on all platforms, which improves build times. # The default on Windows is "cores - 1" (microsoft/rushstack#436). - script: | - node eng/tools/rush-runner.js build "${{parameters.ServiceDirectory}}" --verbose -p max + node eng/tools/rush-runner.js build "${{parameters.ServiceDirectory}}" -packages "$(ArtifactPackageNames)" --verbose -p max displayName: "Build libraries" # Option "-p max" ensures parallelism is set to the number of cores on all platforms, which improves build times. # The default on Windows is "cores - 1" (microsoft/rushstack#436). - script: | - node eng/tools/rush-runner.js build:test "${{parameters.ServiceDirectory}}" --verbose -p max + node eng/tools/rush-runner.js build:test "${{parameters.ServiceDirectory}}" -packages "$(ArtifactPackageNames)" --verbose -p max displayName: "Build test assets" - template: ../steps/use-node-test-version.yml @@ -32,14 +36,14 @@ steps: # Option "-p max" ensures parallelism is set to the number of cores on all platforms, which improves build times. # The default on Windows is "cores - 1" (microsoft/rushstack#436). - script: | - node eng/tools/rush-runner.js unit-test:node "${{parameters.ServiceDirectory}}" --verbose -p max + node eng/tools/rush-runner.js unit-test:node "${{parameters.ServiceDirectory}}" -packages "$(ArtifactPackageNames)" --verbose -p max displayName: "Test libraries" condition: and(succeeded(),eq(variables['TestType'], 'node')) # Option "-p max" ensures parallelism is set to the number of cores on all platforms, which improves build times. # The default on Windows is "cores - 1" (microsoft/rushstack#436). - script: | - node eng/tools/rush-runner.js unit-test:browser "${{parameters.ServiceDirectory}}" --verbose -p max + node eng/tools/rush-runner.js unit-test:browser "${{parameters.ServiceDirectory}}" -packages "$(ArtifactPackageNames)" --verbose -p max displayName: "Test libraries" condition: and(succeeded(),eq(variables['TestType'], 'browser')) diff --git a/eng/tools/rush-runner.js b/eng/tools/rush-runner.js index 84c9ca86a66..f53129bcca2 100644 --- a/eng/tools/rush-runner.js +++ b/eng/tools/rush-runner.js @@ -56,26 +56,37 @@ const parseArgs = () => { } let inFlags = false; + let isPackageFilter = false; + let artifactNames = ""; const services = [], flags = []; const [scriptPath, action, ...givenArgs] = process.argv.slice(1); const baseDir = path.resolve(`${path.dirname(scriptPath)}/../..`); for (const arg of givenArgs) { - if (!inFlags && arg.startsWith("-")) { + if (arg === "-packages") { + isPackageFilter = true; + continue; + } + else if (!inFlags && arg.startsWith("-")) { inFlags = true; } if (inFlags) { flags.push(arg); - } else { + } + else if (isPackageFilter) { + artifactNames = arg; + isPackageFilter = false; + } + else { if (arg && arg !== "*") { // exclude empty value and special value "*" meaning all libraries services.push(arg); } } } - return [baseDir, action, services, flags]; + return [baseDir, action, services, flags, artifactNames]; }; const getPackageJsons = (searchDir) => { @@ -97,22 +108,25 @@ const getPackageJsons = (searchDir) => { return sdkDirectories.concat(perfTestDirectories).filter((f) => fs.existsSync(f)); // only keep paths for files that actually exist }; -const getServicePackages = (baseDir, serviceDirs) => { +const getServicePackages = (baseDir, serviceDirs, artifactNames) => { const packageNames = []; const packageDirs = []; - const validSdkTypes = ["client", "mgmt", "perf-test", "utility"]; // valid "sdk-type"s that we are looking for, to be able to apply rush-runner jobs on + let validSdkTypes = ["client", "mgmt", "perf-test", "utility"]; // valid "sdk-type"s that we are looking for, to be able to apply rush-runner jobs on + console.log(`Packages to build: ${artifactNames}`); + const artifacts = artifactNames.split(","); for (const serviceDir of serviceDirs) { const searchDir = path.resolve(path.join(baseDir, "sdk", serviceDir)); const packageJsons = getPackageJsons(searchDir); for (const filePath of packageJsons) { const contents = JSON.parse(fs.readFileSync(filePath, "utf8")); - if (validSdkTypes.includes(contents["sdk-type"])) { + const artifactName = contents.name.replace("@", "").replace("/", "-"); + if (validSdkTypes.includes(contents["sdk-type"]) && artifacts.includes(artifactName)) { packageNames.push(contents.name); packageDirs.push(path.dirname(filePath)); } } } - + console.log(`Packages eligible to run rush task: ${packageNames}`); return [packageNames, packageDirs]; }; @@ -134,9 +148,9 @@ const flatMap = (arr, f) => { return [].concat(...result); }; -const [baseDir, action, serviceDirs, rushParams] = parseArgs(); +const [baseDir, action, serviceDirs, rushParams, artifactNames] = parseArgs(); -const [packageNames, packageDirs] = getServicePackages(baseDir, serviceDirs); +const [packageNames, packageDirs] = getServicePackages(baseDir, serviceDirs, artifactNames); /** * Helper function to provide the rush logic that is used frequently below diff --git a/sdk/advisor/ci.mgmt.yml b/sdk/advisor/ci.mgmt.yml index fdb08675b40..031f45a21b4 100644 --- a/sdk/advisor/ci.mgmt.yml +++ b/sdk/advisor/ci.mgmt.yml @@ -30,4 +30,4 @@ extends: ServiceDirectory: advisor Artifacts: - name: azure-arm-advisor - safeName: azurearmadvisor \ No newline at end of file + safeName: azurearmadvisor diff --git a/sdk/appconfiguration/ci.yml b/sdk/appconfiguration/ci.yml index 38130f8657c..08154e8b42e 100644 --- a/sdk/appconfiguration/ci.yml +++ b/sdk/appconfiguration/ci.yml @@ -32,4 +32,4 @@ extends: ServiceDirectory: appconfiguration Artifacts: - name: azure-app-configuration - safeName: azureappconfiguration \ No newline at end of file + safeName: azureappconfiguration