Skip to content

Don't verify baselines in CodeCheck when not in a PR build #30462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Feb 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions eng/scripts/CodeCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -192,36 +192,39 @@ try {
}

$targetBranch = $env:SYSTEM_PULLREQUEST_TARGETBRANCH
if ($targetBranch.StartsWith('refs/heads/')) {
$targetBranch = $targetBranch.Replace('refs/heads/','')
}

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

# Retrieve the set of changed files compared to main
Write-Host "Checking for changes to API baseline files $targetBranch"

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

if ($changedFilesFromTarget) {
foreach ($file in $changedFilesFromTarget) {
# Check for changes in Shipped in all branches
if ($file -like '*PublicAPI.Shipped.txt') {
$changedAPIBaselines.Add($file)
}
# Check for changes in Unshipped in servicing branches
if ($targetBranch -like 'release*' -and $file -like '*PublicAPI.Unshipped.txt') {
$changedAPIBaselines.Add($file)
if ($changedFilesFromTarget) {
foreach ($file in $changedFilesFromTarget) {
# Check for changes in Shipped in all branches
if ($file -like '*PublicAPI.Shipped.txt') {
$changedAPIBaselines.Add($file)
}
# Check for changes in Unshipped in servicing branches
if ($targetBranch -like 'release*' -and $file -like '*PublicAPI.Unshipped.txt') {
$changedAPIBaselines.Add($file)
}
}
}
}

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

if ($changedAPIBaselines.count -gt 0) {
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."
LogError "Modified API baseline files:"
foreach ($file in $changedAPIBaselines) {
LogError $file
if ($changedAPIBaselines.count -gt 0) {
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."
LogError "Modified API baseline files:"
foreach ($file in $changedAPIBaselines) {
LogError $file
}
}
}
}
Expand Down