File: resolve-package-info.ps1

package info (click to toggle)
python-azure 20251014%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 766,472 kB
  • sloc: python: 6,314,744; ansic: 804; javascript: 287; makefile: 198; sh: 198; xml: 109
file content (45 lines) | stat: -rw-r--r-- 1,847 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
param (
    [string] $ParameterTargetingStringSetting,
    [string] $PackagePropertiesFolder,
    [bool] $IncludeIndirect = $true
)

$setting = $ParameterTargetingStringSetting
$targetingString = $ParameterTargetingStringSetting

# users of internal service builds will set variable "BuildTargetingString" at runtime
# if they want to artificially filter the discovered packages for the build.
# when azure devops sets the variable, it will make it all capital letters, so we should check that
if ($env:BUILDTARGETINGSTRING) {
    $targetingString = $env:BUILDTARGETINGSTRING
}

Write-Host "The resolved targeting string within the script is `"$targetingString`""

if (Test-Path "$PackagePropertiesFolder") {
    $packageProperties = Get-ChildItem -Recurse -Force "$PackagePropertiesFolder/*.json" `

    if (-not $IncludeIndirect) {
        $packageProperties = Get-ChildItem -Recurse -Force "$PackagePropertiesFolder/*.json" `
            | Where-Object {
                $includedForValidation = (Get-Content -Raw $_ | ConvertFrom-Json).IncludedForValidation
                if ($includedForValidation -eq $true) {
                    Remove-Item $_.FullName; $false
                } else { $true }
            }
    }

    $packageProperties = $packageProperties
        | Where-Object { if ($_.Name.Replace(".json", "") -like "$targetingString") { return $true } else { Remove-Item $_.FullName; return $false; } }
        | ForEach-Object { $_.Name.Replace(".json", "") }

    $setting = $packageProperties -join ","

    # in case we don't expect any packages, we should set the variable to null, which will match NO packages and cause whatever the check
    # is to skip with exit 0 (which is what we want!)
    if (-not $setting) {
        $setting = "null"
    }
}

Write-Host "##vso[task.setvariable variable=TargetingString;]$setting"