Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support artifacts published from any location #6268

Merged
merged 3 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}'."
}
6 changes: 6 additions & 0 deletions Tasks/ServiceFabricUpdateManifests/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ param(
$PreviousPkgName,

[switch]
$Service1Changed
$Service1Changed,

[string]
$PackageSubPath = ""
)

. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1

$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
{
Expand All @@ -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

Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[CmdletBinding()]
param()

. "$PSScriptRoot\Test-ApplicationVersions.ps1" PreviousPkg -PackageSubPath "Foo\Bar\"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[CmdletBinding()]
param()

. "$PSScriptRoot\Test-ApplicationVersions.ps1" PreviousPkg -Service1Changed -PackageSubPath "Foo\Bar\"
49 changes: 37 additions & 12 deletions Tasks/ServiceFabricUpdateManifests/Update-ApplicationVersions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we start with Build.SourcesDirectory directory rather than root?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally this would actually be under Build.StagingDirectory, but there is no guarantee of that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

$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))
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to have UTs for this non-trivial logic

$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
Expand All @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions Tasks/ServiceFabricUpdateManifests/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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))",
Expand Down Expand Up @@ -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}'."
}
}
7 changes: 4 additions & 3 deletions Tasks/ServiceFabricUpdateManifests/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
],
"version": {
"Major": 2,
"Minor": 1,
"Patch": 10
"Minor": 2,
"Patch": 0
},
"minimumAgentVersion": "1.95.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -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"
}
}