Skip to content

Commit 8e1f5ac

Browse files
azure-sdkscbeddweshaggard
authored
Sync eng/common directory with azure-sdk-tools for PR 8754 (#36793)
* more compatibility with expanding/contracting packages. add ability for packages to have DependentPackages that must be included in the set of packages that should be built given a changeset --------- Co-authored-by: Scott Beddall <[email protected]> Co-authored-by: Scott Beddall <[email protected]> Co-authored-by: Wes Haggard <[email protected]>
1 parent 4e39756 commit 8e1f5ac

File tree

7 files changed

+130
-20
lines changed

7 files changed

+130
-20
lines changed

eng/common/pipelines/templates/steps/detect-api-changes.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
parameters:
22
ArtifactPath: $(Build.ArtifactStagingDirectory)
3-
Artifacts: []
43
ArtifactName: 'packages'
54

65
steps:
@@ -14,7 +13,6 @@ steps:
1413
inputs:
1514
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Detect-Api-Changes.ps1
1615
arguments: >
17-
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name)
1816
-ArtifactPath ${{parameters.ArtifactPath}}
1917
-CommitSha '$(Build.SourceVersion)'
2018
-BuildId $(Build.BuildId)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
parameters:
2+
- name: PackagePropertiesFolder
3+
type: string
4+
- name: Condition
5+
type: string
6+
default: succeeded()
7+
8+
steps:
9+
- task: Powershell@2
10+
inputs:
11+
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Verify-ChangeLogs.ps1
12+
arguments: >
13+
-PackagePropertiesFolder '${{ parameters.PackagePropertiesFolder }}'
14+
pwsh: true
15+
displayName: Verify ChangeLogEntries
16+
condition: ${{ parameters.Condition }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
parameters:
2+
- name: PackagePropertiesFolder
3+
type: string
4+
- name: RepoRoot
5+
type: string
6+
default: $(Build.SourcesDirectory)
7+
- name: SettingsPath
8+
type: string
9+
default: '$(Build.SourcesDirectory)/eng/.docsettings.yml'
10+
- name: DocWardenVersion
11+
type: string
12+
default: ''
13+
- name: Condition
14+
type: string
15+
default: succeeded()
16+
17+
steps:
18+
- pwsh: |
19+
$packageProperties = Get-ChildItem -Recurse "${{ parameters.PackagePropertiesFolder }}" *.json
20+
21+
$paths = @()
22+
23+
foreach($propertiesFile in $packageProperties) {
24+
$PackageProp = Get-Content -Path $propertiesFile | ConvertFrom-Json
25+
26+
$paths += (Join-Path "$(Build.SourcesDirectory)" $PackageProp.DirectoryPath)
27+
}
28+
29+
$scanPaths = $paths -join ","
30+
Write-Host "##vso[task.setvariable variable=ScanPathArgument;]$scanPaths"
31+
displayName: Populate Scan Paths
32+
33+
- task: PowerShell@2
34+
displayName: "Verify Readmes"
35+
condition: ${{ parameters.Condition }}
36+
inputs:
37+
filePath: "eng/common/scripts/Verify-Readme.ps1"
38+
arguments: >
39+
-DocWardenVersion '${{ parameters.DocWardenVersion }}'
40+
-ScanPaths '$(ScanPathArgument)'
41+
-RepoRoot ${{ parameters.RepoRoot }}
42+
-SettingsPath ${{ parameters.SettingsPath }}
43+
pwsh: true

eng/common/scripts/Detect-Api-Changes.ps1

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ Param (
1010
[string] $BuildId,
1111
[Parameter(Mandatory=$True)]
1212
[string] $CommitSha,
13-
[Parameter(Mandatory=$True)]
14-
[array] $ArtifactList,
1513
[string] $APIViewUri,
1614
[string] $RepoFullName = "",
1715
[string] $ArtifactName = "packages",
@@ -21,6 +19,8 @@ Param (
2119

2220
. (Join-Path $PSScriptRoot common.ps1)
2321

22+
$configFileDir = Join-Path -Path $ArtifactPath "PackageInfo"
23+
2424
# Submit API review request and return status whether current revision is approved or pending or failed to create review
2525
function Submit-Request($filePath, $packageName)
2626
{
@@ -64,7 +64,6 @@ function Submit-Request($filePath, $packageName)
6464
function Should-Process-Package($pkgPath, $packageName)
6565
{
6666
$pkg = Split-Path -Leaf $pkgPath
67-
$configFileDir = Join-Path -Path $ArtifactPath "PackageInfo"
6867
$pkgPropPath = Join-Path -Path $configFileDir "$packageName.json"
6968
if (!(Test-Path $pkgPropPath))
7069
{
@@ -103,32 +102,39 @@ if (!($FindArtifactForApiReviewFn -and (Test-Path "Function:$FindArtifactForApiR
103102
}
104103

105104
$responses = @{}
106-
foreach ($artifact in $ArtifactList)
105+
106+
$packageProperties = Get-ChildItem -Recurse -Force "$configFileDir" `
107+
| Where-Object { $_.Extension -eq '.json' }
108+
109+
foreach ($packagePropFile in $packageProperties)
107110
{
108-
Write-Host "Processing $($artifact.name)"
109-
$packages = &$FindArtifactForApiReviewFn $ArtifactPath $artifact.name
111+
$packageMetadata = Get-Content $packagePropFile | ConvertFrom-Json
112+
Write-Host "Processing $($packageMetadata.ArtifactName)"
113+
114+
$packages = &$FindArtifactForApiReviewFn $ArtifactPath $packageMetadata.ArtifactName
115+
110116
if ($packages)
111117
{
112118
$pkgPath = $packages.Values[0]
113-
$isRequired = Should-Process-Package -pkgPath $pkgPath -packageName $artifact.name
114-
Write-Host "Is API change detect required for $($artifact.name):$($isRequired)"
119+
$isRequired = Should-Process-Package -pkgPath $pkgPath -packageName $($packageMetadata.ArtifactName)
120+
Write-Host "Is API change detect required for $($packages.ArtifactName):$($isRequired)"
115121
if ($isRequired -eq $True)
116122
{
117123
$filePath = $pkgPath.Replace($ArtifactPath , "").Replace("\", "/")
118-
$respCode = Submit-Request -filePath $filePath -packageName $artifact.name
124+
$respCode = Submit-Request -filePath $filePath -packageName $($packageMetadata.ArtifactName)
119125
if ($respCode -ne '200')
120126
{
121-
$responses[$artifact.name] = $respCode
127+
$responses[$($packageMetadata.ArtifactName)] = $respCode
122128
}
123129
}
124130
else
125131
{
126-
Write-Host "Pull request does not have any change for $($artifact.name). Skipping API change detect."
132+
Write-Host "Pull request does not have any change for $($packageMetadata.ArtifactName)). Skipping API change detect."
127133
}
128134
}
129135
else
130136
{
131-
Write-Host "No package is found in artifact path to find API changes for $($artifact.name)"
137+
Write-Host "No package is found in artifact path to find API changes for $($packageMetadata.ArtifactName)"
132138
}
133139
}
134140

eng/common/scripts/Generate-PR-Diff.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ Param (
1919
[string] $TargetPath
2020
)
2121

22-
. (Join-Path $PSScriptRoot "Helpers" git-helpers.ps1)
22+
. (Join-Path $PSScriptRoot "Helpers" "git-helpers.ps1")
2323

2424
function Get-ChangedServices {
2525
Param (
2626
[Parameter(Mandatory=$True)]
2727
[string[]] $ChangedFiles
2828
)
29-
29+
3030
$changedServices = $ChangedFiles | Foreach-Object { if ($_ -match "sdk/([^/]+)") { $matches[1] } } | Sort-Object -Unique
3131

3232
return $changedServices

eng/common/scripts/Package-Properties.ps1

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class PackageProps
1515
[boolean]$IsNewSdk
1616
[string]$ArtifactName
1717
[string]$ReleaseStatus
18+
[string[]]$DependentPackages
1819

1920
PackageProps([string]$name, [string]$version, [string]$directoryPath, [string]$serviceDirectory)
2021
{
@@ -55,7 +56,7 @@ class PackageProps
5556
if ($changeLogEntry -and $changeLogEntry.ReleaseStatus)
5657
{
5758
$this.ReleaseStatus = $changeLogEntry.ReleaseStatus.Trim().Trim("()")
58-
}
59+
}
5960
}
6061
else
6162
{
@@ -101,7 +102,7 @@ function Get-PkgProperties
101102
return $pkgProps[0]
102103
}
103104

104-
LogError "Failed to retrive Properties for [$PackageName]"
105+
LogError "Failed to retrieve Properties for [$PackageName]"
105106
return $null
106107
}
107108

@@ -112,20 +113,35 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
112113
$diff = Get-Content $InputDiffJson | ConvertFrom-Json
113114
$targetedFiles = $diff.ChangedFiles
114115

115-
foreach($pkg in $allPackageProperties)
116+
$dependentPackagesForInclusion = @()
117+
$lookup = @{}
118+
119+
foreach ($pkg in $allPackageProperties)
116120
{
117121
$pkgDirectory = Resolve-Path "$($pkg.DirectoryPath)"
122+
$lookupKey = ($pkg.DirectoryPath).Replace($RepoRoot, "").SubString(1)
123+
$lookup[$lookupKey] = $pkg
118124

119-
foreach($file in $targetedFiles)
125+
foreach ($file in $targetedFiles)
120126
{
121127
$filePath = Resolve-Path (Join-Path $RepoRoot $file)
122128
$shouldInclude = $filePath -like "$pkgDirectory*"
123129
if ($shouldInclude) {
124130
$packagesWithChanges += $pkg
131+
132+
if ($pkg.DependentPackages) {
133+
$dependentPackagesForInclusion += $pkg.DependentPackages
134+
}
125135
}
126136
}
127137
}
128138

139+
foreach ($addition in $dependentPackagesForInclusion) {
140+
if ($lookup[$addition]) {
141+
$packagesWithChanges += $lookup[$addition]
142+
}
143+
}
144+
129145
return $packagesWithChanges
130146
}
131147

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Wrapper Script for ChangeLog Verification in a PR
2+
[CmdletBinding()]
3+
param (
4+
[String]$PackagePropertiesFolder
5+
)
6+
Set-StrictMode -Version 3
7+
8+
. (Join-Path $PSScriptRoot common.ps1)
9+
10+
# find which packages we need to confirm the changelog for
11+
$packageProperties = Get-ChildItem -Recurse "$PackagePropertiesFolder" *.json
12+
13+
# grab the json file, then confirm the changelog entry for it
14+
$allPassing = $true
15+
foreach($propertiesFile in $packageProperties) {
16+
$PackageProp = Get-Content -Path $propertiesFile | ConvertFrom-Json
17+
18+
$validChangeLog = Confirm-ChangeLogEntry -ChangeLogLocation $PackageProp.ChangeLogPath -VersionString $PackageProp.Version -ForRelease $false
19+
20+
if (-not $validChangeLog) {
21+
$allPassing = $false
22+
}
23+
}
24+
25+
26+
if (!$allPassing)
27+
{
28+
exit 1
29+
}
30+
31+
exit 0

0 commit comments

Comments
 (0)