Skip to content

Commit 29b4b03

Browse files
committed
Fix validate worker script
1 parent bbf7317 commit 29b4b03

File tree

1 file changed

+59
-38
lines changed

1 file changed

+59
-38
lines changed

eng/scripts/validateWorkerVersions.ps1

+59-38
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,52 @@
66
77
Validates the workers match the existing host version and throws an error if they don't
88
.EXAMPLE
9-
./validateWorkerVersions.ps1 -Update -HostVersion 4.0.0
9+
./validateWorkerVersions.ps1 -Update -HostVersion 4.1037.0
1010
11-
Updates the host reference to 4.0.0 and the workers to their matching versions
11+
Updates the host reference to 4.1037.0 and the workers to their matching versions
1212
#>
1313
param (
1414
[Switch]$Update,
1515

16-
# An explicit host version, otherwise the host version from Azure.Functions.Cli.csproj will be used
16+
# An explicit host version, otherwise the host version from Directory.Packages.props will be used
1717
[string]$hostVersion
1818
)
1919

2020
# the xml will fail to parse if the data is encoded with a bom character
2121
function removeBomIfExists([string]$data)
2222
{
2323
if ($data.StartsWith(0xFEFF)) {
24-
$data = $data.substring(1)
24+
$data = $data.Substring(1)
2525
}
2626
return $data
2727
}
2828

29-
$rootDir = Join-Path $PSScriptRoot "../.." # Path to the root of the repository
30-
$rootDir = Resolve-Path $rootDir
29+
$rootDir = Join-Path $PSScriptRoot "../.." | Resolve-Path
30+
$packagesPropsPath = "$rootDir/eng/Directory.Packages.props"
31+
$packagesPropsContent = removeBomIfExists(Get-Content $packagesPropsPath)
32+
$packagesPropsXml = [xml]$packagesPropsContent
3133

32-
$cliCsprojPath = "$rootDir/src/Cli/func/Azure.Functions.Cli.csproj"
33-
$cliCsprojContent = removeBomIfExists(Get-Content $cliCsprojPath)
34-
$cliCsprojXml = [xml]$cliCsprojContent
35-
36-
function getPackageVersion([string]$packageName, [string]$csprojContent)
34+
function getPackageVersion([string]$packageName, [xml]$propsXml, [bool]$isPackageReference = $false)
3735
{
38-
$version = (Select-Xml -Content $csprojContent -XPath "/Project//PackageReference[@Include='$packageName']/@Version").ToString()
39-
if (-Not $version) {
40-
throw "Failed to find version for package $packageName"
36+
if ($isPackageReference) {
37+
$xpath = "/Project/ItemGroup/PackageReference[@Include='$packageName']"
38+
} else {
39+
$xpath = "/Project/ItemGroup/PackageVersion[@Include='$packageName']"
40+
}
41+
42+
$node = Select-Xml -Xml $propsXml -XPath $xpath | Select-Object -ExpandProperty Node
43+
if ($node) {
44+
return $node.Version
45+
} else {
46+
throw "Failed to find version for package $packageName in Directory.Packages.props"
4147
}
42-
return $version
4348
}
4449

45-
function setCliPackageVersion([string]$packageName, [string]$newVersion)
50+
function setPackageVersionInProps([string]$packageName, [string]$newVersion)
4651
{
47-
$node = $cliCsprojXml.SelectSingleNode("/Project//PackageReference[@Include='$packageName']")
52+
$node = Select-Xml -Xml $packagesPropsXml -XPath "/Project/ItemGroup/PackageVersion[@Include='$packageName']" | Select-Object -ExpandProperty Node
4853
if (-Not $node) {
49-
throw "Failed to find reference for package $packageName"
54+
throw "Failed to find reference for package $packageName in Directory.Packages.props"
5055
}
5156
$oldVersion = $node.Version
5257
$node.Version = $newVersion
@@ -55,48 +60,64 @@ function setCliPackageVersion([string]$packageName, [string]$newVersion)
5560

5661
$hostPackageName = "Microsoft.Azure.WebJobs.Script.WebHost"
5762
if (-Not $hostVersion) {
58-
$hostVersion = getPackageVersion $hostPackageName $cliCsprojContent
63+
$hostVersion = getPackageVersion $hostPackageName $packagesPropsXml
5964
} elseif ($Update) {
60-
setCliPackageVersion $hostPackageName $hostVersion
65+
setPackageVersionInProps $hostPackageName $hostVersion
6166
}
6267

63-
function getWorkerPropsFile([string]$filePath) {
64-
$uri = "https://raw.githubusercontent.com/Azure/azure-functions-host/v$hostVersion/$filePath"
65-
return removeBomIfExists((Invoke-WebRequest -Uri $uri).Content)
68+
$tagUri = "https://api.github.com/repos/Azure/azure-functions-host/git/refs/tags/v$hostVersion"
69+
$result = Invoke-WebRequest -Uri $tagUri
70+
if ($result.StatusCode -ne 200) {
71+
throw "Host tag version $hostVersion does not exist, check that the host version provide is a real tag in the Host repo. Note: new host versions may take a different format such as 4.1038.100"
6672
}
6773

68-
$workerPropstoWorkerName = @{}
69-
$workerPropsToWorkerName["eng/build/Workers.Node.props"] = @("NodeJsWorker")
70-
$workerPropsToWorkerName["eng/build/Workers.Java.props"] = @("JavaWorker")
71-
$workerPropsToWorkerName["eng/build/Workers.Python.props"] = @("PythonWorker")
72-
$workerPropsToWorkerName["eng/build/Workers.Powershell.props"] = @("PowerShellWorker.PS7.0", "PowerShellWorker.PS7.2", "PowerShellWorker.PS7.4")
74+
Write-Output "Host version: $hostVersion"
7375

74-
$failedValidation = $false
76+
function getWorkerPropsFileFromHost([string]$filePath) {
77+
$uri = "https://raw.githubusercontent.com/Azure/azure-functions-host/refs/tags/v$hostVersion/$filePath"
78+
$content = removeBomIfExists((Invoke-WebRequest -Uri $uri).Content)
79+
return [xml]$content
80+
}
7581

82+
$workerPropsToWorkerName = @{
83+
"eng/build/Workers.Node.props" = @("NodeJsWorker")
84+
"eng/build/Workers.Java.props" = @("JavaWorker")
85+
"eng/build/Workers.Python.props" = @("PythonWorker")
86+
"eng/build/Workers.Powershell.props" = @("PowerShellWorker.PS7.0", "PowerShellWorker.PS7.2", "PowerShellWorker.PS7.4")
87+
}
88+
89+
$failedValidation = $false
7690

77-
# Iterate through each key-value pair
91+
# Iterate through each worker and validate versions
7892
foreach ($key in $workerPropsToWorkerName.Keys) {
79-
$workerPropsContent = getWorkerPropsFile $key
93+
Write-Output "----------------------------------------------"
94+
$workerPropsContent = getWorkerPropsFileFromHost $key
8095
# Get the list associated with the key
8196
$workerList = $workerPropsToWorkerName[$key]
8297

83-
# Iterate through the list
8498
foreach ($worker in $workerList) {
99+
Write-Output "Validating $worker version..."
85100
$packageName = "Microsoft.Azure.Functions.$worker"
86-
$hostWorkerVersion = getPackageVersion $packageName $workerPropsContent
87-
$cliWorkerVersion = getPackageVersion $packageName $workerPropsContent
88101

89-
if ($Update) {
90-
setCliPackageVersion $packageName $hostWorkerVersion
102+
# Get versions from the host and our repo (from Directory.Packages.props)
103+
$hostWorkerVersion = getPackageVersion $packageName $workerPropsContent $true
104+
$cliWorkerVersion = getPackageVersion $packageName $packagesPropsXml
105+
106+
Write-Output "CLI version: $cliWorkerVersion | Host version: $hostWorkerVersion"
107+
108+
if ($Update -AND $hostWorkerVersion -ne $cliWorkerVersion) {
109+
setPackageVersionInProps $packageName $hostWorkerVersion
91110
} elseif ($hostWorkerVersion -ne $cliWorkerVersion) {
92-
Write-Output "Reference to $worker in the host ($hostWorkerVersion) does not match version in the cli ($cliWorkerVersion)"
111+
Write-Output "Reference to $worker in the host ($hostWorkerVersion) does not match version in the CLI ($cliWorkerVersion)"
93112
$failedValidation = $true
94113
}
95114
}
96115
}
116+
Write-Output "----------------------------------------------"
97117

118+
# Save updated versions if necessary
98119
if ($Update) {
99-
$cliCsprojXml.Save($cliCsprojPath)
120+
$packagesPropsXml.Save($packagesPropsPath)
100121
Write-Output "Updated worker versions! 🚀"
101122
} elseif ($failedValidation) {
102123
Write-Output "You can run './validateWorkerVersions.ps1 -Update' locally to fix worker versions."

0 commit comments

Comments
 (0)