fiftyone.geolocation 4.3.0 → 4.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/ci/build-and-test.yml +21 -0
  2. package/ci/common-ci/.github/labels.yml +80 -0
  3. package/ci/common-ci/.github/workflows/sync-labels.yml +52 -0
  4. package/ci/common-ci/CiTips.md +30 -1
  5. package/ci/common-ci/GitVersion.yml +18 -0
  6. package/ci/common-ci/README.md +155 -17
  7. package/ci/common-ci/build-and-test.yml +65 -0
  8. package/ci/common-ci/check-merge-commit-format.yml +56 -0
  9. package/ci/common-ci/cloud-release-config.json +51 -0
  10. package/ci/common-ci/create-tag.yml +41 -0
  11. package/ci/common-ci/deploy.yml +16 -2
  12. package/ci/common-ci/dotnet/shared-code-signing-steps.yml +20 -0
  13. package/ci/common-ci/dotnet/shared-extract-and-publish-packages.yml +29 -0
  14. package/ci/common-ci/go/shared-go-list-stage.yml +64 -0
  15. package/ci/common-ci/java/readme.md +22 -0
  16. package/ci/common-ci/java/shared-package-signing-steps.yml +17 -0
  17. package/ci/{shared-extract-and-publish-packages.yml → common-ci/node/shared-extract-and-publish-packages.yml} +7 -1
  18. package/ci/common-ci/php/readme.md +15 -0
  19. package/ci/common-ci/release-config-schema.json +52 -0
  20. package/ci/common-ci/release-config-template.json +310 -0
  21. package/ci/common-ci/release-config.json +89 -0
  22. package/ci/common-ci/release-process.drawio +165 -0
  23. package/ci/common-ci/release-process.png +0 -0
  24. package/ci/common-ci/scripts/azure/checkSlot.ps1 +28 -0
  25. package/ci/common-ci/scripts/modules/51DAuthorizationModule/51DAuthorizationModule.Tests.ps1 +1 -0
  26. package/ci/common-ci/scripts/modules/51DAuthorizationModule/51DAuthorizationModule.psm1 +16 -0
  27. package/ci/common-ci/scripts/modules/51DBuildModule/51DBuildModule.Tests.ps1 +3 -0
  28. package/ci/common-ci/scripts/modules/51DBuildModule/51DBuildModule.psm1 +200 -0
  29. package/ci/common-ci/scripts/modules/51DDeployModule/51DDeployModule.psm1 +66 -0
  30. package/ci/common-ci/scripts/modules/51DDownloadDataFileModule/51DDownloadDataFileModule.psm1 +74 -0
  31. package/ci/common-ci/scripts/modules/51DEnvironmentModule/51DEnvironmentModule.Tests.ps1 +25 -0
  32. package/ci/common-ci/scripts/modules/51DEnvironmentModule/51DEnvironmentModule.psm1 +22 -0
  33. package/ci/common-ci/scripts/modules/51DErrorHandleModule/51DErrorHandleModule.Tests.ps1 +1 -0
  34. package/ci/common-ci/scripts/modules/51DErrorHandleModule/51DErrorHandleModule.psm1 +41 -0
  35. package/ci/common-ci/scripts/modules/51DGitModule/51DGitModule.Tests.ps1 +5 -0
  36. package/ci/common-ci/scripts/modules/51DGitModule/51DGitModule.psm1 +702 -0
  37. package/ci/common-ci/scripts/modules/51DPackageModule/51DPackageModule.Tests.ps1 +842 -0
  38. package/ci/common-ci/scripts/modules/51DPackageModule/51DPackageModule.psm1 +926 -0
  39. package/ci/common-ci/scripts/modules/51DPipelineModule/51DPipelineModule.Tests.ps1 +1 -0
  40. package/ci/common-ci/scripts/modules/51DPipelineModule/51DPipelineModule.psm1 +87 -0
  41. package/ci/common-ci/scripts/modules/51DPullRequestModule/51DPullRequestModule.Tests.ps1 +194 -0
  42. package/ci/common-ci/scripts/modules/51DPullRequestModule/51DPullRequestModule.psm1 +653 -0
  43. package/ci/common-ci/scripts/modules/51DReleaseModule/51DReleaseModule.Tests.ps1 +277 -0
  44. package/ci/common-ci/scripts/modules/51DReleaseModule/51DReleaseModule.psm1 +554 -0
  45. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/51DReleaseTestEnvModule.Tests.ps1 +1141 -0
  46. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/51DReleaseTestEnvModule.psd1 +0 -0
  47. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/51DReleaseTestEnvModule.psm1 +1465 -0
  48. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ConfigurationVerifier.Tests.ps1 +318 -0
  49. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ConfigurationVerifier.psm1 +344 -0
  50. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ReleaseVerifier.Tests.ps1 +1186 -0
  51. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ReleaseVerifier.psm1 +900 -0
  52. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/SharedVariables.psm1 +139 -0
  53. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/c-test-env-config.json +268 -0
  54. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/dotnet-deploy-test-env-config.json +700 -0
  55. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/dotnet-test-env-config.json +533 -0
  56. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/go-deploy-test-env-config.json +290 -0
  57. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/go-test-env-config.json +260 -0
  58. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/java-deploy-test-env-config.json +511 -0
  59. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/java-test-env-config.json +388 -0
  60. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/node-deploy-test-env-config.json +419 -0
  61. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/node-test-env-config.json +329 -0
  62. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/php-test-env-config.json +540 -0
  63. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/python-deploy-test-env-config.json +411 -0
  64. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/python-test-env-config.json +321 -0
  65. package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/test-env-config.json +457 -0
  66. package/ci/common-ci/scripts/modules/51DRestModule/51DRestModule.psm1 +38 -0
  67. package/ci/common-ci/scripts/modules/AzurePortalModules/51DApplicationInsightsModule/51DApplicationInsightsModule.psm1 +104 -0
  68. package/ci/common-ci/scripts/modules/AzurePortalModules/51DChecksModule/51DChecksModule.psm1 +68 -0
  69. package/ci/common-ci/scripts/modules/AzurePortalModules/51DCloudModule/51DCloudModule.psm1 +155 -0
  70. package/ci/common-ci/scripts/modules/AzurePortalModules/51DConnectAzureModule/51DConnectAzureModule.psm1 +45 -0
  71. package/ci/common-ci/scripts/modules/AzurePortalModules/51DSSLBindingsModule/51DSSLBIndingsModule.psm1 +100 -0
  72. package/ci/common-ci/scripts/modules/AzurePortalModules/51DStagingSlotModule/51DStagingSlotModule.psm1 +50 -0
  73. package/ci/common-ci/scripts/modules/AzurePortalModules/51DStorageAccountModule/51DStorageAccountModule.psm1 +248 -0
  74. package/ci/common-ci/scripts/modules/AzurePortalModules/51DTrafficManagerModule/51DTrafficManagerModule.psm1 +58 -0
  75. package/ci/common-ci/shared-auto-complete-pr-stage.yml +61 -0
  76. package/ci/common-ci/shared-create-tag-job.yml +19 -30
  77. package/ci/common-ci/shared-docker-build-steps.yml +34 -0
  78. package/ci/common-ci/shared-docker-push-steps.yml +32 -0
  79. package/ci/common-ci/shared-docker-test-http-steps.yml +69 -0
  80. package/ci/common-ci/shared-git-tag-job.yml +38 -0
  81. package/ci/common-ci/shared-git-version-job.yml +71 -0
  82. package/ci/common-ci/shared-publish-github-stage.yml +69 -60
  83. package/ci/common-ci/shared-submodule-trigger-stage.yml +110 -0
  84. package/ci/common-ci/shared-variables.yml +3 -0
  85. package/ci/common-ci/trigger-release-apis.yml +39 -0
  86. package/ci/create-packages.yml +24 -36
  87. package/ci/deploy-external.yml +55 -0
  88. package/ci/{deploy.yml → deploy-internal.yml} +3 -29
  89. package/ci/shared-build-and-test-platforms.yml +7 -1
  90. package/ci/shared-build-and-test-stage.yml +9 -2
  91. package/ci/submodule-trigger.yml +12 -0
  92. package/examples/examples.test.js +3 -3
  93. package/geoLocationPipelineBuilder.js +13 -10
  94. package/package.json +11 -7
  95. package/setup.js +1 -0
@@ -0,0 +1,702 @@
1
+ <#
2
+ ===================== Git =====================
3
+ .Description
4
+ This module contains functions that perform Git
5
+ actions.
6
+ For more information, please read description of
7
+ each function.
8
+ #>
9
+
10
+ Using module 51DAuthorizationModule
11
+ Using module 51DEnvironmentModule
12
+
13
+ # This to redirect all stderr to stdout for git.
14
+ $env:GIT_REDIRECT_STDERR = '2>&1'
15
+
16
+ # For testing purpose only
17
+ $script:releaseConfig = $null
18
+ $script:repositories = $null
19
+
20
+ class GitHandler {
21
+ static [boolean]Checkout ([string]$branchName) {
22
+ Write-Host "# Checkout $branchName"
23
+ git checkout "$branchName"
24
+ return $?
25
+ }
26
+
27
+ static [boolean]CheckoutTrack ([string]$branchName) {
28
+ Write-Host "# Checkout track $branchName"
29
+ git checkout --track "$branchName"
30
+ return $?
31
+ }
32
+
33
+ static [boolean]CheckoutNew ([string]$branchName) {
34
+ Write-Host "# Checkout New $branchName"
35
+ git checkout -b "$branchName"
36
+ return $?
37
+ }
38
+
39
+ static [boolean]Pull () {
40
+ Write-Host "# Git pull"
41
+ git pull
42
+ return $?
43
+ }
44
+
45
+ static [boolean]FetchAllTags () {
46
+ Write-Host "# Fetch all tags"
47
+ # git -c http.extraheader="AUTHORIZATION: bearer $env:SYSTEM_ACCESSTOKEN" fetch --all --tags
48
+ git -c http.extraheader="AUTHORIZATION: $([Authorization]::AuthorizationString)" fetch --all --tags
49
+ return $?
50
+ }
51
+
52
+ static [boolean]Push ([string]$branchName) {
53
+ if ([string]::IsNullOrEmpty($branchName)) {
54
+ Write-Host "# Git Push $branchName to origin"
55
+ git -c http.extraheader="AUTHORIZATION: $([Authorization]::AuthorizationString)" push
56
+ } else {
57
+ Write-Host "# Git Push"
58
+ git -c http.extraheader="AUTHORIZATION: $([Authorization]::AuthorizationString)" push origin "$branchName"
59
+ }
60
+ return $?
61
+ }
62
+
63
+ static [boolean]Commit ([string]$message) {
64
+ Write-Host "# Git commit"
65
+ git commit -m "$message"
66
+ return $?
67
+ }
68
+
69
+ static [boolean]Config ([string]$email, [string]$name) {
70
+ Write-Host "# Git config email '$email' and name '$name'"
71
+ git config user.email "$email"
72
+ [boolean]$returnCode = $?
73
+ git config user.name "$name"
74
+ return $returnCode -and $?
75
+ }
76
+
77
+ static [boolean]Add ([string]$path) {
78
+ Write-Host "# Git stage '$path'"
79
+ git add "$path"
80
+ return $?
81
+ }
82
+
83
+ static [boolean]CheckoutWithAuthorization ([string]$branchName) {
84
+ Write-Host "# Checkout with authorization $branchName"
85
+ # git -c http.extraheader="AUTHORIZATION: bearer $env:SYSTEM_ACCESSTOKEN" checkout "$branchName"
86
+ git -c http.extraheader="AUTHORIZATION: $([Authorization]::AuthorizationString)" checkout "$branchName"
87
+ return $?
88
+ }
89
+
90
+ static [boolean]Clone ([string]$url) {
91
+ Write-Host "# Clone $url"
92
+ # git -c http.extraheader="AUTHORIZATION: Bearer $env:SYSTEM_ACCESSTOKEN" clone "$url"
93
+ git -c http.extraheader="AUTHORIZATION: $([Authorization]::AuthorizationString)" clone "$url"
94
+ return $?
95
+ }
96
+ }
97
+
98
+ <#
99
+ .Description
100
+ Initialise the script variables
101
+
102
+ .Parameter Configuration
103
+ A configuration object
104
+ #>
105
+ function Initialize-GlobalVariables {
106
+ param (
107
+ [Parameter(Mandatory)]
108
+ [object]$Configuration
109
+ )
110
+
111
+ # Obtain the config file content. Initialise the script variables
112
+ $script:releaseConfig = $Configuration
113
+ $script:repositories = $script:releaseConfig.repositories
114
+ Write-Host "# Init config: " + $script:releaseConfig
115
+ Write-Host "# Init repositories: " + $script:repositories
116
+ }
117
+
118
+ <#
119
+ .Description
120
+ Determine whether a release is a major release or a hotfix.
121
+
122
+ .Parameter Version
123
+ Version of a repository
124
+
125
+ .Outputs
126
+ Type of release
127
+ #>
128
+ function Get-ReleaseType {
129
+ param (
130
+ [string]$Version
131
+ )
132
+
133
+ # Determine if version is minor or major
134
+ $isMajor = $Version -match '\d+\.\d+\.0'
135
+
136
+ # Determine the target release/hotfix branch
137
+ if ($isMajor) {
138
+ $type = "release"
139
+ } else {
140
+ $type = "hotfix"
141
+ }
142
+ return $type
143
+ }
144
+
145
+ <#
146
+ .Description
147
+ Determine if a tag has been created
148
+ for a version of a repository.
149
+
150
+ .Parameter RepositoryName
151
+ Name of the repository
152
+
153
+ .Parameter Version
154
+ Release version of the repository
155
+
156
+ .Parameter TeamProjectName
157
+ Name ofthe repository team project
158
+
159
+ .Outputs
160
+ true or false
161
+ #>
162
+ function Test-TagExist {
163
+ param (
164
+ [Parameter(Mandatory)]
165
+ [string]$RepositoryName,
166
+ [Parameter(Mandatory)]
167
+ [string]$Version,
168
+ [Parameter(Mandatory)]
169
+ [string]$TeamProjectName
170
+ )
171
+
172
+ $url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/refs?api-version=6.0&filter=tags/$Version"
173
+
174
+ $response = Invoke-WebRequest `
175
+ -URI $url `
176
+ -Headers @{
177
+ Authorization = "$([Authorization]::AuthorizationString)"
178
+ } `
179
+ -Method GET
180
+
181
+ if ($(Test-RestResponse `
182
+ -Response $response `
183
+ -ErrorMessage "Failed to get all tags which started with $Version for $RepositoryName.")){
184
+ $content = $response.content | Out-String | ConvertFrom-Json
185
+ for ($i = 0; $i -le $content.value.count; $i++) {
186
+ if ($content.value[$i].name -match "$Version(\+\d+)?$") {
187
+ return $true
188
+ }
189
+ }
190
+ }
191
+ return $false
192
+ }
193
+
194
+ <#
195
+ .Description
196
+ Get the existing release branch.
197
+
198
+ .Parameter RepositoryName
199
+ Name of the repository
200
+
201
+ .Parameter Version
202
+ Target release version of the repository.
203
+
204
+ .Parameter TeamProjectName
205
+ Name ofthe repository team project
206
+
207
+ .Outputs
208
+ Full name of the release branch, prefixed with 'refs/heads' or $null if not found.
209
+ #>
210
+ function Get-ReleaseBranchRef {
211
+ param (
212
+ [Parameter(Mandatory)]
213
+ [string]$RepositoryName,
214
+ [Parameter(Mandatory)]
215
+ [string]$Version,
216
+ [Parameter(Mandatory)]
217
+ [string]$TeamProjectName
218
+ )
219
+
220
+ $releaseType = Get-ReleaseType -Version $Version
221
+
222
+ $url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/refs?api-version=6.0&filter=heads/$releaseType/"
223
+
224
+ $response = Invoke-WebRequest `
225
+ -URI $url `
226
+ -Headers @{
227
+ Authorization = "$([Authorization]::AuthorizationString)"
228
+ } `
229
+ -Method GET
230
+
231
+ if ($(Test-RestResponse `
232
+ -Response $response `
233
+ -ErrorMessage "Failed to get the list of existing branches for $RepositoryName.")){
234
+ $content = $response.content | Out-String | ConvertFrom-Json
235
+ for ($i = 0; $i -lt $content.value.count; $i++) {
236
+ if ($content.value[$i].name -match "refs/heads/$releaseType/(v)?$Version$") {
237
+ return $content.value[$i].name
238
+ }
239
+ }
240
+ }
241
+ return $null
242
+ }
243
+
244
+ <#
245
+ .Description
246
+ Construct a merge branch name from pull request Id.
247
+
248
+ .Parameter PullRequestId
249
+ Id number of a pull request
250
+
251
+ .Outputs
252
+ Full reference name of a merge branch.
253
+ #>
254
+ function Get-MergeBranchName {
255
+ param (
256
+ [int32]$PullRequestId
257
+ )
258
+ return "refs/pull/$PullRequestId/merge"
259
+ }
260
+
261
+ <#
262
+ .Description
263
+ Get the existing 'main' branch object based on Azure Devops Response.
264
+ It should be 'main' but can also be 'master' for older repositories.
265
+
266
+ .Parameter TeamProjectName
267
+ Name of a team project
268
+
269
+ .Parameter RepositoryName
270
+ Name of a repository
271
+
272
+ .Parameter AuthorizationHeader
273
+ Authorization Header that contain access token to the Azure Devops repositories
274
+
275
+ .Outputs
276
+ Branch object or $null.
277
+ #>
278
+ function Get-MainBranch {
279
+ param (
280
+ [Parameter(Mandatory)]
281
+ [string]$TeamProjectName,
282
+ [Parameter(Mandatory)]
283
+ [string]$RepositoryName,
284
+ [string]$AuthorizationHeader
285
+ )
286
+
287
+ if ([string]::IsNullOrEmpty($AuthorizationHeader)) {
288
+ $AuthorizationHeader = "$([Authorization]::AuthorizationString)"
289
+ }
290
+
291
+ $potentialNames = $("master", "main")
292
+ foreach ($name in $potentialNames) {
293
+ $url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/refs?filter=heads/$($name)&api-version=6.0-preview.1"
294
+
295
+ $response = Invoke-WebRequest `
296
+ -URI $url `
297
+ -Headers @{
298
+ Authorization = "$AuthorizationHeader"
299
+ } `
300
+ -Method GET
301
+
302
+ if ($(Test-RestResponse `
303
+ -Response $response `
304
+ -ErrorMessage "Failed to query the existence of the 'main' branch.")){
305
+ $content = $response.content | Out-String | ConvertFrom-Json
306
+ if ($content.value.count -eq 1) {
307
+ return $content.value[0]
308
+ }
309
+ }
310
+ }
311
+ return $null
312
+ }
313
+
314
+ <#
315
+ .Description
316
+ Get the existing 'main' branch reference. It should be 'main'
317
+ but can also be 'master' for older repositories.
318
+
319
+ .Parameter RepositoryName
320
+ Name of a repository
321
+
322
+ .Parameter TeamProjectName
323
+ Name ofthe repository team project
324
+
325
+ .Outputs
326
+ Full reference to the 'main' branch.
327
+ #>
328
+ function Get-MainBranchRef {
329
+ param (
330
+ [Parameter(Mandatory)]
331
+ [string]$RepositoryName,
332
+ [Parameter(Mandatory)]
333
+ [string]$TeamProjectName
334
+ )
335
+
336
+ $masterBranch = "master"
337
+ $url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$RepositoryName/refs?filter=heads/$masterBranch&api-version=6.0-preview.1"
338
+
339
+ $response = Invoke-WebRequest `
340
+ -URI $url `
341
+ -Headers @{
342
+ Authorization = "$([Authorization]::AuthorizationString)"
343
+ } `
344
+ -Method GET
345
+
346
+ if ($(Test-RestResponse `
347
+ -Response $response `
348
+ -ErrorMessage "Failed to query the existence of the 'main' branch.")){
349
+ $content = $response.content | Out-String | ConvertFrom-Json
350
+ if ($content.value.count -eq 1) {
351
+ return "refs/heads/$masterBranch"
352
+ }
353
+ }
354
+ return "refs/heads/main"
355
+ }
356
+
357
+ <#
358
+ .Description
359
+ Get the remote Url to clone the repository.
360
+
361
+ .Parameter RepositoryName
362
+ Name of the repository
363
+
364
+ .Parameter TeamProjectName
365
+ Name ofthe repository team project
366
+
367
+ .Outputs
368
+ Remote Url or $null if not found.
369
+ #>
370
+ function Get-RepositoryRemoteUrl {
371
+ param (
372
+ [Parameter(Mandatory)]
373
+ [string]$RepositoryName,
374
+ [Parameter(Mandatory)]
375
+ [string]$TeamProjectName
376
+ )
377
+
378
+ $url = "$([EnvironmentHandler]::GetEnvironmentVariable($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI))$($TeamProjectName)/_apis/git/repositories/$($RepositoryName)?api-version=6.0"
379
+
380
+ $response = Invoke-WebRequest `
381
+ -URI $url `
382
+ -Headers @{
383
+ Authorization = "$([Authorization]::AuthorizationString)"
384
+ } `
385
+ -Method GET
386
+
387
+ if ($(Test-RestResponse `
388
+ -Response $response `
389
+ -ErrorMessage "Failed to query repository $RepositoryName.")){
390
+ $content = $response.content | Out-String | ConvertFrom-Json
391
+ return $content.remoteUrl
392
+ }
393
+ return $null
394
+ }
395
+
396
+ <#
397
+ .Description
398
+ Extract the submodule path from a git submodule entry.
399
+
400
+ .Parameter GitSubmodulePath
401
+ A git submodule entry.
402
+
403
+ .Outputs
404
+ A submodule path or $null if the submodule entry does not conform
405
+ the standard format.
406
+ #>
407
+ function Find-SubmodulePath {
408
+ param (
409
+ [string]$GitSubmodulePath
410
+ )
411
+
412
+ if ($GitSubmodulePath -match "submodule\.(?<content>(.)+)\.path") {
413
+ return $Matches['content']
414
+ }
415
+ return $null
416
+ }
417
+
418
+ <#
419
+ .Description
420
+ Determine the target branch to be assessed.
421
+
422
+ .Parameter Version
423
+ The version of a repository
424
+
425
+ .Outputs
426
+ Target branch without 'refs/heads'.
427
+ #>
428
+ function Get-TargetBranch {
429
+ param (
430
+ [string]$Version
431
+ )
432
+
433
+ $releaseType = Get-ReleaseType -Version $Version
434
+
435
+ # Determine whether the name should contains 'v' or not.
436
+ $remoteRepo = git config --get remote.origin.url
437
+ if (!$(git ls-remote $remoteRepo "refs/heads/$releaseType/$Version") -eq $null) {
438
+ return $releaseType + "/" + $Version
439
+ }
440
+ return $releaseType + "/v" + $Version
441
+ }
442
+
443
+ <#
444
+ .Description
445
+ Get the repository name of current branch.
446
+
447
+ .Outputs
448
+ Repo name or $null if not found.
449
+ #>
450
+ function Get-RepositoryName {
451
+ $remoteUrl = git config --get remote.origin.url
452
+ if ($remoteUrl -match ".*/(?<content>((?!/).)*)") {
453
+ return $Matches['content']
454
+ }
455
+ return $null
456
+ }
457
+
458
+ <#
459
+ .Description
460
+ Check if a branch exist in the remote repository.
461
+ This run on the current git directory.
462
+
463
+ .Parameter Branch
464
+ Name of the branch.
465
+
466
+ .Outputs true or false
467
+ #>
468
+ function Test-BranchExistRemotely {
469
+ param (
470
+ [string]$Branch
471
+ )
472
+
473
+ $remoteRepo = git config --get remote.origin.url
474
+ $exists = $false
475
+ if ($(git ls-remote $remoteRepo "refs/heads/$Branch") -ne $null) {
476
+ $exists = $true
477
+ }
478
+ return $exists
479
+ }
480
+
481
+ <#
482
+ .Description
483
+ Check out a release branch based on the detail in the release config file.
484
+ If no release is required, return false.
485
+
486
+ .Parameter Version
487
+ Version to release
488
+
489
+ .Parameter TeamProjectName
490
+ Name ofthe repository team project
491
+
492
+ .Outputs
493
+ true or false
494
+ #>
495
+ function Get-ReleaseBranch {
496
+ param (
497
+ [Parameter(Mandatory)]
498
+ [string]$Version,
499
+ [Parameter(Mandatory)]
500
+ [string]$TeamProjectName
501
+ )
502
+
503
+ # Check if the release/hotfix branch exist. Create if it doesn't.
504
+ Write-Host ""
505
+ Write-Host "Verify release/hotfix branch existance"
506
+ Write-Host "================"
507
+ $targetBranch = Get-TargetBranch -Version $Version
508
+ $remoteRepo = git config --get remote.origin.url
509
+ if ($(git ls-remote $remoteRepo "refs/heads/$targetBranch") -eq $null) {
510
+ Write-Host "# No $targetBranch exists. Create one."
511
+ $repoName = Get-RepositoryName
512
+ $mainBranchRef = Get-MainBranchRef `
513
+ -RepositoryName $repoName `
514
+ -TeamProjectName $TeamProjectName
515
+ if ($mainBranchRef -eq $null) {
516
+ Write-Host "ERROR: No main branch found."
517
+ return $false
518
+ }
519
+ $mainBranchRef -match "refs/heads/(?<name>(master|main))"
520
+ $mainBranchName = $Matches['name']
521
+
522
+ if (![GitHandler]::Checkout($mainBranchName)) {
523
+ if (![GitHandler]::CheckoutTrack("origin/$mainBranchName")) {
524
+ Write-Host "# ERROR: Failed to checkout $mainBranchRef"
525
+ return $false
526
+ }
527
+ }
528
+ if (![GitHandler]::Pull()) {
529
+ Write-Host "# ERROR: Failed to get the latest version of the main branch $mainBranchRef"
530
+ return $false
531
+ }
532
+
533
+ if (![GitHandler]::CheckoutNew($targetBranch)) {
534
+ Write-Host "# ERROR: Failed to create target release branch $targetBranch"
535
+ $false
536
+ }
537
+ } else {
538
+ Write-Host "# $targetBranch exists. Checkout."
539
+ if (![GitHandler]::CheckoutTrack("origin/$targetBranch")) {
540
+ if (![GitHandler]::Checkout($targetBranch)) {
541
+ Write-Host "# ERROR: Failed to checkout target release branch $targetBranch"
542
+ return $false
543
+ }
544
+ }
545
+ if (![GitHandler]::Pull()) {
546
+ Write-Host "# ERROR: Failed to get the latest version of target release branch $targetBranch"
547
+ return $false
548
+ }
549
+ }
550
+ Write-Host "# OK"
551
+ return $true
552
+ }
553
+
554
+ <#
555
+ .Description
556
+ Update all submodule references of a current git directory.
557
+ This will run on the current directory.
558
+
559
+ .Parameter Configuration
560
+ A Configuration object
561
+
562
+ .Outputs
563
+ true or false.
564
+ #>
565
+ function Update-SubmoduleReferences {
566
+ param (
567
+ [Parameter(Mandatory)]
568
+ [object]$Configuration
569
+ )
570
+
571
+ # Load the configuration into script variables.
572
+ Initialize-GlobalVariables -Configuration $Configuration
573
+
574
+ # Check if all submodules have been deployed
575
+ Write-Host ""
576
+ Write-Host "Update all submodules"
577
+ Write-Host "================"
578
+ foreach ($submodule in $(git config --file .gitmodules --name-only --get-regexp path)) {
579
+ Write-Host ""
580
+ Write-Host "# Process submodule path $submodulePath."
581
+ $submodulePath = Find-SubmodulePath -GitSubmodulePath $submodule
582
+ if ($submodulePath -ne $null) {
583
+ Write-Host "# Path $submodulePath extracted."
584
+ Push-Location $submodulePath
585
+
586
+ # Get repo name
587
+ $subRepoName = Get-RepositoryName
588
+ Write-Host "# Processing module $subRepoName."
589
+
590
+ # Check and update the submodule to the correct tag.
591
+ $targetTag = $script:repositories."$subRepoName".version
592
+ Write-Host "# Checking tag $targetTag"
593
+
594
+ $tagUpdated = $false
595
+ $targetSpecified = $null -ne $targetTag
596
+
597
+ if ($targetSpecified) {
598
+ # Get all tag
599
+ Write-Host "# Fetch all tags"
600
+ if (![GitHandler]::FetchAllTags()) {
601
+ Write-Host "# ERROR: Failed to fetch tags. Cannot reliably check submodule deployment."
602
+ Pop-Location
603
+ return $false
604
+ }
605
+
606
+ $remoteRepo = git -c http.extraheader="AUTHORIZATION: $([Authorization]::AuthorizationString)" config --get remote.origin.url
607
+ Write-Host "# Remote repository found '$remoteRepo'"
608
+ # Make sure to sort the tag, so only pick up the biggest tag.
609
+ # e.g. If 4.3.0 and 4.3.0+1 then pick the later.
610
+ foreach ($tag in $(git -c http.extraheader="AUTHORIZATION: $([Authorization]::AuthorizationString)" ls-remote --tags --sort=-v:refname $remoteRepo "$($targetTag)*")) {
611
+ Write-Host "# Check tag '$tag' against target tag '$targetTag'"
612
+ # By presorted the tags, the first only that match the tag format will be the latest one.
613
+ if ($tag -match ".*/(?<content>$targetTag(\+(\d)+)?)$") {
614
+ Write-Host "# Tag $targetTag found with value $($Matches['content']). The submodule has been been deployed."
615
+
616
+ if (![GitHandler]::CheckoutWithAuthorization("tags/$($Matches['content'])")) {
617
+ Write-Host "# ERROR: Failed to checkout the tag $($Matches['content'])."
618
+ break
619
+ }
620
+
621
+ $tagUpdated = $true
622
+ break
623
+ }
624
+ }
625
+ } else {
626
+ # If no version is found from the configuration file.
627
+ # Treat it as nothing to be changed for this submodule.
628
+ Write-Host "# No target version has been specified for $subRepoName. No update required."
629
+ $tagUpdated = $true
630
+ }
631
+
632
+ Pop-Location
633
+
634
+ if($targetSpecified) {
635
+ # Exit if not all tags have been found.
636
+ if (!$tagUpdated) {
637
+ Write-Host "# ERROR: Failed to update Submodule $subRepoName to tag $targetTag."
638
+ return $false
639
+ }
640
+
641
+ # Stage the submodule update
642
+ Write-Host "# Stage the submodule $submodulePath"
643
+ if (![GitHandler]::Add($submodulePath)) {
644
+ Write-Host "# ERROR: Failed to stage the submodule $subRepoName."
645
+ return $false
646
+ }
647
+ }
648
+ } else {
649
+ Write-Host "# ERROR: Failed to extract module path from $submodulePath"
650
+ return $false
651
+ }
652
+ }
653
+
654
+ Write-Host "# OK"
655
+ return $true
656
+ }
657
+
658
+ <#
659
+ .Description
660
+ Commit any staged changes and push to remote repository.
661
+
662
+ .Outputs
663
+ true or false
664
+ #>
665
+ function Start-CommitAndPush {
666
+ # Commit changes
667
+ Write-Host ""
668
+ Write-Host "# Commit and push staged changes."
669
+ Write-Host "================"
670
+ $branchName = git rev-parse --abbrev-ref HEAD
671
+ $existingBranch = Test-BranchExistRemotely -Branch $branchName
672
+ if (![GitHandler]::Config("ciuser@51degrees.com", "CIUser")) {
673
+ Write-Host "# ERROR: Failed to configure email and user name"
674
+ return $false
675
+ }
676
+
677
+ if ($(git diff --cached --name-only).count -gt 0 ) {
678
+ Write-Host "# There are changes. Commit now."
679
+ if (![GitHandler]::Commit("REF: Update submodules references.")) {
680
+ Write-Host "# ERROR: Failed to commit the submodules updates."
681
+ return $false
682
+ }
683
+
684
+ # Push changes
685
+ Write-Host "# Push the changes."
686
+ [boolean]$rc = $false
687
+ if (!$existingBranch) {
688
+ git -c http.extraheader="AUTHORIZATION: $([Authorization]::AuthorizationString)" push origin "$branchName"
689
+ $rc = [GitHandler]::Push("$branchName")
690
+ } else {
691
+ $rc = [GitHandler]::Push($null)
692
+ }
693
+
694
+ if (!$rc) {
695
+ Write-Host "# ERROR: Failed to push changes."
696
+ return $false
697
+ }
698
+ } else {
699
+ Write-Host "# There is nothing to commit."
700
+ }
701
+ return $true
702
+ }