Skip to content

Commit 8aa4da4

Browse files
author
John Luo
authored
Don't verify baselines in CodeCheck when not in a PR build (#30462)
1 parent 62d4886 commit 8aa4da4

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

eng/scripts/CodeCheck.ps1

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -192,36 +192,39 @@ try {
192192
}
193193

194194
$targetBranch = $env:SYSTEM_PULLREQUEST_TARGETBRANCH
195-
if ($targetBranch.StartsWith('refs/heads/')) {
196-
$targetBranch = $targetBranch.Replace('refs/heads/','')
197-
}
198195

199-
# Retrieve the set of changed files compared to main
200-
Write-Host "Checking for changes to API baseline files $targetBranch"
196+
if (![string]::IsNullOrEmpty($targetBranch)) {
197+
if ($targetBranch.StartsWith('refs/heads/')) {
198+
$targetBranch = $targetBranch.Replace('refs/heads/','')
199+
}
200+
201+
# Retrieve the set of changed files compared to main
202+
Write-Host "Checking for changes to API baseline files $targetBranch"
201203

202-
$changedFilesFromTarget = git --no-pager diff origin/$targetBranch --ignore-space-change --name-only --diff-filter=ar
203-
$changedAPIBaselines = [System.Collections.Generic.List[string]]::new()
204+
$changedFilesFromTarget = git --no-pager diff origin/$targetBranch --ignore-space-change --name-only --diff-filter=ar
205+
$changedAPIBaselines = [System.Collections.Generic.List[string]]::new()
204206

205-
if ($changedFilesFromTarget) {
206-
foreach ($file in $changedFilesFromTarget) {
207-
# Check for changes in Shipped in all branches
208-
if ($file -like '*PublicAPI.Shipped.txt') {
209-
$changedAPIBaselines.Add($file)
210-
}
211-
# Check for changes in Unshipped in servicing branches
212-
if ($targetBranch -like 'release*' -and $file -like '*PublicAPI.Unshipped.txt') {
213-
$changedAPIBaselines.Add($file)
207+
if ($changedFilesFromTarget) {
208+
foreach ($file in $changedFilesFromTarget) {
209+
# Check for changes in Shipped in all branches
210+
if ($file -like '*PublicAPI.Shipped.txt') {
211+
$changedAPIBaselines.Add($file)
212+
}
213+
# Check for changes in Unshipped in servicing branches
214+
if ($targetBranch -like 'release*' -and $file -like '*PublicAPI.Unshipped.txt') {
215+
$changedAPIBaselines.Add($file)
216+
}
214217
}
215218
}
216-
}
217219

218-
Write-Host "Found changes in $($changedAPIBaselines.count) API baseline files"
220+
Write-Host "Found changes in $($changedAPIBaselines.count) API baseline files"
219221

220-
if ($changedAPIBaselines.count -gt 0) {
221-
LogError "Detected modification to baseline API files. PublicAPI.Shipped.txt files should only be updated after a major release. See /docs/APIBaselines.md for more information."
222-
LogError "Modified API baseline files:"
223-
foreach ($file in $changedAPIBaselines) {
224-
LogError $file
222+
if ($changedAPIBaselines.count -gt 0) {
223+
LogError "Detected modification to baseline API files. PublicAPI.Shipped.txt files should only be updated after a major release. See /docs/APIBaselines.md for more information."
224+
LogError "Modified API baseline files:"
225+
foreach ($file in $changedAPIBaselines) {
226+
LogError $file
227+
}
225228
}
226229
}
227230
}

0 commit comments

Comments
 (0)