Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FilePattern support for .github\workflow sync #8849

Merged
merged 4 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ""
weshaggard marked this conversation as resolved.
Show resolved Hide resolved
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 }}
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