From 4e680436288f4d2ab976ccb608586017bb461450 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu <31145988+chidozieononiwu@users.noreply.github.com> Date: Fri, 19 Feb 2021 11:08:58 -0800 Subject: [PATCH] Only run eng/common check when target branch is master (#1415) Only run eng/common check when target branch is master --- .../steps/eng-common-workflow-enforcer.yml | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml b/eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml index 29aa89acc..0125e6cba 100644 --- a/eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml +++ b/eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml @@ -1,13 +1,24 @@ steps: - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: - pwsh: | - $filesInCommonDir = git diff "origin/$(System.PullRequest.TargetBranch)" HEAD --name-only -- 'eng/common/*' + Set-PsDebug -Trace 1 + # Find the default branch of the repo + $defaultBranch = (git remote show origin | Out-String) -replace "(?ms).*HEAD branch: (\w+).*", '$1' + $targetBranch = "$(System.PullRequest.TargetBranch)" -replace "refs/heads/" - if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-eng/common")) -and ($LASTEXITCODE -eq 0) -and ($filesInCommonDir.Count -gt 0)) + Write-Host "Default Branch: ${defaultBranch}" + + if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-eng/common")) -and $targetBranch -eq $defaultBranch) { - Write-Host "##vso[task.LogIssue type=error;]Changes to files under 'eng/common' directory should not be made in this Repo`n${filesInCommonDir}" - 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" - exit 1 + + $filesInCommonDir = git diff "origin/${targetBranch}" HEAD --name-only -- 'eng/common/*' + + if (($LASTEXITCODE -eq 0) -and ($filesInCommonDir.Count -gt 0)) + { + Write-Host "##vso[task.LogIssue type=error;]Changes to files under 'eng/common' directory should not be made in this Repo`n${filesInCommonDir}" + 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" + exit 1 + } } displayName: Prevent changes to eng/common outside of azure-sdk-tools repo condition: and(succeeded(), ne(variables['Skip.EngCommonWorkflowEnforcer'], 'true'))