From 093b743a9ab0ad716de9e6cf052e18612ab4ddf7 Mon Sep 17 00:00:00 2001 From: Nathan Carlson Date: Mon, 22 Jan 2018 10:05:35 -0800 Subject: [PATCH 1/3] Support artifacts published from any location --- .../resources.resjson/en-US/resources.resjson | 5 ++++- .../Tests/Test-ApplicationVersions.ps1 | 1 + .../Update-ApplicationVersions.psm1 | 19 +++++++++++++++---- Tasks/ServiceFabricUpdateManifests/task.json | 16 +++++++++++++--- .../task.loc.json | 16 +++++++++++++--- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson b/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson index c4826b1196ba..8e782e62ed64 100644 --- a/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson @@ -15,6 +15,8 @@ "loc.input.help.updateOnlyChanged": "Incrementally update only the packages that have changed. Use the [deterministic compiler flag](https://go.microsoft.com/fwlink/?LinkId=808668) to ensure builds with the same inputs produce the same outputs.", "loc.input.label.pkgArtifactName": "Package Artifact Name", "loc.input.help.pkgArtifactName": "The name of the artifact containing the application package for comparison.", + "loc.input.label.pkgArtifactPath": "Package Artifact Path", + "loc.input.help.pkgArtifactPath": "The path to the artifact containing the application package. [Variables](https://go.microsoft.com/fwlink/?LinkID=550988) and wildcards can be used in the path.", "loc.input.label.logAllChanges": "Log all changes", "loc.input.help.logAllChanges": "Compare all files in every package and log if the file was added, removed, or if its content changed. Otherwise, compare files in a package only until the first change is found for faster performance.", "loc.input.label.compareType": "Compare against", @@ -59,5 +61,6 @@ "loc.messages.FileChanged": "The file '{0}' has changed.", "loc.messages.NoChanges": "Found no changes.", "loc.messages.PdbWarning": "This package contains '*.pdb' files, which will change in every build even if the 'deterministic' compiler flag is used. Exclude these files from your package in order to accurately detect if the package has changed.", - "loc.messages.InvalidImageDigestValue": "The image digest value '{0}' found in file '{1}' is invalid. Expected a value in the format of 'endpoint/image_name@digest_value'." + "loc.messages.InvalidImageDigestValue": "The image digest value '{0}' found in file '{1}' is invalid. Expected a value in the format of 'endpoint/image_name@digest_value'.", + "loc.messages.PackageIsNotUnderArtifact": "The package path '{0}' is not under artifact path '{1}'." } \ No newline at end of file diff --git a/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 b/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 index 6b91089dce6d..0033d59f817d 100644 --- a/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 +++ b/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 @@ -27,6 +27,7 @@ try $oldSuffix = ".OldSuffix" Register-Mock Get-VstsInput { $pkgPath } -- -Name applicationPackagePath -Require + Register-Mock Get-VstsInput { $PSScriptRoot } -- -Name pkgArtifactPath -Require Register-Mock Get-VstsInput { $newSuffix } -- -Name versionSuffix -Require Register-Mock Get-VstsInput { $true } -- -Name updateOnlyChanged -Require Register-Mock Find-VstsFiles { $pkgPath } -- -LegacyPattern $pkgPath -IncludeDirectories diff --git a/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 b/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 index a00a919d0744..c063a4a5cfb7 100644 --- a/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 +++ b/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 @@ -38,6 +38,11 @@ $compareType = Get-VstsInput -Name compareType -Require $buildNumber = Get-VstsInput -Name buildNumber $overwritePkgArtifact = ((Get-VstsInput -Name overwriteExistingPkgArtifact) -eq "true") + $pkgArtifactPath = Get-VstsInput -Name pkgArtifactPath -Require + if (-not $pkgArtifactPath.EndsWith('\')) + { + $pkgArtifactPath = $pkgArtifactPath + '\' + } try { @@ -57,20 +62,26 @@ Write-Host (Get-VstsLocString -Key SearchingApplicationType -ArgumentList $appTypeName) - $oldAppPackagePath = Join-Path $oldDropLocation $newAppPackagePath.SubString((Get-VstsTaskVariable -Name Build.SourcesDirectory -Require).Length + 1) + if (-not $newAppPackagePath.StartsWith($pkgArtifactPath)) + { + Write-Error (Get-VstsLocString -Key PackageIsNotUnderArtifact -ArgumentList @($newAppPackagePath, $pkgArtifactPath)) + } + $relativePath = $newAppPackagePath.SubString($pkgArtifactPath.Length) + + $oldAppPackagePath = Join-Path $oldDropLocation $relativePath $oldAppManifestPath = Join-Path $oldAppPackagePath $appManifestName if (Test-Path $oldAppManifestPath) { $oldAppManifestXml = [XML](Get-Content $oldAppManifestPath) # Set the version to the version from the previous build (including its suffix). This will be overwritten if we find any changes, otherwise it will match the previous build by design. - # Set it before we search for changes so that we can compare the xml without the old version suffix causing a false positive. + # Set it before we search for changes so that we can compare the xml without the old version suffix causing a false positive. $newAppManifestXml.ApplicationManifest.ApplicationTypeVersion = $oldAppManifestXml.ApplicationManifest.ApplicationTypeVersion } else { Write-Warning (Get-VstsLocString -Key NoManifestInPreviousBuild) - $updateAllVersions = $true + $updateAllVersions = $true } } else @@ -85,7 +96,7 @@ $logIndent = "".PadLeft(2) foreach ($serviceManifestImport in $newAppManifestXml.ApplicationManifest.ServiceManifestImport) { - $serviceVersion = Update-ServiceVersions -VersionValue $versionValue -ServiceName $serviceManifestImport.ServiceManifestRef.ServiceManifestName -NewPackageRoot $newAppPackagePath -OldPackageRoot $oldAppPackagePath -LogIndent $logIndent -UpdateAllVersions:$updateAllVersions -LogAllChanges:$logAllChanges -ReplaceVersion:$replaceVersion + $serviceVersion = Update-ServiceVersions -VersionValue $versionValue -ServiceName $serviceManifestImport.ServiceManifestRef.ServiceManifestName -NewPackageRoot $newAppPackagePath -OldPackageRoot $oldAppPackagePath -LogIndent $logIndent -UpdateAllVersions:$updateAllVersions -LogAllChanges:$logAllChanges -ReplaceVersion:$replaceVersion $serviceManifestImport.ServiceManifestRef.ServiceManifestVersion = $serviceVersion } diff --git a/Tasks/ServiceFabricUpdateManifests/task.json b/Tasks/ServiceFabricUpdateManifests/task.json index 6dcdec213658..8179b58d1d0e 100644 --- a/Tasks/ServiceFabricUpdateManifests/task.json +++ b/Tasks/ServiceFabricUpdateManifests/task.json @@ -18,8 +18,8 @@ ], "version": { "Major": 2, - "Minor": 1, - "Patch": 10 + "Minor": 2, + "Patch": 0 }, "minimumAgentVersion": "1.95.0", "instanceNameFormat": "Update Service Fabric Manifests ($(updateType))", @@ -85,6 +85,15 @@ "helpMarkDown": "The name of the artifact containing the application package for comparison.", "visibleRule": "updateType = Manifest versions && updateOnlyChanged = true" }, + { + "name": "pkgArtifactPath", + "type": "string", + "label": "Package Artifact Path", + "defaultValue": "$(build.artifactstagingdirectory)", + "required": true, + "visibleRule": "updateType = Manifest versions && updateOnlyChanged = true", + "helpMarkDown": "The path to the artifact containing the application package. [Variables](https://go.microsoft.com/fwlink/?LinkID=550988) and wildcards can be used in the path." + }, { "name": "logAllChanges", "type": "boolean", @@ -175,6 +184,7 @@ "FileChanged": "The file '{0}' has changed.", "NoChanges": "Found no changes.", "PdbWarning": "This package contains '*.pdb' files, which will change in every build even if the 'deterministic' compiler flag is used. Exclude these files from your package in order to accurately detect if the package has changed.", - "InvalidImageDigestValue": "The image digest value '{0}' found in file '{1}' is invalid. Expected a value in the format of 'endpoint/image_name@digest_value'." + "InvalidImageDigestValue": "The image digest value '{0}' found in file '{1}' is invalid. Expected a value in the format of 'endpoint/image_name@digest_value'.", + "PackageIsNotUnderArtifact": "The package path '{0}' is not under artifact path '{1}'." } } \ No newline at end of file diff --git a/Tasks/ServiceFabricUpdateManifests/task.loc.json b/Tasks/ServiceFabricUpdateManifests/task.loc.json index 2e3405700201..7ea9cc4c644a 100644 --- a/Tasks/ServiceFabricUpdateManifests/task.loc.json +++ b/Tasks/ServiceFabricUpdateManifests/task.loc.json @@ -18,8 +18,8 @@ ], "version": { "Major": 2, - "Minor": 1, - "Patch": 10 + "Minor": 2, + "Patch": 0 }, "minimumAgentVersion": "1.95.0", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", @@ -85,6 +85,15 @@ "helpMarkDown": "ms-resource:loc.input.help.pkgArtifactName", "visibleRule": "updateType = Manifest versions && updateOnlyChanged = true" }, + { + "name": "pkgArtifactPath", + "type": "string", + "label": "ms-resource:loc.input.label.pkgArtifactPath", + "defaultValue": "$(build.artifactstagingdirectory)", + "required": true, + "visibleRule": "updateType = Manifest versions && updateOnlyChanged = true", + "helpMarkDown": "ms-resource:loc.input.help.pkgArtifactPath" + }, { "name": "logAllChanges", "type": "boolean", @@ -175,6 +184,7 @@ "FileChanged": "ms-resource:loc.messages.FileChanged", "NoChanges": "ms-resource:loc.messages.NoChanges", "PdbWarning": "ms-resource:loc.messages.PdbWarning", - "InvalidImageDigestValue": "ms-resource:loc.messages.InvalidImageDigestValue" + "InvalidImageDigestValue": "ms-resource:loc.messages.InvalidImageDigestValue", + "PackageIsNotUnderArtifact": "ms-resource:loc.messages.PackageIsNotUnderArtifact" } } \ No newline at end of file From 8ea1fe8395c5420868b019055880f41629dd0c05 Mon Sep 17 00:00:00 2001 From: Nathan Carlson Date: Wed, 24 Jan 2018 14:29:11 -0800 Subject: [PATCH 2/3] Remove use of pkgArtifactPath --- .../resources.resjson/en-US/resources.resjson | 4 +- .../Tests/Test-ApplicationVersions.ps1 | 1 - .../Update-ApplicationVersions.psm1 | 52 ++++++++++++------- Tasks/ServiceFabricUpdateManifests/task.json | 11 +--- .../task.loc.json | 11 +--- 5 files changed, 36 insertions(+), 43 deletions(-) diff --git a/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson b/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson index 8e782e62ed64..5ad3a6851200 100644 --- a/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson @@ -15,8 +15,6 @@ "loc.input.help.updateOnlyChanged": "Incrementally update only the packages that have changed. Use the [deterministic compiler flag](https://go.microsoft.com/fwlink/?LinkId=808668) to ensure builds with the same inputs produce the same outputs.", "loc.input.label.pkgArtifactName": "Package Artifact Name", "loc.input.help.pkgArtifactName": "The name of the artifact containing the application package for comparison.", - "loc.input.label.pkgArtifactPath": "Package Artifact Path", - "loc.input.help.pkgArtifactPath": "The path to the artifact containing the application package. [Variables](https://go.microsoft.com/fwlink/?LinkID=550988) and wildcards can be used in the path.", "loc.input.label.logAllChanges": "Log all changes", "loc.input.help.logAllChanges": "Compare all files in every package and log if the file was added, removed, or if its content changed. Otherwise, compare files in a package only until the first change is found for faster performance.", "loc.input.label.compareType": "Compare against", @@ -62,5 +60,5 @@ "loc.messages.NoChanges": "Found no changes.", "loc.messages.PdbWarning": "This package contains '*.pdb' files, which will change in every build even if the 'deterministic' compiler flag is used. Exclude these files from your package in order to accurately detect if the package has changed.", "loc.messages.InvalidImageDigestValue": "The image digest value '{0}' found in file '{1}' is invalid. Expected a value in the format of 'endpoint/image_name@digest_value'.", - "loc.messages.PackageIsNotUnderArtifact": "The package path '{0}' is not under artifact path '{1}'." + "loc.messages.CouldNotFindSubPath": "Could not find a subpath of '{0}' under artifact path '{1}'." } \ No newline at end of file diff --git a/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 b/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 index 0033d59f817d..6b91089dce6d 100644 --- a/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 +++ b/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 @@ -27,7 +27,6 @@ try $oldSuffix = ".OldSuffix" Register-Mock Get-VstsInput { $pkgPath } -- -Name applicationPackagePath -Require - Register-Mock Get-VstsInput { $PSScriptRoot } -- -Name pkgArtifactPath -Require Register-Mock Get-VstsInput { $newSuffix } -- -Name versionSuffix -Require Register-Mock Get-VstsInput { $true } -- -Name updateOnlyChanged -Require Register-Mock Find-VstsFiles { $pkgPath } -- -LegacyPattern $pkgPath -IncludeDirectories diff --git a/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 b/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 index c063a4a5cfb7..ac9f45f48e7a 100644 --- a/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 +++ b/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 @@ -38,11 +38,6 @@ $compareType = Get-VstsInput -Name compareType -Require $buildNumber = Get-VstsInput -Name buildNumber $overwritePkgArtifact = ((Get-VstsInput -Name overwriteExistingPkgArtifact) -eq "true") - $pkgArtifactPath = Get-VstsInput -Name pkgArtifactPath -Require - if (-not $pkgArtifactPath.EndsWith('\')) - { - $pkgArtifactPath = $pkgArtifactPath + '\' - } try { @@ -62,26 +57,45 @@ Write-Host (Get-VstsLocString -Key SearchingApplicationType -ArgumentList $appTypeName) - if (-not $newAppPackagePath.StartsWith($pkgArtifactPath)) + # Try and find the old app package path by finding the largest substring of the path that exists in the artifact path + $relativePath = $newAppPackagePath + $pathRoot = [System.IO.Path]::GetPathRoot($relativePath) + if(![System.String]::IsNullOrEmpty($pathRoot)) { - Write-Error (Get-VstsLocString -Key PackageIsNotUnderArtifact -ArgumentList @($newAppPackagePath, $pkgArtifactPath)) + $relativePath = $relativePath.SubString($pathRoot.Length) } - $relativePath = $newAppPackagePath.SubString($pkgArtifactPath.Length) - + $relativePath.Trim([System.IO.Path]::DirectorySeparatorChar) $oldAppPackagePath = Join-Path $oldDropLocation $relativePath - $oldAppManifestPath = Join-Path $oldAppPackagePath $appManifestName - if (Test-Path $oldAppManifestPath) + while(!(Test-Path $oldAppPackagePath)) { - $oldAppManifestXml = [XML](Get-Content $oldAppManifestPath) - - # Set the version to the version from the previous build (including its suffix). This will be overwritten if we find any changes, otherwise it will match the previous build by design. - # Set it before we search for changes so that we can compare the xml without the old version suffix causing a false positive. - $newAppManifestXml.ApplicationManifest.ApplicationTypeVersion = $oldAppManifestXml.ApplicationManifest.ApplicationTypeVersion + $firstSlash = $relativePath.IndexOf([System.IO.Path]::DirectorySeparatorChar) + if ($firstSlash -lt 0) + { + Write-Warning (Get-VstsLocString -Key CouldNotFindSubPath -ArgumentList @($newAppPackagePath, $oldDropLocation)) + $updateAllVersions = $true + $oldAppPackagePath = $null + break; + } + $relativePath = $relativePath.SubString($firstSlash + 1) + $oldAppPackagePath = Join-Path $oldDropLocation $relativePath } - else + + if ($oldAppPackagePath) { - Write-Warning (Get-VstsLocString -Key NoManifestInPreviousBuild) - $updateAllVersions = $true + $oldAppManifestPath = Join-Path $oldAppPackagePath $appManifestName + if (Test-Path $oldAppManifestPath) + { + $oldAppManifestXml = [XML](Get-Content $oldAppManifestPath) + + # Set the version to the version from the previous build (including its suffix). This will be overwritten if we find any changes, otherwise it will match the previous build by design. + # Set it before we search for changes so that we can compare the xml without the old version suffix causing a false positive. + $newAppManifestXml.ApplicationManifest.ApplicationTypeVersion = $oldAppManifestXml.ApplicationManifest.ApplicationTypeVersion + } + else + { + Write-Warning (Get-VstsLocString -Key NoManifestInPreviousBuild) + $updateAllVersions = $true + } } } else diff --git a/Tasks/ServiceFabricUpdateManifests/task.json b/Tasks/ServiceFabricUpdateManifests/task.json index 8179b58d1d0e..1738040bda30 100644 --- a/Tasks/ServiceFabricUpdateManifests/task.json +++ b/Tasks/ServiceFabricUpdateManifests/task.json @@ -85,15 +85,6 @@ "helpMarkDown": "The name of the artifact containing the application package for comparison.", "visibleRule": "updateType = Manifest versions && updateOnlyChanged = true" }, - { - "name": "pkgArtifactPath", - "type": "string", - "label": "Package Artifact Path", - "defaultValue": "$(build.artifactstagingdirectory)", - "required": true, - "visibleRule": "updateType = Manifest versions && updateOnlyChanged = true", - "helpMarkDown": "The path to the artifact containing the application package. [Variables](https://go.microsoft.com/fwlink/?LinkID=550988) and wildcards can be used in the path." - }, { "name": "logAllChanges", "type": "boolean", @@ -185,6 +176,6 @@ "NoChanges": "Found no changes.", "PdbWarning": "This package contains '*.pdb' files, which will change in every build even if the 'deterministic' compiler flag is used. Exclude these files from your package in order to accurately detect if the package has changed.", "InvalidImageDigestValue": "The image digest value '{0}' found in file '{1}' is invalid. Expected a value in the format of 'endpoint/image_name@digest_value'.", - "PackageIsNotUnderArtifact": "The package path '{0}' is not under artifact path '{1}'." + "CouldNotFindSubPath": "Could not find a subpath of '{0}' under artifact path '{1}'." } } \ No newline at end of file diff --git a/Tasks/ServiceFabricUpdateManifests/task.loc.json b/Tasks/ServiceFabricUpdateManifests/task.loc.json index 7ea9cc4c644a..50ae9b7fb615 100644 --- a/Tasks/ServiceFabricUpdateManifests/task.loc.json +++ b/Tasks/ServiceFabricUpdateManifests/task.loc.json @@ -85,15 +85,6 @@ "helpMarkDown": "ms-resource:loc.input.help.pkgArtifactName", "visibleRule": "updateType = Manifest versions && updateOnlyChanged = true" }, - { - "name": "pkgArtifactPath", - "type": "string", - "label": "ms-resource:loc.input.label.pkgArtifactPath", - "defaultValue": "$(build.artifactstagingdirectory)", - "required": true, - "visibleRule": "updateType = Manifest versions && updateOnlyChanged = true", - "helpMarkDown": "ms-resource:loc.input.help.pkgArtifactPath" - }, { "name": "logAllChanges", "type": "boolean", @@ -185,6 +176,6 @@ "NoChanges": "ms-resource:loc.messages.NoChanges", "PdbWarning": "ms-resource:loc.messages.PdbWarning", "InvalidImageDigestValue": "ms-resource:loc.messages.InvalidImageDigestValue", - "PackageIsNotUnderArtifact": "ms-resource:loc.messages.PackageIsNotUnderArtifact" + "CouldNotFindSubPath": "ms-resource:loc.messages.CouldNotFindSubPath" } } \ No newline at end of file From 9e27e9dc82b2ea054ec5cef5e9afa1ca0c26c053 Mon Sep 17 00:00:00 2001 From: Nathan Carlson Date: Tue, 6 Mar 2018 10:34:52 -0800 Subject: [PATCH 3/3] Added testing for a package built in a sub-path. --- Tasks/ServiceFabricUpdateManifests/Tests/L0.ts | 6 ++++++ .../Tests/Test-ApplicationVersions.ps1 | 15 ++++++++++++--- ...date-ApplicationVersions.NoChanges.SubPath.ps1 | 4 ++++ ...ApplicationVersions.ServiceChanged.SubPath.ps1 | 4 ++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 Tasks/ServiceFabricUpdateManifests/Tests/Update-ApplicationVersions.NoChanges.SubPath.ps1 create mode 100644 Tasks/ServiceFabricUpdateManifests/Tests/Update-ApplicationVersions.ServiceChanged.SubPath.ps1 diff --git a/Tasks/ServiceFabricUpdateManifests/Tests/L0.ts b/Tasks/ServiceFabricUpdateManifests/Tests/L0.ts index 873dd452644e..8585c1325108 100644 --- a/Tasks/ServiceFabricUpdateManifests/Tests/L0.ts +++ b/Tasks/ServiceFabricUpdateManifests/Tests/L0.ts @@ -33,9 +33,15 @@ describe('ServiceFabricUpdateManifests Suite', function () { it('(Update-ApplicationVersions) no changes', (done) => { psr.run(path.join(__dirname, 'Update-ApplicationVersions.NoChanges.ps1'), done); }) + it('(Update-ApplicationVersions) no changes (package in sub path)', (done) => { + psr.run(path.join(__dirname, 'Update-ApplicationVersions.NoChanges.SubPath.ps1'), done); + }) it('(Update-ApplicationVersions) service changed', (done) => { psr.run(path.join(__dirname, 'Update-ApplicationVersions.ServiceChanged.ps1'), done); }) + it('(Update-ApplicationVersions) service changed (package in sub path)', (done) => { + psr.run(path.join(__dirname, 'Update-ApplicationVersions.ServiceChanged.SubPath.ps1'), done); + }) it('(Update-ApplicationVersions) app manifest xml changed', (done) => { psr.run(path.join(__dirname, 'Update-ApplicationVersions.XmlChanged.ps1'), done); }) diff --git a/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 b/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 index 6b91089dce6d..2245c4a61b64 100644 --- a/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 +++ b/Tasks/ServiceFabricUpdateManifests/Tests/Test-ApplicationVersions.ps1 @@ -6,7 +6,10 @@ param( $PreviousPkgName, [switch] - $Service1Changed + $Service1Changed, + + [string] + $PackageSubPath = "" ) . $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 @@ -14,7 +17,9 @@ param( $taskPath = "$PSScriptRoot\.." Microsoft.PowerShell.Core\Import-Module "$taskPath\Test-XmlEqual.psm1" -$pkgPath = "$PSScriptRoot\pkg" +$pkgPath = "$PSScriptRoot\${PackageSubPath}pkg" +$oldDropLocation = "$PSScriptRoot\data\$PreviousPkgName" +$oldPkgPath = "$oldDropLocation\pkg" try { @@ -33,7 +38,7 @@ try Register-Mock Assert-VstsPath Register-Mock Assert-SingleItem - Register-Mock Get-VstsBuild { "$PSScriptRoot\data\$PreviousPkgName" } + Register-Mock Get-VstsBuild { $oldDropLocation } Register-Mock Get-VstsTaskVariable { $PSScriptRoot } -- -Name Build.SourcesDirectory -Require @@ -59,6 +64,10 @@ try Assert-AreEqual "1.0.0$newSuffix" $appManifest.ApplicationManifest.ApplicationTypeVersion "App type version did not match." Assert-AreEqual $expectedService1Version $appManifest.ApplicationManifest.ServiceManifestImport[0].ServiceManifestRef.ServiceManifestVersion "Service 1 version did not match." Assert-AreEqual "1.0.0$oldSuffix" $appManifest.ApplicationManifest.ServiceManifestImport[1].ServiceManifestRef.ServiceManifestVersion "Service 2 version did not match." + Assert-WasCalled Update-ServiceVersions -ParametersEvaluator { + return $NewPackageRoot -eq $pkgPath -and ` + ($PreviousPkgName -eq "PreviousPackageNoManifest") -or $OldPackageRoot -eq $oldPkgPath + } } finally { diff --git a/Tasks/ServiceFabricUpdateManifests/Tests/Update-ApplicationVersions.NoChanges.SubPath.ps1 b/Tasks/ServiceFabricUpdateManifests/Tests/Update-ApplicationVersions.NoChanges.SubPath.ps1 new file mode 100644 index 000000000000..1a09a1a62573 --- /dev/null +++ b/Tasks/ServiceFabricUpdateManifests/Tests/Update-ApplicationVersions.NoChanges.SubPath.ps1 @@ -0,0 +1,4 @@ +[CmdletBinding()] +param() + +. "$PSScriptRoot\Test-ApplicationVersions.ps1" PreviousPkg -PackageSubPath "Foo\Bar\" \ No newline at end of file diff --git a/Tasks/ServiceFabricUpdateManifests/Tests/Update-ApplicationVersions.ServiceChanged.SubPath.ps1 b/Tasks/ServiceFabricUpdateManifests/Tests/Update-ApplicationVersions.ServiceChanged.SubPath.ps1 new file mode 100644 index 000000000000..d281e8feb5d8 --- /dev/null +++ b/Tasks/ServiceFabricUpdateManifests/Tests/Update-ApplicationVersions.ServiceChanged.SubPath.ps1 @@ -0,0 +1,4 @@ +[CmdletBinding()] +param() + +. "$PSScriptRoot\Test-ApplicationVersions.ps1" PreviousPkg -Service1Changed -PackageSubPath "Foo\Bar\" \ No newline at end of file