forked from Azure/azure-sdk-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-directory.yml
More file actions
172 lines (161 loc) · 7.88 KB
/
sync-directory.yml
File metadata and controls
172 lines (161 loc) · 7.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
parameters:
Repos: []
DirectoryToSync: eng/common
FilePattern: ''
CommitMessage: commit-message-not-set
UpstreamBranchName: branch-name-not-set
BaseBranchName: $(DefaultBranch)
Sync: pr-data-artifact-path-not-set
SkipCheckingForChanges: false
ScriptDirectory: eng/common/scripts
PROwner: Azure
PushArgs: -f
steps:
- template: /eng/common/pipelines/templates/steps/set-default-branch.yml
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
parameters:
SkipCheckoutNone: true
Paths:
- ${{ parameters.DirectoryToSync }}
Repositories:
- ${{ each repo in parameters.Repos }}:
- Name: ${{ parameters.PROwner }}/${{ repo }}
Commitish: ${{ parameters.BaseBranchName }}
WorkingDirectory: $(System.DefaultWorkingDirectory)/${{ repo }}
- ${{ each repo in parameters.Repos }}:
- pwsh: |
if (Test-Path '$(PatchFilesLocation)')
{
pushd ${{ repo }}
$results = @()
echo "##vso[task.setvariable variable=HasChanges]$false"
$shaBeforePatches = git rev-parse --short HEAD
foreach ($file in (Get-ChildItem $(PatchFilesLocation)))
{
Write-Host $file.FullName
git -c user.name="azure-sdk" -c user.email="azuresdk@microsoft.com" am -3 $file.FullName
if ($lastExitCode -ne 0) {
git -c user.name="azure-sdk" -c user.email="azuresdk@microsoft.com" am --show-current-patch=diff
Write-Error "##vso[task.LogIssue type=warning;]Failed to properly apply patch files to [https://github.com/azure/${{ repo }}]"
exit 1
}
}
$shaAfterPatches = git rev-parse --short HEAD
$hasChanges = $shaBeforePatches -ne $shaAfterPatches
echo "##vso[task.setvariable variable=HasChanges]$hasChanges"
}
displayName: Apply Patch for ${{ parameters.DirectoryToSync }} from azure-sdk-tools to ${{ repo }}
workingDirectory: $(System.DefaultWorkingDirectory)
- task: PowerShell@2
displayName: Push changes for creating Sync PRs
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
inputs:
pwsh: true
workingDirectory: $(System.DefaultWorkingDirectory)/${{ repo }}
filePath: ${{ parameters.ScriptDirectory }}/git-branch-push.ps1
arguments: >
-PRBranchName "${{ parameters.UpstreamBranchName }}"
-CommitMsg "${{ parameters.CommitMessage }}"
-GitUrl "https://$(azuresdk-github-pat)@github.com/${{ parameters.PROwner }}/${{ repo }}.git"
-PushArgs "${{ parameters.PushArgs }}"
-SkipCommit $${{parameters.SkipCheckingForChanges}}
- task: PowerShell@2
displayName: Push changes for Queueing Test Pipeline
condition: and(succeeded(), ne(variables['${{repo}}-template-definition-id'], ''))
inputs:
pwsh: true
workingDirectory: $(System.DefaultWorkingDirectory)/${{ repo }}
filePath: ${{ parameters.ScriptDirectory }}/git-branch-push.ps1
arguments: >
-PRBranchName "${{ parameters.UpstreamBranchName }}-ForTestPipeline"
-CommitMsg "${{ parameters.CommitMessage }}"
-GitUrl "https://$(azuresdk-github-pat)@github.com/${{ parameters.PROwner }}/${{ repo }}.git"
-PushArgs "${{ parameters.PushArgs }}"
-AmendCommit $True
- task: AzureCLI@2
displayName: Queue template pipeline
condition: and(succeeded(), ne(variables['${{repo}}-template-definition-id'], ''))
inputs:
azureSubscription: opensource-api-connection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
$accessToken = az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv
${{ parameters.ScriptDirectory }}/Queue-Pipeline.ps1 `
-Organization "azure-sdk" `
-Project "internal" `
-SourceBranch "${{ parameters.UpstreamBranchName }}-ForTestPipeline" `
-DefinitionId "$(${{repo}}-template-definition-id)" `
-VsoQueuedPipelines "QUEUEDPIPELINES" `
-CancelPreviousBuilds $True `
-BearerToken $accessToken
workingDirectory: ${{ parameters.WorkingDirectory }}
- task: AzureCLI@2
displayName: Queue live-test template pipeline
condition: and(succeeded(), ne(variables['${{repo}}-template-tests-definition-id'], ''))
inputs:
azureSubscription: opensource-api-connection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
$accessToken = az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv
${{ parameters.ScriptDirectory }}/Queue-Pipeline.ps1 `
-Organization "azure-sdk" `
-Project "internal" `
-SourceBranch "${{ parameters.UpstreamBranchName }}-ForTestPipeline" `
-DefinitionId "$(${{repo}}-template-tests-definition-id)" `
-VsoQueuedPipelines "QUEUEDPIPELINES" `
-CancelPreviousBuilds $True `
-BearerToken $accessToken
workingDirectory: ${{ parameters.WorkingDirectory }}
- task: PowerShell@2
displayName: Write Queued Pipeline Information to Tools PR
condition: and(succeeded(), and(ne(variables['QUEUEDPIPELINES'], ''), eq(variables['Build.Reason'], 'PullRequest')))
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: ${{ parameters.ScriptDirectory }}/Add-IssueComment.ps1
arguments: >
-RepoOwner "Azure"
-RepoName "azure-sdk-tools"
-IssueNumber "$(System.PullRequest.PullRequestNumber)"
-Comment "The following pipelines have been queued for testing:<br>$env:QUEUEDPIPELINES`
<br>You can sign off on the approval gate to test the release stage of each pipeline.`
<br>See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow)"
-AuthToken "$(azuresdk-github-pat)"
- ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
parameters:
SkipCheckoutNone: true
Paths:
- ${{ parameters.DirectoryToSync }}
Repositories:
- Name: $(Build.Repository.Name)
Commitish: $(Build.SourceVersion)
WorkingDirectory: $(System.DefaultWorkingDirectory)/$(Build.Repository.Name)
- ${{ each repo in parameters.Repos }}:
- Name: ${{ parameters.PROwner }}/${{ repo }}
Commitish: ${{ parameters.BaseBranchName }}
WorkingDirectory: $(System.DefaultWorkingDirectory)/${{ repo }}
- ${{ each repo in parameters.Repos }}:
- pwsh: |
Set-PsDebug -Trace 1
$repoPath = "${{ repo }}/${{ parameters.DirectoryToSync }}"
Remove-Item -v -r -ErrorAction Ignore "$repoPath${{ parameters.FilePattern }}"
Copy-Item -v -r `
"$(System.DefaultWorkingDirectory)/$(Build.Repository.Name)/${{ parameters.DirectoryToSync }}${{ parameters.FilePattern }}" `
$repoPath
Get-ChildItem -r $repoPath
displayName: Copy ${{ parameters.DirectoryToSync }} from azure-sdk-tools to ${{ repo }}
workingDirectory: $(System.DefaultWorkingDirectory)
- template: /eng/common/pipelines/templates/steps/create-pull-request.yml
parameters:
RepoName: ${{ repo }}
BaseBranchName: ${{ parameters.BaseBranchName }}
PRBranchName: sync-${{ parameters.DirectoryToSync }}
CommitMsg: ${{ parameters.CommitMessage }}
PRTitle: ${{ parameters.CommitMessage }}
PushArgs: -f
WorkingDirectory: $(System.DefaultWorkingDirectory)/${{ repo }}
ScriptDirectory: $(System.DefaultWorkingDirectory)/$(Build.Repository.Name)/${{ parameters.ScriptDirectory }}