6
6
7
7
Validates the workers match the existing host version and throws an error if they don't
8
8
. EXAMPLE
9
- ./validateWorkerVersions.ps1 -Update -HostVersion 4.0 .0
9
+ ./validateWorkerVersions.ps1 -Update -HostVersion 4.1037 .0
10
10
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
12
12
#>
13
13
param (
14
14
[Switch ]$Update ,
15
15
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
17
17
[string ]$hostVersion
18
18
)
19
19
20
20
# the xml will fail to parse if the data is encoded with a bom character
21
21
function removeBomIfExists ([string ]$data )
22
22
{
23
23
if ($data.StartsWith (0xFEFF )) {
24
- $data = $data.substring (1 )
24
+ $data = $data.Substring (1 )
25
25
}
26
26
return $data
27
27
}
28
28
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
31
33
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 )
37
35
{
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"
41
47
}
42
- return $version
43
48
}
44
49
45
- function setCliPackageVersion ([string ]$packageName , [string ]$newVersion )
50
+ function setPackageVersionInProps ([string ]$packageName , [string ]$newVersion )
46
51
{
47
- $node = $cliCsprojXml .SelectSingleNode ( " /Project//PackageReference [@Include='$packageName ']" )
52
+ $node = Select-Xml - Xml $packagesPropsXml - XPath " /Project/ItemGroup/PackageVersion [@Include='$packageName ']" | Select-Object - ExpandProperty Node
48
53
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 "
50
55
}
51
56
$oldVersion = $node.Version
52
57
$node.Version = $newVersion
@@ -55,48 +60,64 @@ function setCliPackageVersion([string]$packageName, [string]$newVersion)
55
60
56
61
$hostPackageName = " Microsoft.Azure.WebJobs.Script.WebHost"
57
62
if (-Not $hostVersion ) {
58
- $hostVersion = getPackageVersion $hostPackageName $cliCsprojContent
63
+ $hostVersion = getPackageVersion $hostPackageName $packagesPropsXml
59
64
} elseif ($Update ) {
60
- setCliPackageVersion $hostPackageName $hostVersion
65
+ setPackageVersionInProps $hostPackageName $hostVersion
61
66
}
62
67
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"
66
72
}
67
73
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 "
73
75
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
+ }
75
81
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
76
90
77
- # Iterate through each key-value pair
91
+ # Iterate through each worker and validate versions
78
92
foreach ($key in $workerPropsToWorkerName.Keys ) {
79
- $workerPropsContent = getWorkerPropsFile $key
93
+ Write-Output " ----------------------------------------------"
94
+ $workerPropsContent = getWorkerPropsFileFromHost $key
80
95
# Get the list associated with the key
81
96
$workerList = $workerPropsToWorkerName [$key ]
82
97
83
- # Iterate through the list
84
98
foreach ($worker in $workerList ) {
99
+ Write-Output " Validating $worker version..."
85
100
$packageName = " Microsoft.Azure.Functions.$worker "
86
- $hostWorkerVersion = getPackageVersion $packageName $workerPropsContent
87
- $cliWorkerVersion = getPackageVersion $packageName $workerPropsContent
88
101
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
91
110
} 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 )"
93
112
$failedValidation = $true
94
113
}
95
114
}
96
115
}
116
+ Write-Output " ----------------------------------------------"
97
117
118
+ # Save updated versions if necessary
98
119
if ($Update ) {
99
- $cliCsprojXml .Save ($cliCsprojPath )
120
+ $packagesPropsXml .Save ($packagesPropsPath )
100
121
Write-Output " Updated worker versions! 🚀"
101
122
} elseif ($failedValidation ) {
102
123
Write-Output " You can run './validateWorkerVersions.ps1 -Update' locally to fix worker versions."
0 commit comments