Skip to content

Commit

Permalink
Validate ODL Version in csproj against builder.versions.settings.targ…
Browse files Browse the repository at this point in the history
…ets and update ODataLibPackageDependency to 8.2.3 (OData#1389)

* Add a step to pipeline to validate Validate OData Package Versions

* Update ODataLibPackageDependency version to [8.2.3, 9.0.0)

* Bump version to 9.1.3
  • Loading branch information
WanjohiSammy authored Jan 15, 2025
1 parent df9c340 commit 275985b
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pipelines/azure_pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ extends:
inputs:
version: 8.x
includePreviewVersions: true
- task: PowerShell@2
displayName: Validate OData Package Versions
inputs:
targetType: 'inline'
script: 'powershell.exe -executionpolicy remotesigned -File $(Build.SourcesDirectory)\tool\ValidateODataPackageVersions.ps1'
- task: DotNetCoreCLI@2
displayName: build Microsoft.AspNetCore.OData
inputs:
Expand Down
97 changes: 97 additions & 0 deletions tool/ValidateODataPackageVersions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<#
.SYNOPSIS
Validates the package versions in the .csproj file against the lower bound of the ODataLibPackageDependency version range in the builder.versions.settings.targets.
.PARAMETER builderVersionTargetsPath
Specifies the path to the builder.versions.settings.targets file.
.PARAMETER csprojPath
Specifies the path to the .csproj file.
#>

Param(
[string]
$builderVersionTargetsPath,
[string]
$csprojPath
)

# Constants
$ODATA_LIB_PACKAGE_DEPENDENCY_KEY = "ODataLibPackageDependency"
$ODATA_MODEL_BUILDER_PACKAGE_DEPENDENCY_KEY = "ODataModelBuilderPackageDependency"
$BUILDER_VERSION_TARGETS_FILENAME = "builder.versions.settings.targets"
$CSPROJ_FILENAME = "Microsoft.AspNetCore.OData.csproj"

# Path to your builder.versions.settings.targets file
if ($builderVersionTargetsPath -eq "") {
$builderVersionTargetsPath = "$PSScriptRoot\$BUILDER_VERSION_TARGETS_FILENAME"
}

# Path to your .csproj file
if ($csprojPath -eq "") {
$csprojPath = Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath "src/Microsoft.AspNetCore.OData/$CSPROJ_FILENAME"
}

# Function to extract the OData package dependency version range from the targets file
function Get-ODataPackageDependencyVersion {
param (
[xml]$targets,
[string]$dependencyName
)
$dependencyVersionRange = [string]$targets.Project.PropertyGroup.$dependencyName
$dependencyVersionRange = $dependencyVersionRange.Trim()
$dependencyVersionRange = $dependencyVersionRange -replace "\s", ""

# Extract the lower bound version from the version range
$lowerBoundVersion = $dependencyVersionRange -replace "\[([^\]]+),.*", '$1'
return $lowerBoundVersion
}

# Dictionary to store the OData package dependencies
$odataPackageDependenciesDict = [System.Collections.Generic.Dictionary[String,String]]::new()

# Load the targets file
[xml]$targets = Get-Content $builderVersionTargetsPath

# Extract the ODataLibPackageDependency version range
$lowerBoundVersion = Get-ODataPackageDependencyVersion -targets $targets -dependencyName $ODATA_LIB_PACKAGE_DEPENDENCY_KEY
$odataPackageDependenciesDict.Add($ODATA_LIB_PACKAGE_DEPENDENCY_KEY, $lowerBoundVersion)

# Extract the ODataModelBuilderPackageDependency version range
$lowerBoundVersion = Get-ODataPackageDependencyVersion -targets $targets -dependencyName $ODATA_MODEL_BUILDER_PACKAGE_DEPENDENCY_KEY
$odataPackageDependenciesDict.Add($ODATA_MODEL_BUILDER_PACKAGE_DEPENDENCY_KEY, $lowerBoundVersion)

# Extract the lower bound version from the version range
$lowerBoundVersion = $odataPackageDependenciesDict[$ODATA_LIB_PACKAGE_DEPENDENCY_KEY]

# Load the .csproj file
[xml]$csproj = Get-Content $csprojPath

# Extract the PackageReference versions
$PackageReference = $csproj.Project.ItemGroup.PackageReference

# Dictionary to store the PackageReferences
$csprojPackageReferencesDict = @{
$ODATA_LIB_PACKAGE_DEPENDENCY_KEY = "Microsoft.OData.Core|Microsoft.OData.Client|Microsoft.OData.Edm|Microsoft.Spatial"
$ODATA_MODEL_BUILDER_PACKAGE_DEPENDENCY_KEY = "Microsoft.OData.ModelBuilder"
}


foreach ($key in $odataPackageDependenciesDict.Keys) {
$lowerBoundVersion = $odataPackageDependenciesDict[$key]
$packageReferences = $PackageReference | Where-Object { $_.Include -match $csprojPackageReferencesDict[$key] }
$packageVersions = $packageReferences.Version

Write-Host "Validating the package versions of '$key' in '$CSPROJ_FILENAME' against the lower bound of the '$key' version range in '$BUILDER_VERSION_TARGETS_FILENAME'."

# Validate the versions
foreach ($version in $packageVersions) {
if ($version -ne $lowerBoundVersion) {
$exception = New-Object System.Exception(
"Error.VersionMismatch: '$key' version '$version' in '$csprojPath' do not match the lower bound '$lowerBoundVersion' of '$key' in '$builderVersionTargetsPath'.")
throw $exception
}
}

Write-Host "Validation successful: Package versions match the lower bound of the $key version range."
}
4 changes: 2 additions & 2 deletions tool/builder.versions.settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<PropertyGroup>
<VersionMajor Condition="'$(VersionMajor)' == ''">9</VersionMajor>
<VersionMinor Condition="'$(VersionMinor)' == ''">1</VersionMinor>
<VersionBuild Condition="'$(VersionBuild)' == ''">2</VersionBuild>
<VersionBuild Condition="'$(VersionBuild)' == ''">3</VersionBuild>
<VersionRelease Condition="'$(VersionRelease)' == ''"></VersionRelease>
</PropertyGroup>

<!-- For NuGet Package Dependencies -->
<PropertyGroup>
<ODataLibPackageDependency>[8.2.2, 9.0.0)</ODataLibPackageDependency>
<ODataLibPackageDependency>[8.2.3, 9.0.0)</ODataLibPackageDependency>
<ODataModelBuilderPackageDependency>[2.0.0, 3.0.0)</ODataModelBuilderPackageDependency>
</PropertyGroup>

Expand Down

0 comments on commit 275985b

Please sign in to comment.