Skip to content

Commit ce35a98

Browse files
danieljurekCopilotCopilot
authored
Add CODEOWNERS verification pipeline step and script (#15192)
* Add CODEOWNERS verification pipeline step and script Add verify-codeowners.yml pipeline template step and Test-CodeownersForArtifacts.ps1 script to validate that packages intended for release have sufficient CODEOWNERS coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Review feedback * Fail closed on missing release status --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 206b337 commit ce35a98

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
parameters:
2+
- name: ArtifactPath
3+
type: string
4+
default: $(Build.ArtifactStagingDirectory)/PackageInfo
5+
- name: Repo
6+
type: string
7+
default: $(Build.Repository.Name)
8+
- name: SdkTypes
9+
type: object
10+
default:
11+
- client
12+
- compat
13+
- data
14+
- functions
15+
- datamovement
16+
17+
steps:
18+
- template: /eng/common/pipelines/templates/steps/install-azsdk-cli.yml
19+
parameters:
20+
Condition: and(succeeded(), ne(variables['Skip.VerifyCodeowners'], 'true'))
21+
22+
- task: PowerShell@2
23+
displayName: Verify Codeowners
24+
condition: and(succeeded(), ne(variables['Skip.VerifyCodeowners'], 'true'))
25+
inputs:
26+
pwsh: true
27+
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Test-CodeownersForArtifacts.ps1
28+
arguments: >-
29+
-AzsdkPath '$(AZSDK)'
30+
-PackageInfoDirectory '${{ parameters.ArtifactPath }}'
31+
-SdkTypes ${{ join(',', parameters.SdkTypes) }}
32+
-Repo '${{ parameters.Repo }}'
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[CmdletBinding()]
2+
param(
3+
[string] $AzsdkPath,
4+
[string] $PackageInfoDirectory,
5+
[array] $SdkTypes,
6+
[string] $Repo
7+
)
8+
9+
. "$PSScriptRoot/common.ps1"
10+
11+
Set-StrictMode -Version 3
12+
$ErrorActionPreference = 'Stop'
13+
14+
$failedPackages = @()
15+
16+
foreach ($pkgPropertiesFile in Get-ChildItem -Path $PackageInfoDirectory -Filter '*.json' -File) {
17+
$pkgProperties = Get-Content -Raw -Path $pkgPropertiesFile | ConvertFrom-Json
18+
if ($SdkTypes -notcontains $pkgProperties.SdkType) {
19+
Write-Host "Skipping package: $($pkgProperties.Name) $($pkgProperties.DirectoryPath) because its SdkType '$($pkgProperties.SdkType)' is not in the list of SdkTypes to validate."
20+
continue
21+
}
22+
23+
Write-Host "Validating codeowners for package: $($pkgProperties.Name) $($pkgProperties.DirectoryPath)"
24+
25+
if (!$pkgProperties.ReleaseStatus) {
26+
LogError "Package $($pkgProperties.Name) at $($pkgProperties.DirectoryPath) is missing a ReleaseStatus property."
27+
$failedPackages += $pkgProperties.DirectoryPath
28+
continue
29+
}
30+
31+
# Validate packages with a release date (intended to release)
32+
if ($pkgProperties.ReleaseStatus -ne "Unreleased") {
33+
$output = & $AzsdkPath config codeowners check-package `
34+
--directory-path $pkgProperties.DirectoryPath `
35+
--repo $Repo `
36+
--output json 2>&1
37+
38+
if ($LASTEXITCODE) {
39+
LogError "Codeowners validation failed for package: $($pkgProperties.DirectoryPath)"
40+
$output | Write-Host
41+
$failedPackages += $pkgProperties.DirectoryPath
42+
} else {
43+
Write-Host " Codeowners validation succeeded for package: $($pkgProperties.DirectoryPath)"
44+
}
45+
} else {
46+
Write-Host " Skipping CODEOWNERS validation, package is not intended to release."
47+
}
48+
}
49+
50+
if ($failedPackages.Count -gt 0) {
51+
Write-Host ""
52+
Write-Host "Failed Packages:"
53+
foreach ($directoryPath in $failedPackages) {
54+
LogError " - $directoryPath does not have sufficient code owners coverage"
55+
}
56+
LogError "Codeowners validation failed for one or more packages. See http://aka.ms/azsdk/codeowners for instructions to fix the issue."
57+
exit 1
58+
}
59+
exit 0

0 commit comments

Comments
 (0)