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 ff4927b8b..af8b009b5 100644 --- a/eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml +++ b/eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml @@ -19,5 +19,15 @@ steps: exit 1 } } - displayName: Prevent changes to eng/common outside of azure-sdk-tools repo + if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-.github/workflows")) -and "$(System.PullRequest.TargetBranch)" -match "^(refs/heads/)?$(DefaultBranch)$") + { + $filesInCommonDir = & "eng/common/scripts/get-changedfiles.ps1" -DiffPath '.github/workflows/*' + if (($LASTEXITCODE -eq 0) -and ($filesInCommonDir.Count -gt 0)) + { + Write-Host "##vso[task.LogIssue type=error;]Changes to files under '.github/workflows' 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/main/doc/workflows/engsys_workflows.md" + exit 1 + } + } + displayName: Prevent changes to eng/common and .github/workflows outside of azure-sdk-tools repo condition: and(succeeded(), ne(variables['Skip.EngCommonWorkflowEnforcer'], 'true'), not(endsWith(variables['Build.Repository.Name'], '-pr'))) \ No newline at end of file diff --git a/eng/common/scripts/Delete-RemoteBranches.ps1 b/eng/common/scripts/Delete-RemoteBranches.ps1 index 2d1c3c303..49cc85cbe 100644 --- a/eng/common/scripts/Delete-RemoteBranches.ps1 +++ b/eng/common/scripts/Delete-RemoteBranches.ps1 @@ -10,6 +10,7 @@ param( $CentralRepoId, # We start from the sync PRs, use the branch name to get the PR number of central repo. E.g. sync-eng/common-()-(). Have group name on PR number. # For sync-eng/common work, we use regex as "^sync-eng/common.*-(?\d+).*$". + # For sync-.github/workflows work, we use regex as "^sync-.github/workflows.*-(?\d+).*$". $BranchRegex, # Date format: e.g. Tuesday, April 12, 2022 1:36:02 PM. Allow to use other date format. [AllowNull()] @@ -69,7 +70,7 @@ foreach ($res in $responses) LogError "No PR number found in the branch name. Please check the branch name [ $branchName ]. Skipping..." continue } - + try { $centralPR = Get-GitHubPullRequest -RepoId $CentralRepoId -PullRequestNumber $pullRequestNumber -AuthToken $AuthToken LogDebug "Found central PR pull request: $($centralPR.html_url)" @@ -78,7 +79,7 @@ foreach ($res in $responses) continue } } - catch + catch { # If there is no central PR for the PR number, log error and skip. LogError "Get-GitHubPullRequests failed with exception:`n$_" @@ -107,15 +108,15 @@ foreach ($res in $responses) LogDebug "The branch $branch last commit date [ $commitDate ] is newer than the date $LastCommitOlderThan. Skipping." continue } - + LogDebug "Branch [ $branchName ] in repo [ $RepoId ] has a last commit date [ $commitDate ] that is older than $LastCommitOlderThan. " } catch { LogError "Get-GithubReferenceCommitDate failed with exception:`n$_" exit 1 } - } - + } + try { if ($PSCmdlet.ShouldProcess("[ $branchName ] in [ $RepoId ]", "Deleting branches on cleanup script")) { Remove-GitHubSourceReferences -RepoId $RepoId -Ref $branch -AuthToken $AuthToken