Skip to content

Commit

Permalink
Use Rush for building in Azure DevOps
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Siegel committed May 8, 2019
1 parent 897f3be commit 805f87a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 215 deletions.
46 changes: 13 additions & 33 deletions .azure-pipelines/client.test.live.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# External variables:
# Package
# The package to build and test. Defined in pipeline web ui because multiple pipelines use this YAML with different packages.
# Example: eventhubs-client
# Example: @azure/event-hubs
#
# AdditionalTestArguments
# Additional arguments to the test command.
Expand Down Expand Up @@ -34,24 +34,13 @@ jobs:
versionSpec: '$(NodeVersion)'
displayName: 'Install Node.js $(NodeVersion)'

# Rather than running "npm install" in the repo root, reduce build time by only installing the "npm-run-all" package,
# which is the minimum required to run the composite script commands.
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'install npm-run-all'
displayName: 'npm install npm-run-all'

- task: Npm@1
inputs:
command: 'custom'
customCommand: 'run install-client-$(Package)'
displayName: 'npm run install-client-$(Package)'
- script: |
node common/scripts/install-run-rush.js install
displayName: 'rush install'
# To get realtime logging of test progress in Azure Pipelines, we need to use "script" instead of "Npm@1",
# since "Npm@1" currently buffers output (https://github.com/Microsoft/azure-pipelines-tasks/issues/8171).
- script: npm run live-test-client-$(Package)-node -- -- --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- $(AdditionalTestArguments)
displayName: 'npm run live-test-client-$(Package)-node'
- script: |
node common/scripts/npm-run-project.js "$(Package)" integration-test:node -- -- --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- $(AdditionalTestArguments)
displayName: 'npm-run-project "$(Package)" integration-test:node'
env:
# Service Bus
AAD_CLIENT_ID: $(aad-azure-sdk-test-client-id)
Expand Down Expand Up @@ -100,23 +89,14 @@ jobs:
versionSpec: '$(NodeVersion)'
displayName: 'Install Node.js $(NodeVersion)'

# Rather than running "npm install" in the repo root, reduce build time by only installing the "npm-run-all" package,
# which is the minimum required to run the composite script commands.
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'install npm-run-all'
displayName: 'npm install npm-run-all'

- task: Npm@1
inputs:
command: 'custom'
customCommand: 'run install-client-$(Package)'
displayName: 'npm run install-client-$(Package)'
- script: |
node common/scripts/install-run-rush.js install
displayName: 'rush install'
- script: npm run live-test-client-$(Package)-browser
- script: |
node common/scripts/install-run-rush.js integration-test:browser -t "$(Package)"
condition: succeededOrFailed()
displayName: 'npm run live-test-client-$(Package)-browser'
displayName: 'rush integration-test:browser -t "$(Package)"'
env:
# Service Bus
AAD_CLIENT_ID: $(aad-azure-sdk-test-client-id)
Expand Down
46 changes: 13 additions & 33 deletions .azure-pipelines/client.test.storage.live.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# External variables:
# Package
# The package to build and test. Defined in pipeline web ui because multiple pipelines use this YAML with different packages.
# Example: eventhubs-client
# Example: @azure/event-hubs
#
# AdditionalTestArguments
# Additional arguments to the test command.
Expand Down Expand Up @@ -62,24 +62,13 @@ jobs:
versionSpec: '$(NodeVersion)'
displayName: 'Install Node.js $(NodeVersion)'

# Rather than running "npm install" in the repo root, reduce build time by only installing the "npm-run-all" package,
# which is the minimum required to run the composite script commands.
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'install npm-run-all'
displayName: 'npm install npm-run-all'

- task: Npm@1
inputs:
command: 'custom'
customCommand: 'run install-client-$(Package)'
displayName: 'npm run install-client-$(Package)'
- script: |
node common/scripts/install-run-rush.js install
displayName: 'rush install'
# To get realtime logging of test progress in Azure Pipelines, we need to use "script" instead of "Npm@1",
# since "Npm@1" currently buffers output (https://github.com/Microsoft/azure-pipelines-tasks/issues/8171).
- script: npm run live-test-client-$(Package)-node -- -- --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- $(AdditionalTestArguments)
displayName: 'npm run live-test-client-$(Package)-node'
- script: |
node common/scripts/npm-run-project.js "$(Package)" integration-test:node -- -- --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- $(AdditionalTestArguments)
displayName: 'npm-run-project "$(Package)" integration-test:node'
env:
# Storage
ACCOUNT_NAME: $(js-storage-test-account-name)
Expand Down Expand Up @@ -123,23 +112,14 @@ jobs:
versionSpec: '$(NodeVersion)'
displayName: 'Install Node.js $(NodeVersion)'

# Rather than running "npm install" in the repo root, reduce build time by only installing the "npm-run-all" package,
# which is the minimum required to run the composite script commands.
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'install npm-run-all'
displayName: 'npm install npm-run-all'

- task: Npm@1
inputs:
command: 'custom'
customCommand: 'run install-client-$(Package)'
displayName: 'npm run install-client-$(Package)'
- script: |
node common/scripts/install-run-rush.js install
displayName: 'rush install'
- script: npm run live-test-client-$(Package)-browser
- script: |
node common/scripts/install-run-rush.js integration-test:browser -t "$(Package)"
condition: succeededOrFailed()
displayName: 'npm run live-test-client-$(Package)-browser'
displayName: 'rush integration-test:browser -t "$(Package)"'
env:
# Storage
ACCOUNT_NAME: $(js-storage-test-account-name)
Expand Down
89 changes: 28 additions & 61 deletions .azure-pipelines/client.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# External variables:
# packageSuffix
# The package suffix for the package to build and test. Defined in pipeline web ui because multiple pipelines use this YAML with different packages.
# Example: -eventhubs-client
# rushFlags
# Flags to pass to Rush for bulk commands. Typically, this is used to limit commands to a subset of packages, or to enable verbose output.
# Defined in pipeline web ui because multiple pipelines use this YAML with different packages.
# Example: -t @azure/event-hubs --verbose
#
trigger:
- master
Expand All @@ -21,42 +22,28 @@ jobs:
versionSpec: '$(NodeVersion)'
displayName: 'Install Node.js $(NodeVersion)'

# Rather than running "npm install" in the repo root, reduce build time by only installing the "npm-run-all" package,
# which is the minimum required to run the composite script commands.
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'install npm-run-all'
displayName: 'npm install npm-run-all'

- task: Npm@1
inputs:
command: 'custom'
customCommand: 'run install-client$(packageSuffix)'
displayName: 'npm run install-client$(packageSuffix)'
- script: |
node common/scripts/install-run-rush.js install
displayName: 'Install dependencies'
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'run build-client$(packageSuffix)'
displayName: 'npm run build-client$(packageSuffix)'
- script: |
node common/scripts/install-run-rush.js build $(rushFlags)
displayName: 'Build libraries'
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'run pack-client$(packageSuffix)'
displayName: 'npm run pack-client$(packageSuffix)'
- script: |
node common/scripts/install-run-rush.js pack $(rushFlags)
displayName: 'Pack libraries'
- task: CopyFiles@2
inputs:
contents: 'sdk/**/**/*.tgz'
targetFolder: $(Build.ArtifactStagingDirectory)
flattenFolders: true
displayName: 'Copy Packages'
displayName: 'Copy packages'

- task: PublishBuildArtifacts@1
condition: succeededOrFailed()
displayName: 'Publish Artifacts'
displayName: 'Publish artifacts'
inputs:
artifactName: packages

Expand All @@ -82,20 +69,11 @@ jobs:
ward scan -d $(Build.SourcesDirectory) -c $(Build.SourcesDirectory)/.docsettings.yml
displayName: 'Verify Readmes'
# Rather than running "npm install" in the repo root, reduce build time by only installing the "npm-run-all" package,
# which is the minimum required to run the composite script commands.
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'install npm-run-all'
displayName: 'npm install npm-run-all'

- task: Npm@1
- script: |
node common/scripts/install-run-rush.js install
node common/scripts/install-run-rush.js audit $(rushFlags)
condition: and(succeeded(), eq(variables['RunNpmAudit'], 'true'))
inputs:
command: 'custom'
customCommand: 'run audit-client$(packageSuffix)'
displayName: 'npm run audit-client$(packageSuffix)'
displayName: 'Audit packages'
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
# ComponentGovernance is currently unable to run on pull requests of public projects. Running on non-PR
Expand Down Expand Up @@ -153,28 +131,17 @@ jobs:
versionSpec: '$(NodeVersion)'
displayName: 'Install Node.js $(NodeVersion)'

# Rather than running "npm install" in the repo root, reduce build time by only installing the "npm-run-all" package,
# which is the minimum required to run the composite script commands.
#
# Also, "npm install" in the repo root fails when using Node11 on Windows or Linux
# (https://github.com/Azure/azure-sdk-for-js/issues/845)
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'install npm-run-all'
displayName: 'npm install npm-run-all'
- script: |
node common/scripts/install-run-rush.js install
displayName: 'Install dependencies'
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'run install-client$(packageSuffix)'
displayName: 'npm run install-client$(packageSuffix)'
- script: |
node common/scripts/install-run-rush.js build:test $(rushFlags)
displayName: 'Build libraries'
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'run test-client$(packageSuffix) -- -- -- --reporter mocha-junit-reporter'
displayName: 'npm run test-client$(packageSuffix)'
- script: |
node common/scripts/install-run-rush.js unit-test $(rushFlags)
displayName: 'Test libraries'
- task: PublishTestResults@2
inputs:
Expand Down
49 changes: 49 additions & 0 deletions common/scripts/npm-run-project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const fs = require("fs");
const process = require("process");
const childProcess = require("child_process");

function read(filename) {
const txt = fs
.readFileSync(filename, "utf8")
.replace(/\r/gm, "")
.replace(/\n/gm, "«")
.replace(/\/\*.*?\*\//gm, "")
.replace(/«/gm, "\n")
.replace(/\s+\/\/.*/g, "");
return JSON.parse(txt);
}

const [nodePath, /* Ex: /bin/node */ scriptPath, /* /repo/common/scripts/npm-run-project.js */ projectName, /* myproject */ ...scriptNameAndArgs /* [lint, --fix] */] = process.argv;
if (!nodePath || !scriptPath) {
throw new Error('Unexpected exception: could not detect node path or script path');
}
if (process.argv.length < 3) {
console.error('Usage: npm-run-project.js <projectname> <scriptname> [args...]');
console.error('Example: npm-run-project.js myproject lint --fix');
process.exit(1);
}

const rush = read(`${__dirname}/../../rush.json`);
let workingDir;
for (const each of rush.projects) {
if (each.packageName == projectName) {
workingDir = each.projectFolder;
break;
}
}
if (!workingDir) {
console.error(`Project ${projectName} not found in rush.json`);
process.exit(1);
}

try {
const result = childProcess.spawnSync("npm", ["run", ...scriptNameAndArgs], {
stdio: 'inherit',
cwd: workingDir,
env: process.env
});
process.exit(result.status)
} catch (e) {
console.error(`\n\n${e.toString()}\n\n`);
process.exit(1);
}
Loading

0 comments on commit 805f87a

Please sign in to comment.