diff --git a/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson b/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson index c4826b1196ba..5ad3a6851200 100644 --- a/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/ServiceFabricUpdateManifests/Strings/resources.resjson/en-US/resources.resjson @@ -59,5 +59,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.CouldNotFindSubPath": "Could not find a subpath of '{0}' under artifact path '{1}'." } \ No newline at end of file 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 diff --git a/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 b/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 index a00a919d0744..ac9f45f48e7a 100644 --- a/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 +++ b/Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1 @@ -57,20 +57,45 @@ Write-Host (Get-VstsLocString -Key SearchingApplicationType -ArgumentList $appTypeName) - $oldAppPackagePath = Join-Path $oldDropLocation $newAppPackagePath.SubString((Get-VstsTaskVariable -Name Build.SourcesDirectory -Require).Length + 1) - $oldAppManifestPath = Join-Path $oldAppPackagePath $appManifestName - if (Test-Path $oldAppManifestPath) + # 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)) { - $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 + $relativePath = $relativePath.SubString($pathRoot.Length) + } + $relativePath.Trim([System.IO.Path]::DirectorySeparatorChar) + $oldAppPackagePath = Join-Path $oldDropLocation $relativePath + while(!(Test-Path $oldAppPackagePath)) + { + $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 @@ -85,7 +110,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..1738040bda30 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))", @@ -175,6 +175,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'.", + "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 2e3405700201..50ae9b7fb615 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", @@ -175,6 +175,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", + "CouldNotFindSubPath": "ms-resource:loc.messages.CouldNotFindSubPath" } } \ No newline at end of file