@@ -20,24 +20,32 @@ function WriteLog
2020 Write-Host $Message
2121}
2222
23- function ValidateNugetListOutput
23+ Class PackageInfo {
24+ [string ]$Name
25+ [string ]$Version
26+ }
27+
28+ function NewPackageInfo
2429{
2530 param (
2631 [Parameter (Mandatory = $true )]
2732 [ValidateNotNullOrEmpty ()]
2833 [System.String ]
29- $Output ,
30-
31- [Parameter (Mandatory = $true )]
32- [ValidateNotNullOrEmpty ()]
33- [System.String ]
34- $Command
34+ $PackageInformation
3535 )
3636
37- if ($Output -like " *No packages found*" )
37+ $parts = $PackageInformation.Split (" " )
38+
39+ if ($parts.Count -gt 2 )
3840 {
39- WriteLog " Failed to get the latest package information via: $Command " - Throw
41+ WriteLog " Invalid package format. The string should only contain 'name<space>version'. Current value: ' $PackageInformation ' "
4042 }
43+
44+ $packageInfo = [PackageInfo ]::New()
45+ $packageInfo.Name = $parts [0 ]
46+ $packageInfo.Version = $parts [1 ]
47+
48+ return $packageInfo
4149}
4250
4351function GetPackageInfo
@@ -54,38 +62,32 @@ function GetPackageInfo
5462 )
5563
5664 $result = $null
65+ $includeAllVersion = if (-not [string ]::IsNullOrWhiteSpace($MajorVersion )) { " -AllVersions" } else { " " }
5766
58- if (-not [string ]::IsNullOrWhiteSpace($MajorVersion ))
59- {
60- $packageInfo = & { NuGet list $Name - Source $SOURCE - PreRelease - AllVersions }
67+ $packageInfo = & { NuGet list $Name - Source $SOURCE - PreRelease $includeAllVersion }
6168
62- $command = " NuGet list $Name -Source $SOURCE -PreRelease -AllVersions"
63- ValidateNugetListOutput - Output ($packageInfo | Out-String ) - Command $command
69+ if ($packageInfo -like " *No packages found*" )
70+ {
71+ WriteLog " Package name $Name not found in $SOURCE ." - Throw
72+ }
6473
65- foreach ($package in $packageInfo )
74+ if (-not $MajorVersion )
75+ {
76+ $result = NewPackageInfo - PackageInformation $packageInfo
77+ }
78+ else
79+ {
80+ foreach ($thisPackage in $packageInfo.Split ([System.Environment ]::NewLine))
6681 {
67- $packageVersion = $package.Split ()[1 ]
68- if ($packageVersion.StartsWith ($MajorVersion ))
82+ $package = NewPackageInfo - PackageInformation $thisPackage
83+
84+ if ($package.Version.StartsWith ($MajorVersion ))
6985 {
7086 $result = $package
7187 break
7288 }
7389 }
7490 }
75- else
76- {
77- $packageInfo = & { NuGet list $Name - Source $SOURCE - PreRelease }
78-
79- $command = " NuGet list $Name -Source $SOURCE -PreRelease"
80- ValidateNugetListOutput - Output ($packageInfo | Out-String ) - Command $command
81-
82- $result = $packageInfo
83- }
84-
85- if (-not $result )
86- {
87- WriteLog " Failed to get the latest package information for '$Name '" - Throw
88- }
8991
9092 return $result
9193}
@@ -99,7 +101,7 @@ if (-not (Test-Path $path))
99101 WriteLog " Failed to find '$path ' to update package references" - Throw
100102}
101103
102- $URL = " https://raw.githubusercontent.com/Azure/azure-functions-integration-tests/dev /integrationTestsBuild/V3/HostBuild2 .json"
104+ $URL = " https://raw.githubusercontent.com/Azure/azure-functions-integration-tests/main /integrationTestsBuild/V3/HostBuild .json"
103105$SOURCE = " https://azfunc.pkgs.visualstudio.com/e6a70c92-4128-439f-8012-382fe78d6396/_packaging/AzureFunctionsPreRelease/nuget/v3/index.json"
104106
105107WriteLog " Get the list of packages to update"
120122
121123 foreach ($package in $packagesToUpdate )
122124 {
123- WriteLog " Package name: $ ( $package.Name ) "
124-
125125 $packageInfo = GetPackageInfo - Name $package.Name - MajorVersion $package.MajorVersion
126126
127- WriteLog " AzureFunctionsPreRelease latest package info --> $packageInfo "
128- $packageName = $packageInfo.Split ()[0 ]
129- $packageVersion = $packageInfo.Split ()[1 ]
130-
131- if ($package -eq " Microsoft.Azure.Functions.PythonWorker" )
127+ if ($package.Name -eq " Microsoft.Azure.Functions.PythonWorker" )
132128 {
133129 # The PythonWorker is not defined in the src/WebJobs.Script/WebJobs.Script.csproj. It is defined in build/python.props.
134130 # To update the package version, the xml file build/python.props needs to be updated directly.
@@ -139,13 +135,13 @@ try
139135 WriteLog " Python Props file '$pythonPropsFilePath ' does not exist." - Throw
140136 }
141137
142- WriteLog " Set Python package version in '$pythonPropsFilePath ' to '$packageVersion '"
138+ WriteLog " Set Python package version in '$pythonPropsFilePath ' to '$ ( $packageInfo .Version ) '"
143139
144140 # Read the xml file
145141 [xml ]$xml = Get-Content $pythonPropsFilePath - Raw - ErrorAction Stop
146142
147143 # Replace the package version
148- $xml.Project.ItemGroup.PackageReference.Version = $packageVersion
144+ $xml.Project.ItemGroup.PackageReference.Version = $packageInfo .Version
149145
150146 # Save the file
151147 $xml.Save ($pythonPropsFilePath )
@@ -157,12 +153,12 @@ try
157153 }
158154 else
159155 {
160- WriteLog " Adding '$packageName ' '$packageVersion ' to project"
161- & { dotnet add package $packageName - v $packageVersion - s $source -- no- restore }
156+ WriteLog " Adding '$ ( $packageInfo .Name ) ' '$ ( $packageInfo .Version ) ' to project"
157+ & { dotnet add package $packageInfo .Name - v $packageInfo .Version - s $SOURCE -- no- restore }
162158
163159 if ($LASTEXITCODE -ne 0 )
164160 {
165- WriteLog " dotnet add package $packageName -v $packageVersion -s $source --no-restore failed" - Throw
161+ WriteLog " dotnet add package ' $ ( $packageInfo .Name ) ' -v ' $ ( $packageInfo .Version ) ' -s $SOURCE --no-restore failed" - Throw
166162 }
167163 }
168164 }
0 commit comments