forked from OData/AspNetCoreOData
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate ODL Version in csproj against builder.versions.settings.targ…
…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
1 parent
df9c340
commit 275985b
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters