Skip to content

Commit

Permalink
Move testing dependent projects from a script to Azure Devops Pipeline (
Browse files Browse the repository at this point in the history
#357)

* Disable ms-rest-azure-js tests

* Refactor script

* Add debug statement

* Change test command

* Remove command line arguments

* Rename command

* Split the script

* Add directory creation

* Combine jobs

* Refactor script

* Remove workdir

* Add pwd script

* Change variable name

* Split jobs

* Add additional logging

* Add additional logging

* Add ls -a

* Combine jobs

* Add copying artifacts

* Move artifact to a folder

* Move artifact to a folder

* Rename artifact

* Add npm pack

* Add ls -a

* Fix path

* Add predefined variable

* Introduce variables

* Fix missing variable

* Add autorest.typescript testing

* Add ms-rest-azure-js publishing

* Add working directory parameter

* Fix dependent tasks

* Add debug statement

* Flip order of gulp build

* Bump the version

* Update Constants

* Add friendly job names

* Cleanup debug statements
  • Loading branch information
kpajdzik authored Jun 6, 2019
1 parent 8c76e21 commit 4273b51
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 41 deletions.
111 changes: 89 additions & 22 deletions .devops/azure-pipelines-test-dependent-projects.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,96 @@
variables:
artifactName: ms-rest-js
msRestJsPackageName: azure-ms-rest-js.tgz
msRestAzureArtifactName: ms-rest-azure-js
msRestAzureJsPackageName: azure-ms-rest-azure-js.tgz
tempDirectory: $(Pipeline.Workspace)/.tmp
vmImage: 'Ubuntu 16.04'

jobs:
- job: Test_dependent_projects
- job: prepare_ms_rest_js
displayName: 'Pack and upload ms-rest-js'
pool:
vmImage: 'Ubuntu 16.04'
vmImage: $(vmImage)
steps:
- task: Npm@1
displayName: 'npm install'
- script: 'npm pack'
displayName: 'npm pack'
- script: 'mv azure-ms-rest-js-*.tgz $(msRestJsPackageName)'
displayName: 'rename artifact'
- task: PublishPipelineArtifact@0
inputs:
command: custom
verbose: false
customCommand: install
- task: Npm@1
displayName: 'Build ms-rest-js'
artifactName: $(artifactName)
targetPath: $(msRestJsPackageName)

- job: test_ms_rest_azure_js
displayName: 'Test ms-rest-azure-js with PR ms-rest-js'
dependsOn: prepare_ms_rest_js
pool:
vmImage: $(vmImage)
variables:
repoDir: '$(tempDirectory)/ms-rest-azure-js'
steps:
- task: DownloadPipelineArtifact@0
inputs:
artifactName: $(artifactName)
targetPath: $(System.DefaultWorkingDirectory)
- script: 'mkdir -p $(tempDirectory)'
displayName: 'mkdir -p $(tempDirectory)'
- script: 'git clone https://github.com/Azure/ms-rest-azure-js.git ms-rest-azure-js --depth 1'
workingDirectory: $(tempDirectory)
displayName: "clone ms-rest-azure-js"
- script: 'npm pack'
workingDirectory: $(repoDir)
displayName: 'npm pack'
- script: 'npm install $(Build.SourcesDirectory)/$(msRestJsPackageName)'
workingDirectory: $(repoDir)
displayName: 'npm install @azure/ms-rest-js'
- script: 'npm run test'
workingDirectory: $(repoDir)
displayName: "npm run test"
- script: 'mv azure-ms-rest-azure-js-*.tgz $(msRestAzureJsPackageName)'
workingDirectory: $(repoDir)
displayName: 'rename artifact'
- task: PublishPipelineArtifact@0
inputs:
command: custom
verbose: false
customCommand: 'run build'
- task: Npm@1
displayName: 'npm run dep:ms-rest-azure-js'
artifactName: $(msRestAzureArtifactName)
targetPath: '$(repoDir)/$(msRestAzureJsPackageName)'

- job: test_autorest_typescript
displayName: 'Test autorest.typescript with PR ms-rest-js'
dependsOn: [prepare_ms_rest_js, test_ms_rest_azure_js]
pool:
vmImage: $(vmImage)
variables:
repoDir: '$(tempDirectory)/autorest.typescript'
steps:
- task: DownloadPipelineArtifact@0
inputs:
command: custom
verbose: true
customCommand: run dep:ms-rest-azure-js
- task: Npm@1
displayName: 'npm run dep:autorest.typescript'
artifactName: $(artifactName)
targetPath: $(System.DefaultWorkingDirectory)
- task: DownloadPipelineArtifact@0
inputs:
command: custom
verbose: true
customCommand: run dep:autorest.typescript
artifactName: $(msRestAzureArtifactName)
targetPath: $(System.DefaultWorkingDirectory)
- script: 'mkdir -p $(tempDirectory)'
displayName: 'mkdir -p $(tempDirectory)'
- script: 'git clone https://github.com/Azure/autorest.typescript.git autorest.typescript --recursive --depth 1'
workingDirectory: $(tempDirectory)
displayName: "clone autorest.typescript"
- script: 'npm install $(Build.SourcesDirectory)/$(msRestAzureJsPackageName)'
workingDirectory: $(repoDir)
displayName: 'npm install @azure/ms-rest-azure-js'
- script: 'npm install $(Build.SourcesDirectory)/$(msRestJsPackageName)'
workingDirectory: $(repoDir)
displayName: 'npm install @azure/ms-rest-js'
- script: 'cat package.json'
workingDirectory: $(repoDir)
displayName: "debug"
- script: 'npm install --verbose'
workingDirectory: $(repoDir)
displayName: "npm install"
- script: 'gulp regenerate'
workingDirectory: $(repoDir)
displayName: 'gulp regenerate'
- script: 'gulp test'
workingDirectory: $(repoDir)
displayName: 'gulp test'
44 changes: 28 additions & 16 deletions .scripts/testDependentProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function execAndLog(executable: string, args?: string[], options?: RunOpti
showResult: true,
});

console.log(`\Result of "${commandToString(command)}" [Exit code: ${result.exitCode}]:\n` + result.stdout + "\n");
console.log(`\nResult of "${commandToString(command)}" [Exit code: ${result.exitCode}]:\n` + result.stdout + "\n");

if (result.exitCode) {
console.error(`Error while running "${commandToString(command)}": ${result.error}`);
Expand All @@ -26,28 +26,40 @@ async function execAndLog(executable: string, args?: string[], options?: RunOpti
return Promise.resolve(result);
}

async function cloneRepository(projectName: string, projectDirectory: string) {
const gitHubUrl = `https://github.com/Azure/${projectName}.git`;
await execAndLog(`git`, ["clone", gitHubUrl, projectDirectory, "--recursive"]);
await execAndLog(`npm`, [ "install" ], { executionFolderPath: projectDirectory });
}

async function buildAndTest(projectDirectory: string) {
await execAndLog(`npm`, [ "run", "build" ], { executionFolderPath: projectDirectory });
await execAndLog(`npm`, [ "run", "test" ], { executionFolderPath: projectDirectory });
}

async function cloneAndRunTest(msRestJsDirectory: string, projectName: string) {
const projectDirectory = path.join(msRestJsDirectory, `../.tmp/${projectName}`);
await cloneRepository(projectName, projectDirectory);

await execAndLog(`npm`, [ "install", msRestJsDirectory ], { executionFolderPath: projectDirectory });

const additionalCommands: string[] = process.argv.slice(3);
for (const command of additionalCommands) {
await execAndLog(command, undefined, { executionFolderPath: projectDirectory });
}

await buildAndTest(projectDirectory);
await execAndLog(`rm`, [ "-rf", projectDirectory ]);
}

(async () => {
try {
console.log(`Passed parameters:\n${process.argv}`);
const msRestJsDirectory = path.join(__dirname, "..");
console.log(`ms-rest-js directory: ${msRestJsDirectory}`);

const projectName = process.argv[2];
const projectDirectory = path.join(msRestJsDirectory, `../.tmp/${projectName}`);
const gitHubUrl = `https://github.com/Azure/${projectName}.git`;

await execAndLog(`git`, ["clone", gitHubUrl, projectDirectory, "--recursive"]);
await execAndLog(`npm`, [ "install", msRestJsDirectory ], { executionFolderPath: projectDirectory });
await execAndLog(`npm`, [ "install" ], { executionFolderPath: projectDirectory });

const additionalCommands: string[] = process.argv.slice(3);
for (const command of additionalCommands) {
await execAndLog(command, undefined, { executionFolderPath: projectDirectory });
}

await execAndLog(`npm`, [ "run", "build" ], { executionFolderPath: projectDirectory });
await execAndLog(`npm`, [ "run", "test" ], { executionFolderPath: projectDirectory });
await execAndLog(`rm`, [ "-rf", projectDirectory ]);
await cloneAndRunTest(msRestJsDirectory, projectName);
} catch (error) {
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const Constants = {
* @const
* @type {string}
*/
msRestVersion: "1.8.10",
msRestVersion: "1.8.11",

/**
* Specifies HTTP.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"email": "azsdkteam@microsoft.com",
"url": "https://github.com/Azure/ms-rest-js"
},
"version": "1.8.10",
"version": "1.8.11",
"description": "Isomorphic client Runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest",
"tags": [
"isomorphic",
Expand Down Expand Up @@ -139,7 +139,7 @@
"test:unit": "nyc mocha",
"test:karma": "npm run build:test-browser && node ./node_modules/karma/bin/karma start karma.conf.ts --browsers ChromeNoSecurity --single-run ",
"test:karma:debug": "npm run build:test-browser && node ./node_modules/karma/bin/karma start karma.conf.ts --log-level debug --browsers ChromeDebugging --debug --auto-watch",
"dep:autorest.typescript": "npx ts-node .scripts/testDependentProjects.ts autorest.typescript 'gulp build' 'gulp regenerate' 'npm run local'",
"dep:autorest-typescript": "npx ts-node .scripts/testDependentProjects.ts autorest.typescript 'gulp build' 'gulp regenerate' 'npm run local'",
"dep:ms-rest-azure-js": "npx ts-node .scripts/testDependentProjects.ts ms-rest-azure-js",
"publish-preview": "mocha --no-colors && shx rm -rf dist/test && node ./.scripts/publish",
"local": "ts-node ./.scripts/local.ts",
Expand Down

0 comments on commit 4273b51

Please sign in to comment.