Skip to content

Commit 571fc6a

Browse files
authored
Add FilePattern support for .github\workflow sync (#8849)
Given we cannot create subfolders under .github\workflow folder and we have repos that want additional workflows then we have in the tools repo we need to setup a file pattern matching for the sync processing to only sync the ones we want to be common. For now just use the existing *event* pattern but we can move them to another pattern similar to *common* or *sync* in the future as we add more common workflows.
1 parent c376240 commit 571fc6a

4 files changed

Lines changed: 16 additions & 12 deletions

File tree

eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ steps:
2121
}
2222
if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-.github/workflows")) -and "$(System.PullRequest.TargetBranch)" -match "^(refs/heads/)?$(DefaultBranch)$")
2323
{
24-
$filesInCommonDir = & "eng/common/scripts/get-changedfiles.ps1" -DiffPath '.github/workflows/*' -DiffFilterType ""
24+
$filesInCommonDir = & "eng/common/scripts/get-changedfiles.ps1" -DiffPath '.github/workflows/*event*' -DiffFilterType ""
2525
if (($LASTEXITCODE -eq 0) -and ($filesInCommonDir.Count -gt 0))
2626
{
2727
Write-Host "##vso[task.LogIssue type=error;]Changes to files under '.github/workflows' directory should not be made in this Repo`n${filesInCommonDir}"

eng/pipelines/eng-workflows-sync.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ parameters:
66
- name: DirectoryToSync
77
type: string
88
default: .github/workflows
9+
- name: FilePattern
10+
type: string
11+
default: '/*event*'
912
- name: Repos
1013
type: object
1114
default:
@@ -28,10 +31,11 @@ pr:
2831
- main
2932
paths:
3033
include:
31-
- .github/workflows
34+
- .github/workflows/*event*
3235

3336
extends:
3437
template: /eng/pipelines/templates/stages/archetype-sdk-tool-repo-sync.yml
3538
parameters:
3639
DirectoryToSync: ${{ parameters.DirectoryToSync }}
40+
FilePattern: ${{ parameters.FilePattern }}
3741
Repos: ${{ parameters.Repos }}

eng/pipelines/templates/stages/archetype-sdk-tool-repo-sync.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ parameters:
88
- name: DirectoryToSync
99
type: string
1010
default: not-specified
11+
- name: FilePattern
12+
type: string
13+
default: ''
1114
- name: BaseBranchName
1215
type: string
13-
default: $(Build.SourceBranch)
16+
default: $(DefaultBranch)
1417
- name: Repos
1518
type: object
1619
default: []
@@ -35,7 +38,7 @@ stages:
3538
- pwsh: |
3639
Set-PsDebug -Trace 1
3740
$patchDir = "$(Build.ArtifactStagingDirectory)/patchfiles"
38-
$patchfiles = git format-patch --output-directory $patchDir HEAD...origin/$(system.pullRequest.targetBranch) -- "${{ parameters.DirectoryToSync }}"
41+
$patchfiles = git format-patch --output-directory $patchDir HEAD...origin/$(system.pullRequest.targetBranch) -- "${{ parameters.DirectoryToSync }}${{ parameters.FilePattern }}"
3942
if ($patchfiles -and ($LASTEXITCODE -eq 0)) {
4043
echo "##vso[task.setvariable variable=PatchFilesLocation]$patchDir"
4144
echo "Setting PatchFilesLocation"
@@ -57,6 +60,7 @@ stages:
5760
parameters:
5861
CommitMessage: "Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools repository for Tools PR $(System.PullRequest.PullRequestNumber)"
5962
DirectoryToSync: ${{ parameters.DirectoryToSync }}
63+
FilePattern: ${{ parameters.FilePattern }}
6064
UpstreamBranchName: "sync-${{ parameters.DirectoryToSync }}-$(System.PullRequest.SourceBranch)-$(System.PullRequest.PullRequestNumber)"
6165
BaseBranchName: $(system.pullRequest.targetBranch)
6266
SkipCheckingForChanges: true
@@ -189,15 +193,11 @@ stages:
189193
vmImage: ubuntu-22.04
190194

191195
steps:
192-
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
193-
parameters:
194-
Paths:
195-
- ${{ parameters.DirectoryToSync }}
196-
197196
- template: /eng/pipelines/templates/steps/sync-directory.yml
198197
parameters:
199198
CommitMessage: Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools repository
200199
DirectoryToSync: ${{ parameters.DirectoryToSync }}
200+
FilePattern: ${{ parameters.FilePattern }}
201201
UpstreamBranchName: "sync-${{ parameters.DirectoryToSync }}"
202202
BaseBranchName: ${{ parameters.BaseBranchName }}
203203
Repos: ${{ parameters.Repos }}

eng/pipelines/templates/steps/sync-directory.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
parameters:
22
Repos: []
33
DirectoryToSync: eng/common
4+
FilePattern: ''
45
CommitMessage: commit-message-not-set
56
UpstreamBranchName: branch-name-not-set
67
BaseBranchName: $(DefaultBranch)
@@ -27,7 +28,6 @@ steps:
2728

2829
- ${{ each repo in parameters.Repos }}:
2930
- pwsh: |
30-
$repoPath = "${{ repo }}/${{ parameters.DirectoryToSync }}"
3131
if (Test-Path '$(PatchFilesLocation)')
3232
{
3333
pushd ${{ repo }}
@@ -152,9 +152,9 @@ steps:
152152
- pwsh: |
153153
Set-PsDebug -Trace 1
154154
$repoPath = "${{ repo }}/${{ parameters.DirectoryToSync }}"
155-
Remove-Item -v -r -ErrorAction Ignore $repoPath
155+
Remove-Item -v -r -ErrorAction Ignore "$repoPath${{ parameters.FilePattern }}"
156156
Copy-Item -v -r `
157-
$(System.DefaultWorkingDirectory)/$(Build.Repository.Name)/${{ parameters.DirectoryToSync }} `
157+
"$(System.DefaultWorkingDirectory)/$(Build.Repository.Name)/${{ parameters.DirectoryToSync }}${{ parameters.FilePattern }}" `
158158
$repoPath
159159
Get-ChildItem -r $repoPath
160160
displayName: Copy ${{ parameters.DirectoryToSync }} from azure-sdk-tools to ${{ repo }}

0 commit comments

Comments
 (0)