From 0e9854d63631b5b1fedfe1d1fb6673641b471835 Mon Sep 17 00:00:00 2001 From: vinca Date: Wed, 15 Feb 2017 14:29:27 +0530 Subject: [PATCH 1/8] Recursive Copy Fix * MSdeploy Changes --- Tasks/Common/webdeployment-common/deployusingmsdeploy.ts | 2 +- .../webdeployment-common/fileTransformationsUtility.ts | 6 ++---- Tasks/Common/webdeployment-common/msdeployutility.ts | 2 +- Tasks/Common/webdeployment-common/ziputility.ts | 1 + 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Tasks/Common/webdeployment-common/deployusingmsdeploy.ts b/Tasks/Common/webdeployment-common/deployusingmsdeploy.ts index aae1d5435e16..10d64c4ad573 100644 --- a/Tasks/Common/webdeployment-common/deployusingmsdeploy.ts +++ b/Tasks/Common/webdeployment-common/deployusingmsdeploy.ts @@ -34,7 +34,7 @@ export async function DeployUsingMSDeploy(webDeployPkg, webAppName, publishingPr setParametersFileName = setParametersFile.slice(setParametersFile.lastIndexOf('\\') + 1, setParametersFile.length); } var isParamFilePresentInPackage = isFolderBasedDeployment ? false : await msDeployUtility.containsParamFile(webDeployPkg); - var msDeployPath = await msDeployUtility.getMSDeployFullPath(); + var msDeployCmdArgs = msDeployUtility.getMSDeployCmdArgs(webDeployPkg, webAppName, publishingProfile, removeAdditionalFilesFlag, excludeFilesFromAppDataFlag, takeAppOfflineFlag, virtualApplication, setParametersFileName, additionalArguments, isParamFilePresentInPackage, isFolderBasedDeployment, useWebDeploy); diff --git a/Tasks/Common/webdeployment-common/fileTransformationsUtility.ts b/Tasks/Common/webdeployment-common/fileTransformationsUtility.ts index 2c500c2f472c..a37b9e46d106 100644 --- a/Tasks/Common/webdeployment-common/fileTransformationsUtility.ts +++ b/Tasks/Common/webdeployment-common/fileTransformationsUtility.ts @@ -13,14 +13,12 @@ export async function fileTransformations(isFolderBasedDeployment: boolean, JSON var folderPath = utility.generateTemporaryFolderOrZipPath(tl.getVariable('System.DefaultWorkingDirectory'), true); if(isFolderBasedDeployment) { - tl.debug('Copying Folder: ' + webDeployPkg + ' to temporary location: ' + folderPath); + tl.debug('Copying Web Packge: ' + webDeployPkg + ' to temporary location: ' + folderPath); tl.cp(path.join(webDeployPkg, '/*'), folderPath, '-rf', false); - tl.debug('Copied Folder: ' + webDeployPkg + ' to temporary location: ' + folderPath + ' successfully.'); + tl.debug('Copied Web Package: ' + webDeployPkg + ' to temporary location: ' + folderPath + ' successfully.'); } else { - tl.debug('Extracting Web Deploy Package: ' + webDeployPkg + ' to temporary location: ' + folderPath); await zipUtility.unzip(webDeployPkg, folderPath); - tl.debug('Extracted Web Deploy Package: ' + webDeployPkg + ' to temporary location: ' + folderPath + ' successfully.'); } if(xmlTransformation) { diff --git a/Tasks/Common/webdeployment-common/msdeployutility.ts b/Tasks/Common/webdeployment-common/msdeployutility.ts index c83998f5021b..ae2a7bb0c269 100644 --- a/Tasks/Common/webdeployment-common/msdeployutility.ts +++ b/Tasks/Common/webdeployment-common/msdeployutility.ts @@ -179,7 +179,7 @@ export async function getMSDeployFullPath() { return msDeployFullPath; } catch(error) { - tl.warning(error); + tl.debug(error); return path.join(__dirname, "..", "..", "MSDeploy3.6", "msdeploy.exe"); } } diff --git a/Tasks/Common/webdeployment-common/ziputility.ts b/Tasks/Common/webdeployment-common/ziputility.ts index 4c2722e80437..98e10a29c9d3 100644 --- a/Tasks/Common/webdeployment-common/ziputility.ts +++ b/Tasks/Common/webdeployment-common/ziputility.ts @@ -17,6 +17,7 @@ export async function unzip(zipLocation, unzipLocation) { defer.reject(error); }); unzipper.on('extract', function (log) { + tl.debug('extracted ' + zipLocation + ' to ' + unzipLocation + ' Successfully'); defer.resolve(unzipLocation); }); unzipper.extract({ From 7b5040795e06f143bffaae2193eb3bf1655894bd Mon Sep 17 00:00:00 2001 From: vinca Date: Wed, 15 Feb 2017 14:35:56 +0530 Subject: [PATCH 2/8] resolve merge conflict - 1 --- Tasks/Common/webdeployment-common/deployusingmsdeploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/Common/webdeployment-common/deployusingmsdeploy.ts b/Tasks/Common/webdeployment-common/deployusingmsdeploy.ts index b1482170f876..080cca7c3c96 100644 --- a/Tasks/Common/webdeployment-common/deployusingmsdeploy.ts +++ b/Tasks/Common/webdeployment-common/deployusingmsdeploy.ts @@ -33,7 +33,7 @@ export async function DeployUsingMSDeploy(webDeployPkg, webAppName, publishingPr if(setParametersFile != null) { setParametersFileName = setParametersFile.slice(setParametersFile.lastIndexOf('\\') + 1, setParametersFile.length); } - var isParamFilePresentInPackage = isFolderBasedDeployment ? false : await msDeployUtility.containsParamFile(webDeployPkg); + var isParamFilePresentInPackage = isFolderBasedDeployment ? false : await utility.isMSDeployPackage(webDeployPkg); var msDeployCmdArgs = msDeployUtility.getMSDeployCmdArgs(webDeployPkg, webAppName, publishingProfile, removeAdditionalFilesFlag, excludeFilesFromAppDataFlag, takeAppOfflineFlag, virtualApplication, setParametersFileName, additionalArguments, isParamFilePresentInPackage, isFolderBasedDeployment, From 0762e921eeb783ea3bc1fdbb6339f0eb65e31de0 Mon Sep 17 00:00:00 2001 From: vinca Date: Thu, 16 Feb 2017 13:01:07 +0530 Subject: [PATCH 3/8] copy dir added ! --- .../fileTransformationsUtility.ts | 2 +- Tasks/Common/webdeployment-common/utility.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Tasks/Common/webdeployment-common/fileTransformationsUtility.ts b/Tasks/Common/webdeployment-common/fileTransformationsUtility.ts index a37b9e46d106..10f972ac2099 100644 --- a/Tasks/Common/webdeployment-common/fileTransformationsUtility.ts +++ b/Tasks/Common/webdeployment-common/fileTransformationsUtility.ts @@ -14,7 +14,7 @@ export async function fileTransformations(isFolderBasedDeployment: boolean, JSON if(isFolderBasedDeployment) { tl.debug('Copying Web Packge: ' + webDeployPkg + ' to temporary location: ' + folderPath); - tl.cp(path.join(webDeployPkg, '/*'), folderPath, '-rf', false); + utility.copyDirectory(webDeployPkg, folderPath); tl.debug('Copied Web Package: ' + webDeployPkg + ' to temporary location: ' + folderPath + ' successfully.'); } else { diff --git a/Tasks/Common/webdeployment-common/utility.ts b/Tasks/Common/webdeployment-common/utility.ts index 1a280bdc14c2..1c573b5d71dc 100644 --- a/Tasks/Common/webdeployment-common/utility.ts +++ b/Tasks/Common/webdeployment-common/utility.ts @@ -153,4 +153,23 @@ export async function isMSDeployPackage(webAppPackage: string ) { } tl.debug("Is the package an msdeploy package : " + isParamFilePresent); return isParamFilePresent; +} + +export function copyDirectory(sourceDirectory: string, destDirectory: string) { + var queue = [[sourceDirectory, destDirectory]]; + while(queue.length > 0) { + var sourceDestPair = queue.shift(); + if(tl.stats(sourceDestPair[0]).isDirectory()) { + var listDir = tl.ls('-A',[sourceDestPair[0]]); + tl.debug('list of files to copy from ' + sourceDestPair[0] + ' to ' + sourceDestPair[1] + ' : ' + listDir); + for(var relativePath of listDir) { + queue.push([path.join(sourceDestPair[0], relativePath), path.join(sourceDestPair[1], relativePath)]); + } + tl.mkdirP(sourceDestPair[1]); + } + else { + tl.debug('Copying file: ' + sourceDestPair[0] + ' to ' + sourceDestPair[1]); + tl.cp(sourceDestPair[0], sourceDestPair[1], '-f', false); + } + } } \ No newline at end of file From 0e3495f38bbb6b33e90e5e6461d67c36869f5f4a Mon Sep 17 00:00:00 2001 From: vinca Date: Thu, 16 Feb 2017 13:59:30 +0530 Subject: [PATCH 4/8] task version updated ! --- Tasks/AzureRmWebAppDeployment/task.json | 2 +- Tasks/AzureRmWebAppDeployment/task.loc.json | 2 +- Tasks/IISWebAppDeploymentOnMachineGroup/task.json | 2 +- Tasks/IISWebAppDeploymentOnMachineGroup/task.loc.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tasks/AzureRmWebAppDeployment/task.json b/Tasks/AzureRmWebAppDeployment/task.json index 19d5617968b4..9d101b3a916c 100644 --- a/Tasks/AzureRmWebAppDeployment/task.json +++ b/Tasks/AzureRmWebAppDeployment/task.json @@ -16,7 +16,7 @@ "version": { "Major": 3, "Minor": 0, - "Patch": 7 + "Patch": 8 }, "preview": "true", "releaseNotes": "What's new in Version 3.0:
  Supports File Transformations (XDT)
  Supports Variable Substitutions(XML, JSON)
Click [here](https://aka.ms/azurermwebdeployreadme) for more Information.", diff --git a/Tasks/AzureRmWebAppDeployment/task.loc.json b/Tasks/AzureRmWebAppDeployment/task.loc.json index fb16de8f8fa3..1492cdc2aacf 100644 --- a/Tasks/AzureRmWebAppDeployment/task.loc.json +++ b/Tasks/AzureRmWebAppDeployment/task.loc.json @@ -16,7 +16,7 @@ "version": { "Major": 3, "Minor": 0, - "Patch": 7 + "Patch": 8 }, "preview": "true", "releaseNotes": "What's new in Version 3.0:
  Supports File Transformations (XDT)
  Supports Variable Substitutions(XML, JSON)
Click [here](https://aka.ms/azurermwebdeployreadme) for more Information.", diff --git a/Tasks/IISWebAppDeploymentOnMachineGroup/task.json b/Tasks/IISWebAppDeploymentOnMachineGroup/task.json index 4cfb60a66b14..594b18198f1e 100644 --- a/Tasks/IISWebAppDeploymentOnMachineGroup/task.json +++ b/Tasks/IISWebAppDeploymentOnMachineGroup/task.json @@ -15,7 +15,7 @@ "version": { "Major": 0, "Minor": 0, - "Patch": 9 + "Patch": 10 }, "demands": [], "minimumAgentVersion": "2.104.1", diff --git a/Tasks/IISWebAppDeploymentOnMachineGroup/task.loc.json b/Tasks/IISWebAppDeploymentOnMachineGroup/task.loc.json index 9bdac9f6c369..916972c8dedc 100644 --- a/Tasks/IISWebAppDeploymentOnMachineGroup/task.loc.json +++ b/Tasks/IISWebAppDeploymentOnMachineGroup/task.loc.json @@ -15,7 +15,7 @@ "version": { "Major": 0, "Minor": 0, - "Patch": 9 + "Patch": 10 }, "demands": [], "minimumAgentVersion": "2.104.1", From 27d9588ab30d38735cfb0668849899ae59a5d0e1 Mon Sep 17 00:00:00 2001 From: vinca Date: Fri, 17 Feb 2017 13:13:38 +0530 Subject: [PATCH 5/8] changed copy files logic --- Tasks/Common/webdeployment-common/utility.ts | 26 +++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Tasks/Common/webdeployment-common/utility.ts b/Tasks/Common/webdeployment-common/utility.ts index 1c573b5d71dc..a9d76a2b0c27 100644 --- a/Tasks/Common/webdeployment-common/utility.ts +++ b/Tasks/Common/webdeployment-common/utility.ts @@ -156,20 +156,22 @@ export async function isMSDeployPackage(webAppPackage: string ) { } export function copyDirectory(sourceDirectory: string, destDirectory: string) { - var queue = [[sourceDirectory, destDirectory]]; - while(queue.length > 0) { - var sourceDestPair = queue.shift(); - if(tl.stats(sourceDestPair[0]).isDirectory()) { - var listDir = tl.ls('-A',[sourceDestPair[0]]); - tl.debug('list of files to copy from ' + sourceDestPair[0] + ' to ' + sourceDestPair[1] + ' : ' + listDir); - for(var relativePath of listDir) { - queue.push([path.join(sourceDestPair[0], relativePath), path.join(sourceDestPair[1], relativePath)]); - } - tl.mkdirP(sourceDestPair[1]); + if(!tl.exist(destDirectory)) { + tl.mkdirP(destDirectory); + } + var listSrcDirectory = tl.find(sourceDirectory); + for(var srcDirPath of listSrcDirectory) { + var relativePath = srcDirPath.substring(sourceDirectory.length); + var destinationPath = path.join(destDirectory, relativePath); + if(tl.stats(srcDirPath).isDirectory()) { + tl.mkdirP(destinationPath); } else { - tl.debug('Copying file: ' + sourceDestPair[0] + ' to ' + sourceDestPair[1]); - tl.cp(sourceDestPair[0], sourceDestPair[1], '-f', false); + if(tl.exist(path.dirname(destinationPath))) { + tl.mkdirP(path.dirname(destinationPath)); + } + tl.debug('copy file from: ' + srcDirPath + ' to: ' + destinationPath); + tl.cp(srcDirPath, destinationPath, '-f', false); } } } \ No newline at end of file From 31d20e96358326e19a03becfb2eb4c7377c8f8bd Mon Sep 17 00:00:00 2001 From: vinca Date: Mon, 20 Feb 2017 10:39:00 +0530 Subject: [PATCH 6/8] make dir if not exist --- Tasks/Common/webdeployment-common/utility.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/Common/webdeployment-common/utility.ts b/Tasks/Common/webdeployment-common/utility.ts index a9d76a2b0c27..799a8e2f29c9 100644 --- a/Tasks/Common/webdeployment-common/utility.ts +++ b/Tasks/Common/webdeployment-common/utility.ts @@ -167,7 +167,7 @@ export function copyDirectory(sourceDirectory: string, destDirectory: string) { tl.mkdirP(destinationPath); } else { - if(tl.exist(path.dirname(destinationPath))) { + if(!tl.exist(path.dirname(destinationPath))) { tl.mkdirP(path.dirname(destinationPath)); } tl.debug('copy file from: ' + srcDirPath + ' to: ' + destinationPath); From 154f7db24f30bc02897a03c46fb2cac0cc19b9c9 Mon Sep 17 00:00:00 2001 From: vinca Date: Tue, 21 Feb 2017 11:17:54 +0530 Subject: [PATCH 7/8] L0 Test added --- Tasks/AzureRmWebAppDeployment/Tests/L0.ts | 9 +++ .../Tests/L0CopyDirectory.ts | 59 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Tasks/Common/webdeployment-common/Tests/L0CopyDirectory.ts diff --git a/Tasks/AzureRmWebAppDeployment/Tests/L0.ts b/Tasks/AzureRmWebAppDeployment/Tests/L0.ts index 145704208a5e..47a0bda87637 100644 --- a/Tasks/AzureRmWebAppDeployment/Tests/L0.ts +++ b/Tasks/AzureRmWebAppDeployment/Tests/L0.ts @@ -458,4 +458,13 @@ describe('AzureRmWebAppDeployment Suite', function() { done(); }); + it('Validate webdeployment-common.utility.copyDirectory()', (done:MochaDone) => { + let tp = path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L0CopyDirectory.js'); + let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); + tr.run(); + + assert(tr.stdout.search('## Copy Files Successful ##') >=0, 'should have copied the files'); + assert(tr.stdout.search('## mkdir Successful ##') >= 0, 'should have created dir including dest folder'); + done(); + }); }); diff --git a/Tasks/Common/webdeployment-common/Tests/L0CopyDirectory.ts b/Tasks/Common/webdeployment-common/Tests/L0CopyDirectory.ts new file mode 100644 index 000000000000..82ed38b23299 --- /dev/null +++ b/Tasks/Common/webdeployment-common/Tests/L0CopyDirectory.ts @@ -0,0 +1,59 @@ +var mockery = require('mockery'); +mockery.enable({ + useCleanCache: true, + warnOnReplace: false, + warnOnUnregistered: false +}); + +var fileList = ["C:/vinca/path", "C:/vinca/path/myfile.txt", + "C:/vinca/path/New Folder", "C:/vinca/path/New Folder/Another New Folder", + "C:/vinca/New Folder/anotherfile.py", "C:/vinca/New Folder/Another New Folder/mynewfile.txt"]; + +var mkdirPCount = 0; +var cpfilesCount = 0; +mockery.registerMock('vsts-task-lib/task', { + exist: function (path) { + console.log("exist : " + path); + }, + find: function (path) { + console.log("find : " + path); + return fileList; + }, + mkdirP: function (path) { + mkdirPCount += 1; + console.log("mkdirp : " + path); + }, + cp: function (source, dest, options, continueOnError) { + if(fileList.indexOf(source)!= -1) { + cpfilesCount += 1; + console.log('cp ' + source + ' to ' + dest); + } + }, + stats: function (path) { + return { + isDirectory: function() { + if(path.endsWith('.py') || path.endsWith('.txt')) { + return false; + } + return true; + } + }; + }, + debug: function(message) { + console.log(message); + } +}); +var utility = require('webdeployment-common/utility.js'); +utility.copyDirectory('C:/vinca/path', 'C:/vinca/path/destFolder'); + +if(cpfilesCount === 3) { + console.log('## Copy Files Successful ##'); +} +/** + * 7 dir to be created including dest dir + * Hash is not created to check already created dir, for testing purpose + */ +if(mkdirPCount === 7) { + console.log('## mkdir Successful ##'); +} + From 84e917d8d73e0389397c83c80d6e114e52be3847 Mon Sep 17 00:00:00 2001 From: vinca Date: Tue, 21 Feb 2017 15:37:31 +0530 Subject: [PATCH 8/8] L0 test for IIS App Deployment --- Tasks/IISWebAppDeploymentOnMachineGroup/Tests/L0.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tasks/IISWebAppDeploymentOnMachineGroup/Tests/L0.ts b/Tasks/IISWebAppDeploymentOnMachineGroup/Tests/L0.ts index 63887f04b17b..ded7c2fbbf5d 100644 --- a/Tasks/IISWebAppDeploymentOnMachineGroup/Tests/L0.ts +++ b/Tasks/IISWebAppDeploymentOnMachineGroup/Tests/L0.ts @@ -210,4 +210,13 @@ describe('IISWebsiteDeploymentOnMachineGroup test suite', function() { done(); }); + it('Validate webdeployment-common.utility.copyDirectory()', (done:MochaDone) => { + let tp = path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L0CopyDirectory.js'); + let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); + tr.run(); + + assert(tr.stdout.search('## Copy Files Successful ##') >=0, 'should have copied the files'); + assert(tr.stdout.search('## mkdir Successful ##') >= 0, 'should have created dir including dest folder'); + done(); + }); });