fiftyone.geolocation 4.4.1 → 4.4.3

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