Skip to content

Commit 7052e1b

Browse files
scbeddweshaggard
andauthored
Re-enable BuildTargetingString for mgmt release unblockers (Azure#38617)
* filter saved package properties by an optional runtime variable BuildTargetingString * if this is set, the package set for the service will be further filtered to matching the targetingstring. globbing is supported EG azure-storage* --------- Co-authored-by: Wes Haggard <[email protected]>
1 parent 4a63f72 commit 7052e1b

File tree

2 files changed

+51
-30
lines changed

2 files changed

+51
-30
lines changed

eng/pipelines/templates/steps/resolve-package-targeting.yml

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parameters:
22
- name: BuildTargetingString
33
type: string
4-
default: 'azure-*'
4+
default: '*'
55
- name: PackagePropertiesFolder
66
type: string
77
default: ''
@@ -13,36 +13,12 @@ steps:
1313
# whether we are running within a PR build or not, we need to walk the package properties and save them to
1414
# variable $(TargetingString) so that every other check and accept it as an argument.
1515
- pwsh: |
16-
$setting = "${{ parameters.BuildTargetingString }}"
16+
$IncludeIndirect = [bool]::Parse("${{ parameters.IncludeIndirect }}")
1717
18-
# if the variable is not set, it'll just come back as the variable name. otherwise it's set.
19-
if ('$(BuildTargetingString)' -ne ('$' + '(BuildTargetingString)')) {
20-
Write-Host "The variable named BuildTargetingString is set to $(BuildTargetingString)"
21-
$setting = "$(BuildTargetingString)"
22-
}
23-
else {
24-
if (Test-Path "${{ parameters.PackagePropertiesFolder }}") {
25-
if ("${{ parameters.IncludeIndirect }}" -eq "true") {
26-
$packageProperties = Get-ChildItem -Recurse -Force "${{ parameters.PackagePropertiesFolder }}/*.json" `
27-
| ForEach-Object { $_.Name.Replace(".json", "") }
28-
}
29-
else {
30-
$packageProperties = Get-ChildItem -Recurse -Force "${{ parameters.PackagePropertiesFolder }}/*.json" `
31-
| Where-Object { (Get-Content -Raw $_ | ConvertFrom-Json).IncludedForValidation -eq $false } `
32-
| ForEach-Object { $_.Name.Replace(".json", "") }
33-
}
34-
35-
$setting = $packageProperties -join ","
36-
37-
# 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
38-
# is to skip with exit 0 (which is what we want!)
39-
if (-not $setting) {
40-
$setting = "null"
41-
}
42-
}
43-
}
44-
45-
Write-Host "##vso[task.setvariable variable=TargetingString;]$setting"
18+
./eng/scripts/resolve-package-info.ps1 `
19+
-ParameterTargetingStringSetting "${{ parameters.BuildTargetingString }}" `
20+
-PackagePropertiesFolder "${{ parameters.PackagePropertiesFolder }}" `
21+
-IncludeIndirect $IncludeIndirect
4622
displayName: Resolve Targeted Packages
4723
# if targeting has been set by matrix, this value will already be populated
4824
condition: eq(variables['TargetingString'], '')
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
param (
2+
[string] $ParameterTargetingStringSetting,
3+
[string] $PackagePropertiesFolder,
4+
[bool] $IncludeIndirect = $true
5+
)
6+
7+
$setting = $ParameterTargetingStringSetting
8+
$targetingString = $ParameterTargetingStringSetting
9+
10+
# users of internal service builds will set variable "BuildTargetingString" at runtime
11+
# if they want to artificially filter the discovered packages for the build.
12+
# when azure devops sets the variable, it will make it all capital letters, so we should check that
13+
if ($env:BUILDTARGETINGSTRING) {
14+
$targetingString = $env:BUILDTARGETINGSTRING
15+
}
16+
17+
Write-Host "The resolved targeting string within the script is `"$targetingString`""
18+
19+
if (Test-Path "$PackagePropertiesFolder") {
20+
$packageProperties = Get-ChildItem -Recurse -Force "$PackagePropertiesFolder/*.json" `
21+
22+
if (-not $IncludeIndirect) {
23+
$packageProperties = Get-ChildItem -Recurse -Force "$PackagePropertiesFolder/*.json" `
24+
| Where-Object {
25+
$includedForValidation = (Get-Content -Raw $_ | ConvertFrom-Json).IncludedForValidation
26+
if ($includedForValidation -eq $true) {
27+
Remove-Item $_.FullName; $false
28+
} else { $true }
29+
}
30+
}
31+
32+
$packageProperties = $packageProperties
33+
| Where-Object { if ($_.Name.Replace(".json", "") -like "$targetingString") { return $true } else { Remove-Item $_.FullName; return $false; } }
34+
| ForEach-Object { $_.Name.Replace(".json", "") }
35+
36+
$setting = $packageProperties -join ","
37+
38+
# 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
39+
# is to skip with exit 0 (which is what we want!)
40+
if (-not $setting) {
41+
$setting = "null"
42+
}
43+
}
44+
45+
Write-Host "##vso[task.setvariable variable=TargetingString;]$setting"

0 commit comments

Comments
 (0)