-
Notifications
You must be signed in to change notification settings - Fork 6
/
azure-pipelines.yml
344 lines (323 loc) · 15 KB
/
azure-pipelines.yml
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
pool:
vmImage: 'ubuntu-latest'
variables:
- name: PIPELINE_ORG
value: Azure
- name: PIPELINE_REPO
value: depth-coverage-pipeline
- name: PULL_NUMBER
value: $(System.PullRequest.PullRequestNumber)
- name: ResourceProvider
value: empty
- name: Resource
value: ""
- name: ResourceMapJson
value: ""
- name: RESOURCE_MAP_FILE
value: ToGenerate.json
- name: README_FILE
value: ""
- name: TARGET
value: clicore
- name: AlertInstruction
value: ""
- name: NotifyUsers
value: ""
- name: Artifcact
value: ""
stages:
- stage: setup
jobs:
# - job: controlappserver
# steps:
# - script: |
# curl -X GET http://10.172.15.142:3000
- job: config
steps:
- script: |
sudo npm install -g depthcoverage --unsafe-perm=true --allow-root
sudo apt-get install jq -y
displayName: 'prepare'
- script: |
depthcoverage --token=$(PIPELINE_TOKEN) --org=$(PIPELINE_ORG) --repo=$(PIPELINE_REPO) --operation=readPR --PRNumber=$(System.PullRequest.PullRequestNumber)
# rp=`jq .RPName $(RESOURCE_MAP_FILE)`
# echo $rp
# echo '##vso[task.setvariable variable=ResourceProvider]$rp'
displayName: 'Get resource config file'
- pwsh: |
$jsonfile=$env:RESOURCE_MAP_FILE
echo $jsonfile
$data = Get-content $jsonfile | ConvertFrom-Json
echo $data
$name=$data.RPName
$readmefile=$data.readmeFile
$target=$data.target
$ignore=$data.ignoreFailures
$excludeStages=$data.excludeStages
echo $target
Write-Host "##vso[task.setvariable variable=ResourceProvider]$name"
Write-Host "##vso[task.setvariable variable=README_FILE]$readmefile"
Write-Host "##vso[task.setvariable variable=TARGET]$target"
$af=""
$packagename=""
if($target -eq "terraform") {
$af="generated/$name ./go/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/Azure/azure-sdk-for-go/services/$name"
$packagename=$name
} else {
if($name -eq "compute") {
$af="./azure-cli/src/azure-cli/azure/cli/command_modules/vm ./azure-cli/src/azure-cli/requirements*.txt ./azure-cli/doc/sphinx/azhelpgen/doc_source_map.json ./azure-rest-api-specs/specification/$(ResourceProvider)/resource-manager/readme.az.md"
$packagename="vm"
} else {
$af="./azure-cli/src/azure-cli/azure/cli/command_modules/$name ./azure-cli/src/azure-cli/requirements*.txt ./azure-cli/doc/sphinx/azhelpgen/doc_source_map.json ./azure-rest-api-specs/specification/$(ResourceProvider)/resource-manager/readme.az.md"
$packagename=$name
}
}
echo $af
Write-Host "##vso[task.setvariable variable=Artifcact]$af"
Write-Host "##vso[task.setvariable variable=Package]$packagename"
Write-Host "##vso[task.setvariable variable=ignore;isOutput=true]$ignore TestFailure"
Write-Host "##vso[task.setvariable variable=excludestages;isOutput=true]$excludedStages"
name: configResource
displayName: "Set variable"
- script: echo $(ResourceProvider)
displayName: "Get variable"
- script: |
mkdir -p $(Pipeline.Workspace)/variables
echo "$(ResourceProvider)" > $(Pipeline.Workspace)/variables/ResourceProvider
echo "$(README_FILE)" > $(Pipeline.Workspace)/variables/README_FILE
echo "$(TARGET)" > $(Pipeline.Workspace)/variables/TARGET
echo "$(Artifcact)" > $(Pipeline.Workspace)/variables/Artifact
echo ""
ls -l $(Pipeline.Workspace)/variables
displayName: "publish variable"
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifact: 'variables'
publishLocation: 'pipeline'
- stage: GenerateCode
dependsOn: setup
condition: succeeded()
jobs:
- job: GenerateJob
steps:
- template: .azure-pipelines/templates/VariableSetTask.yml
- template: .azure-pipelines/templates/GenerateCode.yml
- bash: |
sdktarget=$(TARGET)
if [ "$sdktarget" == "terraform" ]; then
echo "##vso[task.setvariable variable=tobuild;isOutput=true]Yes"
else
echo "##vso[task.setvariable variable=tobuild;isOutput=true]No"
fi
displayName: "set output variable"
name: DetermineResult
- template: .azure-pipelines/templates/AfterTask.yml
- stage: Build
dependsOn: GenerateCode
condition: and(succeeded(), eq(stageDependencies.GenerateCode.outputs['GenerateJob.DetermineResult.tobuild'], 'Yes'))
jobs:
- job: build
steps:
- template: .azure-pipelines/templates/BeforeTask.yml
- script: echo 'build'
- template: .azure-pipelines/templates/BuildTF.yml
- job: alertIssue
dependsOn: build
condition: and(failed(),eq(variables['TARGET'], 'terraform'))
steps:
- template: .azure-pipelines/templates/IssueAlertTask.yml
- stage: MockTest
dependsOn:
- GenerateCode
- Build
condition: and(in(dependencies.Build.result, 'Succeeded', 'SucceededWithIssues', 'Skipped'), succeeded('GenerateCode'))
jobs:
- job: DetermineSDKJob
steps:
- template: .azure-pipelines/templates/VariableSetTask.yml
- bash: |
sdktarget=$(TARGET)
if [ "$sdktarget" == "terraform" ]; then
echo "##vso[task.setvariable variable=sdk;isOutput=true]terraform"
else
echo "##vso[task.setvariable variable=sdk;isOutput=true]cli"
fi
name: determineSDK
- job: ClIMockTest
steps:
- template: .azure-pipelines/templates/BeforeTask.yml
- script: echo 'CLI MockTest'
- template: .azure-pipelines/templates/SetupCliTestEnv.yml
- template: .azure-pipelines/templates/SetupCliMockServerEnv.yml
# - template: .azure-pipelines/templates/SetupCliTestEnv.yml
- template: .azure-pipelines/templates/RunCliMockTest.yml
displayName: CLIMockTest
dependsOn: DetermineSDKJob
condition: eq(dependencies.DetermineSDKJob.outputs['determineSDK.sdk'], 'cli')
- job: TFMockTest
steps:
- template: .azure-pipelines/templates/BeforeTask.yml
- script: echo 'TF MockTest'
- template: .azure-pipelines/templates/SetupTFTestEnv.yml
- template: .azure-pipelines/templates/SetupTFMockServerEnv.yml
- template: .azure-pipelines/templates/RunTFMockTest.yml
displayName: TFIMockTest
dependsOn: DetermineSDKJob
condition: eq(dependencies.DetermineSDKJob.outputs['determineSDK.sdk'], 'terraform')
- job: alertIssue
dependsOn:
- CLIMockTest
- TFMockTest
condition: or(and(eq(dependencies.DetermineSDKJob.outputs['determineSDK.sdk'], 'cli'), failed('ClIMockTest')), and(eq(dependencies.DetermineSDKJob.outputs['determineSDK.sdk'], 'terraform'), failed('TFMockTest')))
steps:
- template: .azure-pipelines/templates/VariableSetTask.yml
- template: .azure-pipelines/templates/IssueAlertTask.yml
- stage: LiveTest
dependsOn: MockTest
condition: succeeded('MockTest')
jobs:
- job: DetermineSDKForLiveJob
steps:
- template: .azure-pipelines/templates/VariableSetTask.yml
- bash: |
sdktarget=$(TARGET)
if [ "$sdktarget" == "terraform" ]; then
echo "##vso[task.setvariable variable=sdk;isOutput=true]terraform"
else
echo "##vso[task.setvariable variable=sdk;isOutput=true]cli"
fi
name: liveSDK
- job: CLILiveTest
steps:
- script: echo 'CLILiveTest'
- template: .azure-pipelines/templates/BeforeTask.yml
- template: .azure-pipelines/templates/SetupCliTestEnv.yml
- template: .azure-pipelines/templates/RunCliTest.yml
displayName: CLILiveTest
dependsOn: DetermineSDKForLiveJob
condition: eq(dependencies.DetermineSDKForLiveJob.outputs['liveSDK.sdk'], 'cli')
- job : TFLiveTest
steps:
- bash: echo 'TF LiveTest'
- template: .azure-pipelines/templates/BeforeTask.yml
- template: .azure-pipelines/templates/SetupTFTestEnv.yml
- template: .azure-pipelines/templates/RunTFLiveTest.yml
displayName: TFLiveTest
dependsOn: DetermineSDKForLiveJob
condition: eq(dependencies.DetermineSDKForLiveJob.outputs['liveSDK.sdk'], 'terraform')
- job: alertIssue
dependsOn:
- CLILiveTest
- TFLiveTest
condition: or(and(eq(dependencies.DetermineSDKForLiveJob.outputs['liveSDK.sdk'], 'cli'), failed('ClIMockTest')), and(eq(dependencies.DetermineSDKForLiveJob.outputs['liveSDK.sdk'], 'terraform'), failed('TFMockTest')))
steps:
- template: .azure-pipelines/templates/VariableSetTask.yml
- template: .azure-pipelines/templates/IssueAlertTask.yml
- stage: SubmitStage
dependsOn:
- setup
- LiveTest
condition: or(succeeded('LiveTest'), contains(stageDependencies.setup.outputs['config.configResource.ignore'], 'TestFailure'))
jobs:
- job: submit
steps:
- template: .azure-pipelines/templates/BeforeTask.yml
- bash: |
echo $(Pipeline.Workspace)
pwd
echo "https://$(PIPELINE_USER):${PIPELINE_TOKEN}@github.com" > ~/.git-credentials
sdktarget=$(TARGET)
if [ "$sdktarget" == "terraform" ]; then
git clone --branch depth-$(TARGET)-$(ResourceProvider) https://${PIPELINE_USER}:${PIPELINE_TOKEN}@github.com/${TF_ORG}/terraform-provider-azurerm.git
cd ./terraform-provider-azurerm
fi
if [ "$sdktarget" == "clicore" ] || [ "$sdktarget" == "cliextension" ]; then
git clone --branch depth-$(TARGET)-$(ResourceProvider) https://${PIPELINE_USER}:${PIPELINE_TOKEN}@github.com/${CLI_ORG}/azure-cli
cd ./azure-cli
fi
git config credential.helper store; git config --global user.email "[email protected]";git config --global user.name "chunyu3;"
git branch; git add -A; git commit -m "autogenerated"; git push origin depth-$(TARGET)-$(ResourceProvider);
displayName: 'Generate pull request'
- job: confirm
dependsOn: submit
condition: succeeded()
displayName: confirm submit or customize
steps:
- template: .azure-pipelines/templates/VariableSetTask.yml
- bash: |
echo "https://$(PIPELINE_USER):${PIPELINE_TOKEN}@github.com" > ~/.git-credentials
git clone --branch depth-$(TARGET)-$(ResourceProvider) https://${PIPELINE_USER}:${PIPELINE_TOKEN}@github.com/${Swagger_ORG}/azure-rest-api-specs.git
sdktarget=$(TARGET)
if [ "$sdktarget" == "terraform" ]; then
git clone --branch depth-$(TARGET)-$(ResourceProvider) https://${PIPELINE_USER}:${PIPELINE_TOKEN}@github.com/${TF_ORG}/terraform-provider-azurerm.git
cp ./azure-rest-api-specs/specification/$(ResourceProvider)/resource-manager/readme.trenton.md ./terraform-providers/terraform-provider-azurerm/azurerm/internal/services/$(ResourceProvider)/
cd ./terraform-provider-azurerm
# git checkout -b depth-code-$(TARGET)-$(ResourceProvider)
tf_existed_in_remote=$(git ls-remote --heads origin depth-code-$(TARGET)-$(ResourceProvider))
if [[ -z ${tf_existed_in_remote} ]]; then
git checkout -b depth-code-$(TARGET)-$(ResourceProvider)
else
git checkout depth-code-$(TARGET)-$(ResourceProvider)
fi
fi
if [ "$sdktarget" == "clicore" ] || [ "$sdktarget" == "cliextension" ]; then
git clone --branch depth-$(TARGET)-$(ResourceProvider) https://${PIPELINE_USER}:${PIPELINE_TOKEN}@github.com/${CLI_ORG}/azure-cli
name=$(ResourceProvider)
if [ "$name" == "compute" ]; then
name="vm"
fi
# cp ./azure-rest-api-specs/specification/$(ResourceProvider)/resource-manager/readme.az.md ./azure-cli/src/azure-cli/azure/cli/command_modules/$name/
cp ./azure-rest-api-specs/specification/$(ResourceProvider)/resource-manager/readme.az.md ./azure-cli/
cd ./azure-cli
# git checkout -b depth-code-$(TARGET)-$(ResourceProvider)
tf_existed_in_remote=$(git ls-remote --heads origin depth-code-$(TARGET)-$(ResourceProvider))
if [[ -z ${tf_existed_in_remote} ]]; then
git checkout -b depth-code-$(TARGET)-$(ResourceProvider)
else
git checkout depth-code-$(TARGET)-$(ResourceProvider)
fi
git branch; git add -A; git commit -m "autogenerated"; git push origin depth-code-$(TARGET)-$(ResourceProvider);
fi
git config credential.helper store; git config --global user.email "[email protected]";git config --global user.name "chunyu3;"
git branch; git add -A; git commit -m "autogenerated"; git push origin depth-code-$(TARGET)-$(ResourceProvider);
cd $(Pipeline.Workspace)/s
sdktarget=$(TARGET)
org=""
repo=""
base="master"
sdk="";
if [ "$sdktarget" == "terraform" ]; then
org=$(TF_ORG)
repo="terraform-provider-azurerm"
sdk="terraform"
else
org=$(CLI_ORG)
repo="azure-cli"
base="dev"
sdk="clicore"
fi
echo "$repo"
echo "$org"
echo "$base"
# curl -X POST -H "Content-Type: application/json" http://$(CodegenApp_Server)/DepthCoverage/generateCodePR -d '{"token":"$(PIPELINE_TOKEN)", "org":"$org", "repo":"$repo", "title":"[]pull request of $(ResourceProvider)", "branch":"depth-$(TARGET)-$(ResourceProvider)", "base":"$base"}'
# codePR=`curl -X POST -H "Content-Type: application/json" http://$(CodegenApp_Server)/DepthCoverage/generateCodePR -d '{"token":"$(PIPELINE_TOKEN)", "org":"$(org)", "repo":"$(repo)", "title":"{depth coverage, not merge} pull request of $(ResourceProvider)", "branch":"depth-$(TARGET)-$(ResourceProvider)", "base":"$(base)"}'`
codePR=$(curl -X POST -H "Content-Type: application/json" http://$(CodegenApp_Server)/DepthCoverage/generateCodePR -d '{"token":"$(PIPELINE_TOKEN)", "org":"'"$org"'", "repo":"'"$repo"'", "title":"{depth coverage, not merge} pull request of $(ResourceProvider)", "branch":"depth-code-$(TARGET)-$(ResourceProvider)", "base":"'"$base"'"}')
echo $codePR
triggerPR="https://github.com/Azure/depth-coverage-pipeline/pull/$(System.PullRequest.PullRequestNumber)"
submitURL="http://$(CodegenApp_Server)/DepthCoverage/RPs/$(ResourceProvider)/SDKs/$sdk/submit?token=$(PIPELINE_TOKEN)&swaggerorg=$(Swagger_ORG)&org=$org"
customizeURL="http://$(CodegenApp_Server)/DepthCoverage/RPs/$(ResourceProvider)/SDKs/$sdk/Customize?triggerPR=$triggerPR&token=$(PIPELINE_TOKEN)&codePR=$codePR&org=$org"
python scripts/onboard.py "Onboarding" "$(TARGET) Onboarding $(ResourceProvider) confirm" "$codePR" "$triggerPR" "$submitURL" "$customizeURL" > scripts/email.html
echo "start of email"
cat scripts/email.html
echo "end of email"
to_mail="[email protected]"
sudo pip install wheel
sudo pip install sendgrid
python scripts/sendGridemail.py "scripts/email.html" $to_mail "Depth-coverage Onboarding Confirm" $(API_KEY)
echo "end of send email"
displayName: "send confirm email"