forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepo-Tasks.psm1
423 lines (348 loc) · 15.1 KB
/
Repo-Tasks.psm1
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
$taskScriptDir = [System.IO.Path]::GetDirectoryName($PSCommandPath)
$env:repoRoot = [System.IO.Path]::GetDirectoryName($taskScriptDir)
$userPsFileDir = [string]::Empty
[string]$envVariableName="TEST_CSM_ORGID_AUTHENTICATION"
[CmdletBinding]
Function Set-TestEnvironment
{
<#
.SYNOPSIS
This cmdlet helps you to setup Test Environment for running tests
In order to successfully run a test, you will need SubscriptionId, TenantId
This cmdlet will only prompt you for Subscription and Tenant information, rest all other parameters are optional
#>
[CmdletBinding(DefaultParameterSetName='SpnParamSet')]
param(
[Parameter(ParameterSetName='UserIdParamSet', Mandatory=$true, HelpMessage = "UserId (OrgId) you would like to use")]
[ValidateNotNullOrEmpty()]
[string]$UserId,
[Parameter(ParameterSetName='UserIdParamSet', Mandatory=$true, HelpMessage = "UserId (OrgId) you would like to use")]
[ValidateNotNullOrEmpty()]
[string]$Password,
[Parameter(ParameterSetName='SpnParamSet', Mandatory=$true, HelpMessage='ServicePrincipal/ClientId you would like to use')]
[ValidateNotNullOrEmpty()]
[string]$ServicePrincipal,
[Parameter(ParameterSetName='SpnParamSet', Mandatory=$true, HelpMessage='ServicePrincipal Secret/ClientId Secret you would like to use')]
[ValidateNotNullOrEmpty()]
[string]$ServicePrincipalSecret,
[Parameter(ParameterSetName='SpnParamSet', Mandatory=$true)]
[Parameter(ParameterSetName='UserIdParamSet', Mandatory=$true, HelpMessage = "SubscriptionId you would like to use")]
[ValidateNotNullOrEmpty()]
[string]$SubscriptionId,
[Parameter(ParameterSetName='SpnParamSet', Mandatory=$true, HelpMessage='AADTenant/TenantId you would like to use')]
[ValidateNotNullOrEmpty()]
[string]$TenantId,
[ValidateSet("Playback", "Record", "None")]
[string]$RecordMode='Playback',
[ValidateSet("Prod", "Dogfood", "Current", "Next", "Custom")]
[string]$TargetEnvironment='Prod',
[string]$ResourceManagementUri,
[string]$GraphUri,
[string]$AADAuthUri,
[string]$AADTokenAudienceUri,
[string]$GraphTokenAudienceUri,
[string]$IbizaPortalUri,
[string]$ServiceManagementUri,
[string]$RdfePortalUri,
[string]$GalleryUri,
[string]$DataLakeStoreServiceUri,
[string]$DataLakeAnalyticsJobAndCatalogServiceUri
)
[string]$uris=""
$formattedConnStr = [string]::Format("SubscriptionId={0};HttpRecorderMode={1};Environment={2}", $SubscriptionId, $RecordMode, $TargetEnvironment)
if([string]::IsNullOrEmpty($UserId) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";UserId={0}"), $UserId)
}
if([string]::IsNullOrEmpty($Password) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";Password={0}"), $Password)
}
if([string]::IsNullOrEmpty($TenantId) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";AADTenant={0}"), $TenantId)
}
if([string]::IsNullOrEmpty($ServicePrincipal) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";ServicePrincipal={0}"), $ServicePrincipal)
}
if([string]::IsNullOrEmpty($ServicePrincipalSecret) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";ServicePrincipalSecret={0}"), $ServicePrincipalSecret)
}
#Uris
if([string]::IsNullOrEmpty($ResourceManagementUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";ResourceManagementUri={0}"), $ResourceManagementUri)
}
if([string]::IsNullOrEmpty($GraphUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";GraphUri={0}"), $GraphUri)
}
if([string]::IsNullOrEmpty($AADAuthUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";AADAuthUri={0}"), $AADAuthUri)
}
if([string]::IsNullOrEmpty($AADTokenAudienceUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";AADTokenAudienceUri={0}"), $AADTokenAudienceUri)
}
if([string]::IsNullOrEmpty($GraphTokenAudienceUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";GraphTokenAudienceUri={0}"), $GraphTokenAudienceUri)
}
if([string]::IsNullOrEmpty($IbizaPortalUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";IbizaPortalUri={0}"), $IbizaPortalUri)
}
if([string]::IsNullOrEmpty($ServiceManagementUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";ServiceManagementUri={0}"), $ServiceManagementUri)
}
if([string]::IsNullOrEmpty($RdfePortalUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";RdfePortalUri={0}"), $RdfePortalUri)
}
if([string]::IsNullOrEmpty($GalleryUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";GalleryUri={0}"), $GalleryUri)
}
if([string]::IsNullOrEmpty($DataLakeStoreServiceUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";DataLakeStoreServiceUri={0}"), $DataLakeStoreServiceUri)
}
if([string]::IsNullOrEmpty($DataLakeAnalyticsJobAndCatalogServiceUri) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";DataLakeAnalyticsJobAndCatalogServiceUri={0}"), $DataLakeAnalyticsJobAndCatalogServiceUri)
}
#$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";BaseUri={0}"), $uris)
Write-Host "Below connection string is ready to be set"
#Print-ConnectionString $UserId $Password $SubscriptionId $TenantId $ServicePrincipal $ServicePrincipalSecret $RecordMode $TargetEnvironment $uris
Print-ConnectionString $UserId $Password $SubscriptionId $TenantId $ServicePrincipal $ServicePrincipalSecret $RecordMode $TargetEnvironment $uris $ResourceManagementUri $GraphUri $AADAuthUri $AADTokenAudienceUri $GraphTokenAudienceUri $IbizaPortalUri $ServiceManagementUri $RdfePortalUri $GalleryUri $DataLakeStoreServiceUri $DataLakeAnalyticsJobAndCatalogServiceUri
#Set connection string to Environment variable
$env:TEST_CSM_ORGID_AUTHENTICATION=$formattedConnStr
Write-Host ""
# Set AZURE_TEST_MODE
$env:AZURE_TEST_MODE=$RecordMode
# Retrieve the environment variable
Write-Host ""
Write-Host "Below connection string was set. Start Visual Studio by typing devenv" -ForegroundColor Green
[Environment]::GetEnvironmentVariable($envVariableName)
Write-Host ""
Write-Host "If your needs demand you to set connection string differently, for all the supported Key/Value pairs in connection string"
Write-Host "Please visit https://github.com/Azure/azure-powershell/blob/dev/documentation/Using-Azure-TestFramework.md" -ForegroundColor Yellow
}
Function Print-ConnectionString([string]$uid, [string]$pwd, [string]$subId, [string]$aadTenant, [string]$spn, [string]$spnSecret, [string]$recordMode, [string]$targetEnvironment, [string]$uris)
{
if([string]::IsNullOrEmpty($uid) -eq $false)
{
Write-Host "UserId=" -ForegroundColor Green -NoNewline
Write-Host $uid";" -NoNewline
}
if([string]::IsNullOrEmpty($pwd) -eq $false)
{
Write-Host "Password=" -ForegroundColor Green -NoNewline
Write-Host $pwd";" -NoNewline
}
if([string]::IsNullOrEmpty($subId) -eq $false)
{
Write-Host "SubscriptionId=" -ForegroundColor Green -NoNewline
Write-Host $subId";" -NoNewline
}
if([string]::IsNullOrEmpty($aadTenant) -eq $false)
{
Write-Host "AADTenant=" -ForegroundColor Green -NoNewline
Write-Host $aadTenant";" -NoNewline
}
if([string]::IsNullOrEmpty($spn) -eq $false)
{
Write-Host "ServicePrincipal=" -ForegroundColor Green -NoNewline
Write-Host $spn";" -NoNewline
}
if([string]::IsNullOrEmpty($spnSecret) -eq $false)
{
Write-Host "ServicePrincipalSecret=" -ForegroundColor Green -NoNewline
Write-Host $spnSecret";" -NoNewline
}
if([string]::IsNullOrEmpty($recordMode) -eq $false)
{
Write-Host "HttpRecorderMode=" -ForegroundColor Green -NoNewline
Write-Host $recordMode";" -NoNewline
}
if([string]::IsNullOrEmpty($targetEnvironment) -eq $false)
{
Write-Host "Environment=" -ForegroundColor Green -NoNewline
Write-Host $targetEnvironment";" -NoNewline
}
#========================================
if([string]::IsNullOrEmpty($ResourceManagementUri) -eq $false)
{
Write-Host "ResourceManagementUri=" -ForegroundColor Green -NoNewline
Write-Host $ResourceManagementUri";" -NoNewline
}
if([string]::IsNullOrEmpty($GraphUri) -eq $false)
{
Write-Host "GraphUri=" -ForegroundColor Green -NoNewline
Write-Host $GraphUri";" -NoNewline
}
if([string]::IsNullOrEmpty($AADTokenAudienceUri) -eq $false)
{
Write-Host "AADTokenAudienceUri=" -ForegroundColor Green -NoNewline
Write-Host $AADTokenAudienceUri";" -NoNewline
}
if([string]::IsNullOrEmpty($GraphTokenAudienceUri) -eq $false)
{
Write-Host "GraphTokenAudienceUri=" -ForegroundColor Green -NoNewline
Write-Host $GraphTokenAudienceUri -NoNewline
}
if([string]::IsNullOrEmpty($IbizaPortalUri) -eq $false)
{
Write-Host "IbizaPortalUri=" -ForegroundColor Green -NoNewline
Write-Host $IbizaPortalUri";" -NoNewline
}
if([string]::IsNullOrEmpty($ServiceManagementUri) -eq $false)
{
Write-Host "ServiceManagementUri=" -ForegroundColor Green -NoNewline
Write-Host $ServiceManagementUri";" -NoNewline
}
if([string]::IsNullOrEmpty($RdfePortalUri) -eq $false)
{
Write-Host "RdfePortalUri=" -ForegroundColor Green -NoNewline
Write-Host $RdfePortalUri";" -NoNewline
}
if([string]::IsNullOrEmpty($GalleryUri) -eq $false)
{
Write-Host "GalleryUri=" -ForegroundColor Green -NoNewline
Write-Host $GalleryUri";" -NoNewline
}
if([string]::IsNullOrEmpty($DataLakeStoreServiceUri) -eq $false)
{
Write-Host "DataLakeStoreServiceUri=" -ForegroundColor Green -NoNewline
Write-Host $DataLakeStoreServiceUri";" -NoNewline
}
if([string]::IsNullOrEmpty($DataLakeAnalyticsJobAndCatalogServiceUri) -eq $false)
{
Write-Host "DataLakeAnalyticsJobAndCatalogServiceUri=" -ForegroundColor Green -NoNewline
Write-Host $DataLakeAnalyticsJobAndCatalogServiceUri";" -NoNewline
}
Write-Host ""
}
[CmdletBinding]
Function Get-BuildScopes
{
<#
.SYNOPSIS
You can build a particular package rather than doing a full build by providing Build Scope.
This cmdlet will help to identify existing Scope available
This will enable to execute Start-RepoBuild <scope>
#>
Write-Host "Below are available scopes you can specify for building specific projects"
Write-Host ""
Get-ChildItem -path "$env:repoRoot\src\ResourceManagement" -dir | Format-Wide -Column 5 | Format-Table -Property Name
Write-Host "e.g of a scope would be 'ResourceManagement\Compute'" -ForegroundColor Yellow
Get-ChildItem -path "$env:repoRoot\src\" -dir -Exclude "ResourceManagement" | Format-Wide -Column 5 | Format-Table -Property Name
Write-Host "e.g of a scope would be 'Authentication'" -ForegroundColor Yellow
}
[CmdletBinding]
Function Start-Build
{
<#
.SYNOPSIS
This cmdlet will help to do either with full build or targeted build for specific scopes.
.PARAMETER BuildScope
Use Get-BuildScope cmdLet to get list of existing scopes that can be used to build
#>
param(
[parameter(Mandatory=$false, Position=0, HelpMessage='BuildScope that you would like to use. For list of build scopes, run List-BuildScopes')]
[string]$BuildScope
)
if([string]::IsNullOrEmpty($BuildScope) -eq $true)
{
Write-Host "Starting Full build"
msbuild.exe "$env:repoRoot\build.proj" /t:Build
}
else
{
Write-Host "Building $BuildScope"
msbuild.exe "$env:repoRoot\build.proj" /t:Build /p:Scope=$BuildScope
}
}
[CmdletBinding]
Function Invoke-CheckinTests
{
<#
.SYNOPSIS
Runs all the check in tests
#>
Write-Host "cmdline Args: msbuild.exe $env:repoRoot\build.proj /t:Test"
msbuild.exe "$env:repoRoot\build.proj" /t:Test
}
[cmdletBinding]
Function Install-VSProjectTemplates
{
<#
.SYNOPSIS
Install-VSProjectTemplates will install getting started project templates for
1) Autorest-.NET SDKProject
2) .NET SDK Test projectct
After executing the cmdlet, restart VS (if already open), create new project
Search for the project template as we install the following three project templates
AutoRest-AzureDotNetSDK
AzureDotNetSDK-TestProject
AzurePowerShell-TestProject
#>
msbuild.exe "$env:repoRoot\build.proj" /t:BuildProjectTemplates
if($env:VisualStudioVersion -eq "14.0")
{
$templateDirNames = Get-ChildItem "$env:repoRoot\tools\ProjectTemplates\" -Directory
foreach($dirName in $templateDirNames)
{
$templateFullPath = "$env:TEMP\$dirName.zip"
if((Test-Path $templateFullPath) -eq $true)
{
Write-Host "Installing '$dirName' template"
Copy-Item $templateFullPath "$env:USERPROFILE\Documents\Visual Studio 2015\Templates\ProjectTemplates\"
}
else
{
Write-Host "Missing templates to install, make sure you have project templates available in the repo under $env:repoRoot\tools\ProjectTemplates\"
}
}
Write-Host "Restart VS (if already open), search for 'AzureDotNetSDK'" -ForegroundColor Yellow
}
else
{
Write-Host "Unsupported VS Version detected. Visual Studio 2015 is the only supported version for current set of project templates"
}
}
<#
We allow users to include any helper powershell scripts they would like to include in the current session
Currently we support two ways to include helper powershell scripts
1) psuserspreferences environment variable
2) $env:USERPROFILE\psFiles directory
We will include all *.ps1 files from any of the above mentioned locations
#>
if([System.IO.Directory]::Exists($env:psuserpreferences))
{
$userPsFileDir = $env:psuserpreferences
}
elseif([System.IO.Directory]::Exists("$env:USERPROFILE\psFiles"))
{
$userPsFileDir = "$env:USERPROFILE\psFiles"
}
if([string]::IsNullOrEmpty($userPsFileDir) -eq $false)
{
Get-ChildItem $userPsFileDir | WHERE {$_.Name -like "*.ps1"} | ForEach {
Write-Host "Including $_" -ForegroundColor Green
. $userPsFileDir\$_
}
}
else
{
Write-Host "Loading skipped. 'psuserpreferences' environment variable was not set to load user preferences." -ForegroundColor DarkYellow
}
export-modulemember -Function Set-TestEnvironment
export-modulemember -Function Get-BuildScopes
export-modulemember -Function Start-Build
export-modulemember -Function Invoke-CheckinTests
export-modulemember -Function Install-VSProjectTemplates