Skip to content

Commit c8c5adb

Browse files
authored
[CI] Update Sync tools pipeline to support all branches (#26917)
* update sync-tools-folder to support more branches * fix a typo * remove SyncFromMainBranchConfig.json * update pr branch name * update pr branch name again
1 parent c96fa39 commit c8c5adb

File tree

3 files changed

+67
-72
lines changed

3 files changed

+67
-72
lines changed

.azure-pipelines/SyncFromMainBranchConfig.json

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,68 @@
1-
resources:
2-
repositories:
3-
- repository: self
4-
type: git
5-
ref: main
1+
parameters:
2+
- name: ToBranches
3+
displayName: To Branches
4+
type: object
5+
default: ["generation"]
6+
- name: SyncPaths
7+
displayName: Paths to sync
8+
type: object
9+
default:
10+
- .ci-config.json
11+
- tools
12+
- .azure-pipelines
13+
- src/lib
14+
- src/shared
15+
- build.proj
16+
- src/Az.props
17+
- src/Az.Shared.props
18+
- src/Az.Test.props
19+
- src/Az.autorest.props
20+
- src/Az.Post.props
21+
- src/psm1.props
22+
- NuGet.Config
623

724
trigger:
825
branches:
926
include:
1027
- main
1128
paths:
1229
include:
13-
- .azure-pipelines
14-
- .devcontainer
15-
- tools
16-
- src/lib
17-
- .ci-config.json
18-
- src/shared
19-
- build.proj
20-
- src/Az.props
21-
- src/Az.Shared.props
22-
- src/Az.Test.props
23-
- src/Az.autorest.props
24-
- src/Az.Post.props
25-
- src/psm1.props
26-
- NuGet.Config
30+
- .ci-config.json
31+
- tools
32+
- .azure-pipelines
33+
- src/lib
34+
- src/shared
35+
- build.proj
36+
- src/Az.props
37+
- src/Az.Shared.props
38+
- src/Az.Test.props
39+
- src/Az.autorest.props
40+
- src/Az.Post.props
41+
- src/psm1.props
42+
- NuGet.Config
2743

28-
variables:
29-
GenerationBranchName: generation
30-
3144
jobs:
32-
- job: Sync
33-
displayName: Sync task
34-
condition: succeeded()
35-
strategy:
36-
matrix:
37-
Generation:
38-
BranchName: ${{ variables.GenerationBranchName }}
45+
- ${{ each ToBranch in parameters.ToBranches }}:
46+
- job: Sync_${{ replace(ToBranch, '/', '_') }}
47+
displayName: "Sync To ${{ ToBranch }}"
48+
pool: pool-ubuntu-2004
3949

40-
steps:
41-
- template: util/get-github-pat-steps.yml
42-
- task: PowerShell@2
43-
displayName: Sync branch
44-
inputs:
45-
targetType: inline
46-
script: >-
47-
./tools/SyncFromMainBranch.ps1 -BranchName $(BranchName) -GithubToken $(GithubToken)
48-
pwsh: true
50+
steps:
51+
- template: util/get-github-pat-steps.yml
4952

50-
- pwsh: |
51-
$Title = "Sync tools code from main branch to $(BranchName) branch"
52-
$HeadBranch = "syncToolsFolder-$(BranchName)"
53-
$BaseBranch = "$(BranchName)"
54-
$Description = "Migrate Sync tools code from main branch to $(BranchName) branch"
55-
./tools/Github/CreatePR.ps1 -Title $Title -HeadBranch $HeadBranch -BaseBranch $BaseBranch -BotAccessToken $(GithubToken) -Description $Description
56-
displayName: Create PR to $(BranchName) branch
53+
- task: PowerShell@2
54+
displayName: "Sync To ${{ ToBranch }}"
55+
inputs:
56+
targetType: inline
57+
script: |
58+
$SyncPaths='${{Converttojson(parameters.SyncPaths)}}' | ConvertFrom-Json
59+
./tools/SyncFromMainBranch.ps1 -BranchName ${{ ToBranch }} -GithubToken $(GithubToken) -SyncPath $SyncPaths -UnSyncPath @()
60+
pwsh: true
61+
62+
- pwsh: |
63+
$Title = "Sync tools code from $(Build.SourceBranchName) branch to ${{ ToBranch }} branch"
64+
$HeadBranch = "syncToolsFolder/${{ ToBranch }}"
65+
$BaseBranch = "${{ ToBranch }}"
66+
$Description = "Migrate Sync tools code from $(Build.SourceBranchName) branch to ${{ ToBranch }} branch"
67+
./tools/Github/CreatePR.ps1 -Title $Title -HeadBranch $HeadBranch -BaseBranch $BaseBranch -BotAccessToken $(GithubToken) -Description $Description
68+
displayName: Create PR to ${{ ToBranch }} branch

tools/SyncFromMainBranch.ps1

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@ param(
33
[Parameter()]
44
[string]$BranchName,
55
[Parameter()]
6-
[string]$GithubToken
6+
[string]$GithubToken,
7+
[Parameter()]
8+
[array]$SyncPaths,
9+
[Parameter()]
10+
[array]$UnSyncPaths
711
)
812

9-
$Config = Get-Content (Join-Path $PSScriptRoot "../.azure-pipelines/SyncFromMainBranchConfig.json") | ConvertFrom-Json
1013
$TmpFolder = New-Item -ItemType Directory -Path tmp
1114

12-
foreach ($SyncPath in $Config.SyncPath)
15+
foreach ($SyncPath in $SyncPaths)
1316
{
1417
Write-Host "Back up $SyncPath from main branch."
1518
Copy-Item -Path $SyncPath -Destination "$TmpFolder/$SyncPath" -Recurse -Force
1619
}
1720

1821
git config --global user.email "[email protected]"
1922
git config --global user.name "azurepowershell"
20-
git checkout -b "syncToolsFolder-$BranchName" "origin/$BranchName"
23+
git checkout -b "syncToolsFolder/$BranchName" "origin/$BranchName"
2124

2225
# There are some files or folders who need to be keeped in target branch.
23-
foreach ($UnSyncPath in $Config.UnSyncPath)
26+
foreach ($UnSyncPath in $UnSyncPaths)
2427
{
2528
if (Test-Path -Path $UnSyncPath)
2629
{
@@ -30,7 +33,7 @@ foreach ($UnSyncPath in $Config.UnSyncPath)
3033
}
3134
}
3235

33-
foreach ($SyncPath in $Config.SyncPath)
36+
foreach ($SyncPath in $SyncPaths)
3437
{
3538
if (Test-Path -Path $SyncPath) {
3639
Remove-Item -Path $SyncPath -Recurse -Force
@@ -41,4 +44,4 @@ foreach ($SyncPath in $Config.SyncPath)
4144

4245
git commit -m "Sync tools folder from main branch to $BranchName branch"
4346
git remote set-url origin "https://$GithubToken@github.com/Azure/azure-powershell.git"
44-
git push origin "syncToolsFolder-$BranchName" --force
47+
git push origin "syncToolsFolder/$BranchName" --force

0 commit comments

Comments
 (0)