Skip to content

Commit b222aa7

Browse files
Only run eng/common check when target branch is master (Azure#16787)
Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
1 parent 3d4267b commit b222aa7

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
steps:
22
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
33
- pwsh: |
4-
$filesInCommonDir = git diff "origin/$(System.PullRequest.TargetBranch)" HEAD --name-only -- 'eng/common/*'
4+
Set-PsDebug -Trace 1
5+
# Find the default branch of the repo
6+
$defaultBranch = (git remote show origin | Out-String) -replace "(?ms).*HEAD branch: (\w+).*", '$1'
7+
$targetBranch = "$(System.PullRequest.TargetBranch)" -replace "refs/heads/"
58
6-
if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-eng/common")) -and ($LASTEXITCODE -eq 0) -and ($filesInCommonDir.Count -gt 0))
9+
Write-Host "Default Branch: ${defaultBranch}"
10+
11+
if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-eng/common")) -and $targetBranch -eq $defaultBranch)
712
{
8-
Write-Host "##vso[task.LogIssue type=error;]Changes to files under 'eng/common' directory should not be made in this Repo`n${filesInCommonDir}"
9-
Write-Host "##vso[task.LogIssue type=error;]Please follow workflow at https://github.com/Azure/azure-sdk-tools/blob/master/doc/common/common_engsys.md"
10-
exit 1
13+
14+
$filesInCommonDir = git diff "origin/${targetBranch}" HEAD --name-only -- 'eng/common/*'
15+
16+
if (($LASTEXITCODE -eq 0) -and ($filesInCommonDir.Count -gt 0))
17+
{
18+
Write-Host "##vso[task.LogIssue type=error;]Changes to files under 'eng/common' directory should not be made in this Repo`n${filesInCommonDir}"
19+
Write-Host "##vso[task.LogIssue type=error;]Please follow workflow at https://github.com/Azure/azure-sdk-tools/blob/master/doc/common/common_engsys.md"
20+
exit 1
21+
}
1122
}
1223
displayName: Prevent changes to eng/common outside of azure-sdk-tools repo
1324
condition: and(succeeded(), ne(variables['Skip.EngCommonWorkflowEnforcer'], 'true'))

0 commit comments

Comments
 (0)