@@ -6,6 +6,7 @@ $MetadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/main/_data/rel
66$CampaignTag = Resolve-Path (Join-Path - Path $PSScriptRoot - ChildPath " ../repo-docs/ga_tag.html" )
77$GithubUri = " https://github.com/Azure/azure-sdk-for-java"
88$PackageRepositoryUri = " https://repo1.maven.org/maven2"
9+ $ValidationGroupsFile = Resolve-Path (Join-Path - Path $PSScriptRoot - ChildPath " ../validation-groups.yml" )
910
1011. " $PSScriptRoot /docs/Docs-ToC.ps1"
1112. " $PSScriptRoot /docs/Docs-Onboarding.ps1"
@@ -193,6 +194,130 @@ function Get-AllPackageInfoFromRepo([string]$serviceDirectory = $null) {
193194 return $allPackageProps
194195}
195196
197+ # Get-java-AdditionalValidationPackagesFromPackageSet is the implementation of the
198+ # $AdditionalValidationPackagesFromPackageSetFn which is used
199+ function Get-java-AdditionalValidationPackagesFromPackageSet {
200+ param (
201+ [Parameter (Mandatory = $true )]
202+ $LocatedPackages ,
203+ [Parameter (Mandatory = $true )]
204+ $diffObj ,
205+ [Parameter (Mandatory = $true )]
206+ $AllPkgProps
207+ )
208+ $additionalValidationPackages = @ ()
209+ $uniqueResultSet = @ ()
210+
211+ function Test-StartsWith {
212+ param (
213+ [string []]$ChangedFiles ,
214+ [string []]$StartsWithPrefixes
215+ )
216+ if ($ChangedFiles.Length -eq 0 -or $StartsWithPrefixes.Length -eq 0 ) {
217+ return $false ;
218+ }
219+ foreach ($startsWithPrefix in $StartsWithPrefixes ) {
220+ $HasMatch = $ChangedFiles | Where-Object { $_.StartsWith ($startsWithPrefix ) }
221+ # if there's a match, return right away
222+ if ($HasMatch ) {
223+ return $true
224+ }
225+ }
226+ # no matches will return false
227+ return $false
228+ }
229+
230+ # this section will identify the list of packages that we should treat as
231+ # "directly" changed for a given service level change. While that doesn't
232+ # directly change a package within the service, I do believe we should directly include all
233+ # packages WITHIN that service. This is because the service level file changes are likely to
234+ # have an impact on the packages within that service.
235+ $changedServices = @ ()
236+ $targetedFiles = $diffObj.ChangedFiles
237+ if ($diff.DeletedFiles ) {
238+ if (-not $targetedFiles ) {
239+ $targetedFiles = @ ()
240+ }
241+ $targetedFiles += $diff.DeletedFiles
242+ }
243+
244+ # The targetedFiles needs to filter out anything in the ExcludePaths
245+ # otherwise it'll end up processing things below that it shouldn't be.
246+ foreach ($excludePath in $diffObj.ExcludePaths ) {
247+ $targetedFiles = $targetedFiles | Where-Object { -not $_.StartsWith ($excludePath.TrimEnd (" /" ) + " /" ) }
248+ }
249+
250+ if ($targetedFiles ) {
251+ foreach ($file in $targetedFiles ) {
252+ $pathComponents = $file -split " /"
253+ # Handle changes in the root of any sdk/<ServiceDirectory>. Unfortunately, changes
254+ # in the root service directory require any and all libraries in that service directory,
255+ # include those in a <ServiceDirectory>/<LibraryDirectory> to get added to the changed
256+ # services.
257+ if ($pathComponents.Length -eq 3 -and $pathComponents [0 ] -eq " sdk" ) {
258+ $changedServices += $pathComponents [1 ]
259+ }
260+
261+ # For anything in the root of the sdk directory, or the repository root, just run template
262+ if (($pathComponents.Length -eq 2 -and $pathComponents [0 ] -eq " sdk" ) -or
263+ ($pathComponents.Length -eq 1 )) {
264+ $changedServices += " template"
265+ }
266+ }
267+ # dedupe the changedServices list
268+ $changedServices = $changedServices | Get-Unique
269+ foreach ($changedService in $changedServices ) {
270+ # Because Java has libraries at the sdk/<ServiceDirectory> and sdk/<ServiceDirectory>/<Library>
271+ # directories, the additional package lookup needs to for ci*.yml files where the ServiceDirectory
272+ # equals the $changedService as well as ServiceDirectories that starts $changedService/, note the
273+ # trailing slash is necessary. For example, if PR changes the ServiceDirectory foo and there
274+ # exist ci.yml files with the service directories "foo/bar" and "foobar", we only want to match
275+ # foo and foo/bar, not foobar hence the -eq $changedService and StartsWith("$changedService/")
276+ $additionalPackages = $AllPkgProps | Where-Object { $_.ServiceDirectory -eq $changedService -or $_.ServiceDirectory.StartsWith (" $changedService /" )}
277+ foreach ($pkg in $additionalPackages ) {
278+ if ($uniqueResultSet -notcontains $pkg -and $LocatedPackages -notcontains $pkg ) {
279+ # notice the lack of setting IncludedForValidation to true. This is because these "changed services"
280+ # are specifically where a file within the service, but not an individual package within that service has changed.
281+ # we want this package to be fully validated
282+ $uniqueResultSet += $pkg
283+ }
284+ }
285+ }
286+ }
287+
288+ $additionalPackagesForOtherDirs = @ ()
289+ if ($targetedFiles ) {
290+ $content = LoadFrom- Yaml $ValidationGroupsFile
291+ $validationGroups = GetValueSafelyFrom- Yaml $content @ (" validationGroups" )
292+ foreach ($validationGroup in $validationGroups ) {
293+ if (Test-StartsWith - ChangedFiles $targetedFiles - StartsWithPrefixes $validationGroup.dirStartsWithPrefixes ) {
294+ $itemsToAdd = $validationGroup.additionalPackagesForValidation -join " , "
295+ Write-Verbose " $ ( $validationGroup.Name ) match, adding the following packages for additional validation: $itemsToAdd "
296+ $additionalPackagesForOtherDirs += $validationGroup.additionalPackagesForValidation
297+ }
298+ }
299+ }
300+
301+ if ($additionalPackagesForOtherDirs ) {
302+ $additionalPackages = $additionalPackagesForOtherDirs | ForEach-Object { $me = $_ ; $AllPkgProps | Where-Object { $_.Name -eq $me } | Select-Object - First 1 }
303+ $additionalValidationPackages += $additionalPackages
304+ }
305+
306+ foreach ($pkg in $additionalValidationPackages ) {
307+ if ($uniqueResultSet -notcontains $pkg -and $LocatedPackages -notcontains $pkg ) {
308+ $pkg.IncludedForValidation = $true
309+ $uniqueResultSet += $pkg
310+ }
311+ }
312+
313+ Write-Host " Returning additional packages for validation: $ ( $uniqueResultSet.Count ) "
314+ foreach ($pkg in $uniqueResultSet ) {
315+ Write-Host " - $ ( $pkg.Name ) "
316+ }
317+
318+ return $uniqueResultSet
319+ }
320+
196321# Returns the maven (really sonatype) publish status of a package id and version.
197322function IsMavenPackageVersionPublished ($pkgId , $pkgVersion , $groupId )
198323{
@@ -565,4 +690,3 @@ function Get-java-ApiviewStatusCheckRequirement($packageInfo) {
565690 }
566691 return $false
567692}
568-
0 commit comments