Skip to content

Commit

Permalink
Add FilePattern support for .github\workflow sync (#8849)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weshaggard authored Aug 16, 2024
1 parent c376240 commit 571fc6a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ steps:
}
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/*' -DiffFilterType ""
$filesInCommonDir = & "eng/common/scripts/get-changedfiles.ps1" -DiffPath '.github/workflows/*event*' -DiffFilterType ""
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}"
Expand Down
6 changes: 5 additions & 1 deletion eng/pipelines/eng-workflows-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ parameters:
- name: DirectoryToSync
type: string
default: .github/workflows
- name: FilePattern
type: string
default: '/*event*'
- name: Repos
type: object
default:
Expand All @@ -28,10 +31,11 @@ pr:
- main
paths:
include:
- .github/workflows
- .github/workflows/*event*

extends:
template: /eng/pipelines/templates/stages/archetype-sdk-tool-repo-sync.yml
parameters:
DirectoryToSync: ${{ parameters.DirectoryToSync }}
FilePattern: ${{ parameters.FilePattern }}
Repos: ${{ parameters.Repos }}
14 changes: 7 additions & 7 deletions eng/pipelines/templates/stages/archetype-sdk-tool-repo-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ parameters:
- name: DirectoryToSync
type: string
default: not-specified
- name: FilePattern
type: string
default: ''
- name: BaseBranchName
type: string
default: $(Build.SourceBranch)
default: $(DefaultBranch)
- name: Repos
type: object
default: []
Expand All @@ -35,7 +38,7 @@ stages:
- pwsh: |
Set-PsDebug -Trace 1
$patchDir = "$(Build.ArtifactStagingDirectory)/patchfiles"
$patchfiles = git format-patch --output-directory $patchDir HEAD...origin/$(system.pullRequest.targetBranch) -- "${{ parameters.DirectoryToSync }}"
$patchfiles = git format-patch --output-directory $patchDir HEAD...origin/$(system.pullRequest.targetBranch) -- "${{ parameters.DirectoryToSync }}${{ parameters.FilePattern }}"
if ($patchfiles -and ($LASTEXITCODE -eq 0)) {
echo "##vso[task.setvariable variable=PatchFilesLocation]$patchDir"
echo "Setting PatchFilesLocation"
Expand All @@ -57,6 +60,7 @@ stages:
parameters:
CommitMessage: "Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools repository for Tools PR $(System.PullRequest.PullRequestNumber)"
DirectoryToSync: ${{ parameters.DirectoryToSync }}
FilePattern: ${{ parameters.FilePattern }}
UpstreamBranchName: "sync-${{ parameters.DirectoryToSync }}-$(System.PullRequest.SourceBranch)-$(System.PullRequest.PullRequestNumber)"
BaseBranchName: $(system.pullRequest.targetBranch)
SkipCheckingForChanges: true
Expand Down Expand Up @@ -189,15 +193,11 @@ stages:
vmImage: ubuntu-22.04

steps:
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
parameters:
Paths:
- ${{ parameters.DirectoryToSync }}

- template: /eng/pipelines/templates/steps/sync-directory.yml
parameters:
CommitMessage: Sync ${{ parameters.DirectoryToSync }} directory with azure-sdk-tools repository
DirectoryToSync: ${{ parameters.DirectoryToSync }}
FilePattern: ${{ parameters.FilePattern }}
UpstreamBranchName: "sync-${{ parameters.DirectoryToSync }}"
BaseBranchName: ${{ parameters.BaseBranchName }}
Repos: ${{ parameters.Repos }}
6 changes: 3 additions & 3 deletions eng/pipelines/templates/steps/sync-directory.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
Repos: []
DirectoryToSync: eng/common
FilePattern: ''
CommitMessage: commit-message-not-set
UpstreamBranchName: branch-name-not-set
BaseBranchName: $(DefaultBranch)
Expand All @@ -27,7 +28,6 @@ steps:

- ${{ each repo in parameters.Repos }}:
- pwsh: |
$repoPath = "${{ repo }}/${{ parameters.DirectoryToSync }}"
if (Test-Path '$(PatchFilesLocation)')
{
pushd ${{ repo }}
Expand Down Expand Up @@ -152,9 +152,9 @@ steps:
- pwsh: |
Set-PsDebug -Trace 1
$repoPath = "${{ repo }}/${{ parameters.DirectoryToSync }}"
Remove-Item -v -r -ErrorAction Ignore $repoPath
Remove-Item -v -r -ErrorAction Ignore "$repoPath${{ parameters.FilePattern }}"
Copy-Item -v -r `
$(System.DefaultWorkingDirectory)/$(Build.Repository.Name)/${{ parameters.DirectoryToSync }} `
"$(System.DefaultWorkingDirectory)/$(Build.Repository.Name)/${{ parameters.DirectoryToSync }}${{ parameters.FilePattern }}" `
$repoPath
Get-ChildItem -r $repoPath
displayName: Copy ${{ parameters.DirectoryToSync }} from azure-sdk-tools to ${{ repo }}
Expand Down

0 comments on commit 571fc6a

Please sign in to comment.