Skip to content

Commit 0a5ff58

Browse files
POM file version scanner updates and fixes (#43243)
* POM file version scanner updates and fixes * Update to azure-sdk-parent gets scanned as well as signature nodes * Update eng/versioning/pom_file_version_scanner.ps1 Co-authored-by: Bill Wert <[email protected]> * Update eng/versioning/pom_file_version_scanner.ps1 Co-authored-by: Bill Wert <[email protected]> --------- Co-authored-by: Bill Wert <[email protected]>
1 parent a41c6d9 commit 0a5ff58

File tree

1 file changed

+107
-23
lines changed

1 file changed

+107
-23
lines changed

eng/versioning/pom_file_version_scanner.ps1

Lines changed: 107 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ param()
3434

3535
# Since we're skipping Management for the moment, only look for files with certain parents. These
3636
# limitations will vanish once Management track is updated.
37-
$ValidParents = ("azure-sdk-parent", "azure-client-sdk-parent", "azure-data-sdk-parent", "azure-perf-test-parent", "azure-cosmos-parent")
37+
$ValidParents = ("azure-sdk-parent", "azure-client-sdk-parent", "azure-data-sdk-parent", "azure-perf-test-parent", "azure-cosmos-spark_3_2-12")
3838

3939
# SpringSampleParents is necessary for the spring samples which have to build using the spring-boot-starter-parent BOM.
4040
# The problem with this is, it's a BOM file and the spring dependencies are pulled in through that which means any
@@ -48,7 +48,7 @@ $SamplesPath = Resolve-Path ($PSScriptRoot + "/../../samples")
4848
$SdkRoot = Resolve-Path ($PSScriptRoot + "/../../sdk")
4949

5050
# Not all POM files have a parent entry
51-
$PomFilesIgnoreParent = ("$($Path)\parent\pom.xml")
51+
# $PomFilesIgnoreParent = ("$($Path)\parent\pom.xml")
5252
$script:FoundError = $false
5353
$DependencyTypeCurrent = "current"
5454
$DependencyTypeDependency = "dependency"
@@ -252,6 +252,13 @@ function Build-Dependency-Hash-From-File {
252252
{
253253
try {
254254
[Dependency]$dep = [Dependency]::new($line)
255+
# This is the case where there is no current version but dependency isn't
256+
# "unreleased_" or "beta_" meaning that the line is either incorrect or
257+
# has an invalid format
258+
if (-not $dep.curVer -and (-not $dep.Id.StartsWith("unreleased_")) -and (-not $dep.Id.StartsWith("beta_"))) {
259+
Write-Error-With-Color "Invalid dependency line='$($line) in file=$($depFile) has no current version and is not unreleased_ or beta_.`nPlease ensure the format is <groupId>:<artifactId>;<dependencyVer>;<currentVer> and the seperators are semicolons (;)"
260+
$script:FoundError = $true
261+
}
255262
if ($depHash.ContainsKey($dep.id))
256263
{
257264
Write-Error-With-Color "Error: Duplicate dependency encountered. '$($dep.id)' defined in '$($depFile)' already exists in the dependency list which means it is defined in multiple version_*.txt files."
@@ -262,6 +269,7 @@ function Build-Dependency-Hash-From-File {
262269
}
263270
catch {
264271
Write-Error-With-Color "Invalid dependency line='$($line) in file=$($depFile)"
272+
$script:FoundError = $true
265273
}
266274
}
267275
else
@@ -278,6 +286,7 @@ function Build-Dependency-Hash-From-File {
278286
}
279287
catch {
280288
Write-Error-With-Color "Invalid external dependency line='$($line) in file=$($depFile)"
289+
$script:FoundError = $true
281290
}
282291
}
283292
}
@@ -510,13 +519,35 @@ $ArtifactsPerSD = [ordered]@{};
510519
Get-ArtifactsList-Per-Service-Directory $ArtifactsPerSD
511520

512521
# Create one dependency hashtable for libraries we build (the groupIds will make the entries unique) and
513-
# one hash for external dependencies
522+
# one hash for external dependencies. If there are errors building the dependency hash, output those and
523+
# exit. There's no point in scanning the pom files if any of the files have invalid or duplicate entries.
514524
$libHash = @{}
515-
Build-Dependency-Hash-From-File $libHash $Path\eng\versioning\version_client.txt $false
516-
Build-Dependency-Hash-From-File $libHash $Path\eng\versioning\version_data.txt $false
525+
$verClientFile = Join-Path $Path "eng/versioning/version_client.txt"
526+
Build-Dependency-Hash-From-File $libHash $verClientFile $false
527+
if ($script:FoundError)
528+
{
529+
Write-Error-With-Color "There were errors encountered building the dependency hash from version_client.txt. Please fix errors and run the script again."
530+
Write-Error-With-Color "This script can be run locally from the root of the repo. .\eng\versioning\pom_file_version_scanner.ps1"
531+
exit 1
532+
}
533+
$verDataFile = Join-Path $Path "eng/versioning/version_data.txt"
534+
Build-Dependency-Hash-From-File $libHash $verDataFile $false
535+
if ($script:FoundError)
536+
{
537+
Write-Error-With-Color "There were errors encountered building the dependency hash from version_data.txt. Please fix errors and run the script again."
538+
Write-Error-With-Color "This script can be run locally from the root of the repo. .\eng\versioning\pom_file_version_scanner.ps1"
539+
exit 1
540+
}
517541

518542
$extDepHash = @{}
519-
Build-Dependency-Hash-From-File $extDepHash $Path\eng\versioning\external_dependencies.txt $true
543+
$extDepFile = Join-Path $Path "eng/versioning/external_dependencies.txt"
544+
Build-Dependency-Hash-From-File $extDepHash $extDepFile $true
545+
if ($script:FoundError)
546+
{
547+
Write-Error-With-Color "There were errors encountered building the external dependency has from external_dependencies.txt. Please fix errors and run the script again."
548+
Write-Error-With-Color "This script can be run locally from the root of the repo. .\eng\versioning\pom_file_version_scanner.ps1"
549+
exit 1
550+
}
520551

521552
# Loop through every client and data POM file and perform the verification. Right now
522553
# management isn't being processed, when it is the checks below will go away and every
@@ -558,25 +589,18 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
558589
return
559590
}
560591

561-
if ($PomFilesIgnoreParent -contains $pomFile)
592+
$xmlPomFile = New-Object xml
593+
$xmlPomFile.Load($pomFile)
594+
if ($ValidParents -notcontains $xmlPomFile.project.parent.artifactId -and $ValidParents -notcontains $xmlPomFile.project.artifactId)
562595
{
563-
$xmlPomFile = New-Object xml
564-
$xmlPomFile.Load($pomFile)
565-
566-
} else {
567-
$xmlPomFile = New-Object xml
568-
$xmlPomFile.Load($pomFile)
569-
if ($ValidParents -notcontains $xmlPomFile.project.parent.artifactId)
596+
if ($SpringSampleParents -contains $xmlPomFile.project.parent.artifactId)
570597
{
571-
if ($SpringSampleParents -contains $xmlPomFile.project.parent.artifactId)
572-
{
573-
Assert-Spring-Sample-Version-Tags $libHash $extDepHash $xmlPomFile
574-
}
575-
# This may look odd but ForEach-Object is a cmdlet which means that "continue"
576-
# exits the loop altogether and "return" behaves like continue for a particular
577-
# loop
578-
return
598+
Assert-Spring-Sample-Version-Tags $libHash $extDepHash $xmlPomFile
579599
}
600+
# This may look odd but ForEach-Object is a cmdlet which means that "continue"
601+
# exits the loop altogether and "return" behaves like continue for a particular
602+
# loop
603+
return
580604
}
581605

582606
$hasError = $false
@@ -794,6 +818,64 @@ Get-ChildItem -Path $Path -Filter pom*.xml -Recurse -File | ForEach-Object {
794818
}
795819
}
796820

821+
foreach($signatureNode in $xmlPomFile.GetElementsByTagName("signature"))
822+
{
823+
$artifactId = $signatureNode.artifactId
824+
$groupId = $signatureNode.groupId
825+
# If the artifactId and groupId are both empty then check to see if this
826+
# is part of a configuration entry.
827+
if (!$artifactId -and !$groupId)
828+
{
829+
$isPartOfConfig = Confirm-Node-Is-Part-Of-Configuration $signatureNode
830+
if (!$isPartOfConfig)
831+
{
832+
$hasError = $true
833+
# Because this particular case is harder to track down, print the OuterXML which is effectively the entire tag
834+
$potentialLogMessage = Join-With-NewLine $potentialLogMessage "Error: signature is missing version element and/or artifactId and groupId elements signatureNode=$($signatureNode.OuterXml)"
835+
}
836+
continue
837+
}
838+
# signatures should always have an artifact but may not have a groupId
839+
if (!$groupId)
840+
{
841+
$hasError = $true
842+
$potentialLogMessage = Join-With-NewLine $potentialLogMessage "Error: signature $($artifactId) is missing its groupId tag"
843+
continue
844+
}
845+
$versionNode = $signatureNode.GetElementsByTagName("version")[0]
846+
if (!$versionNode)
847+
{
848+
$hasError = $true
849+
$potentialLogMessage = Join-With-NewLine $potentialLogMessage "Error: signature is missing version element for groupId=$($groupId), artifactId=$($artifactId) should be <version></version> <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
850+
continue
851+
}
852+
if ($versionNode.NextSibling -and $versionNode.NextSibling.NodeType -eq "Comment")
853+
{
854+
# unfortunately because there are POM exceptions we need to wildcard the group which may be
855+
# something like <area>_groupId
856+
if ($versionNode.NextSibling.Value.Trim() -notmatch "{x-version-update;(.+)?$($groupId):$($artifactId);\w+}")
857+
{
858+
$hasError = $true
859+
$potentialLogMessage = Join-With-NewLine $potentialLogMessage "Error: signature version update tag for groupId=$($groupId), artifactId=$($artifactId) should be <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
860+
}
861+
else
862+
{
863+
# verify the version tag and version are correct
864+
$retVal = Test-Dependency-Tag-And-Version $libHash $extDepHash $versionNode.InnerText.Trim() $versionNode.NextSibling.Value
865+
if ($retVal)
866+
{
867+
$hasError = $true
868+
$potentialLogMessage = Join-With-NewLine $potentialLogMessage "$($retVal)"
869+
}
870+
}
871+
}
872+
else
873+
{
874+
$hasError = $true
875+
$potentialLogMessage = Join-With-NewLine $potentialLogMessage "Error: Missing signature version update tag for groupId=$($groupId), artifactId=$($artifactId). The tag should be <!-- {x-version-update;$($groupId):$($artifactId);current|dependency|external_dependency<select one>} -->"
876+
}
877+
}
878+
797879
# This is for the allowlist dependencies. Fetch the banned dependencies
798880
foreach($bannedDependencies in $xmlPomFile.GetElementsByTagName("bannedDependencies"))
799881
{
@@ -923,5 +1005,7 @@ if ($script:FoundError)
9231005
{
9241006
Write-Error-With-Color "There were errors encountered during execution. Please fix errors and run the script again."
9251007
Write-Error-With-Color "This script can be run locally from the root of the repo. .\eng\versioning\pom_file_version_scanner.ps1"
926-
exit(1)
1008+
exit 1
9271009
}
1010+
# no errors, ensure it's exiting 0
1011+
exit 0

0 commit comments

Comments
 (0)