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,926 @@
1
+ <#
2
+ ===================== Packages =====================
3
+ .Description
4
+ This module contains functions that perform actions
5
+ on managing packages.
6
+ For more information, please read description of
7
+ each function.
8
+ #>
9
+
10
+ Using module 51DGitModule
11
+
12
+ # Global variables to be updated when one of the main APIs is called.
13
+ $script:releaseConfig = $null
14
+ $script:repositories = $null
15
+
16
+ class FileHandler {
17
+ static [boolean]SetContent([string]$target, [string]$value) {
18
+ Set-Content -NoNewline "$target" -Value $value
19
+ return $?
20
+ }
21
+ }
22
+
23
+ <#
24
+ .Description
25
+ Initialise the script variables
26
+
27
+ .Parameter Configuration
28
+ A Configuration object
29
+ #>
30
+ function Initialize-GlobalVariables {
31
+ param (
32
+ [Parameter(Mandatory)]
33
+ [object]$Configuration
34
+ )
35
+
36
+ # Obtain the config file content. Initialise the script variables
37
+ $script:releaseConfig = $Configuration
38
+ $script:repositories = $script:releaseConfig.repositories
39
+ Write-Host "# Init config: " + $script:releaseConfig
40
+ Write-Host "# Init repositories: " + $script:repositories
41
+ }
42
+
43
+ <#
44
+ .Description
45
+ Update the pom.xml content with dependency version.
46
+
47
+ .Parameter Dependencies
48
+ An array of dependencies of the current repository
49
+
50
+ .Parameter PomContent
51
+ Content of the pom.xml to be updated.
52
+
53
+ .Parameter TeamProjectName
54
+ Name ofthe repository team project
55
+
56
+ .Outputs
57
+ Updated content or $null of error occurs.
58
+ #>
59
+ function Update-MavenPackageFileContent {
60
+ param (
61
+ [Parameter(Mandatory)]
62
+ [string[]]$Dependencies,
63
+ [Parameter(Mandatory)]
64
+ [string]$PomContent,
65
+ [Parameter(Mandatory)]
66
+ [string]$TeamProjectName
67
+ )
68
+ Write-Host "Pom content $PomContent"
69
+ foreach ($dependency in $Dependencies) {
70
+ $versionVariableName = $script:repositories."$dependency".versionVariableName
71
+ Write-Host "Version variable: " $versionVariableName
72
+ if ([string]::IsNullOrEmpty($versionVariableName)) { continue }
73
+ if ($PomContent -match "\<$versionVariableName\>") {
74
+ Write-Host "# Version variable matches dependency $versionVariableName. Update."
75
+ $dependencyVersion = $script:repositories."$dependency".version
76
+
77
+ # Make sure that the version exists for the dependency. Else bail out.
78
+ if (!$(Test-TagExist `
79
+ -RepositoryName $dependency `
80
+ -Version $dependencyVersion `
81
+ -TeamProjectName $TeamProjectName)) {
82
+ Write-Host "# ERROR: Tag $dependencyVersion for repository $dependency does not exist."
83
+ return $null
84
+ }
85
+
86
+ $PomContent = $PomContent -replace `
87
+ "\<$versionVariableName\>.*\</$versionVariableName\>", `
88
+ "<$versionVariableName>$dependencyVersion</$versionVariableName>"
89
+ } else {
90
+ Write-Host "# Nothing to update for dependency $versionVariableName"
91
+ }
92
+ }
93
+ return $PomContent
94
+ }
95
+
96
+ <#
97
+ .Description
98
+ Update dependencies of all Maven packages in a repository.
99
+
100
+ .Parameter RepositoryName
101
+ Name of a repository
102
+
103
+ .Parameter TeamProjectName
104
+ Name ofthe repository team project
105
+
106
+ .Outputs
107
+ true or false
108
+ #>
109
+ function Update-MavenPackageDependencies {
110
+ param (
111
+ [Parameter(Mandatory)]
112
+ [string]$RepositoryName,
113
+ [Parameter(Mandatory)]
114
+ [string]$TeamProjectName
115
+ )
116
+
117
+ Write-Host ""
118
+ Write-Host "Update Maven Package Dependencies"
119
+ Write-Host "================================="
120
+
121
+ $dependencies = $script:repositories."$RepositoryName".dependencies
122
+ if ($dependencies -ne $null -and $dependencies.count -gt 0) {
123
+ # Check if pom.xml exists
124
+ if (Test-Path pom.xml) {
125
+ $pomContent = $(Get-Content pom.xml -Raw)
126
+ $updatedContent = Update-MavenPackageFileContent `
127
+ -Dependencies $dependencies `
128
+ -PomContent $pomContent `
129
+ -TeamProjectName $TeamProjectName
130
+
131
+ # Check if pom has been updated.
132
+ if ($updatedContent -ne $null) {
133
+ if ($updatedContent -ne $pomContent) {
134
+ Write-Host "# Dependency version has been updated. Update the pom.xml content."
135
+ if (![FileHandler]::SetContent("pom.xml", $updatedContent)) {
136
+ Write-Host "# ERROR: Failed to update the pom.xml content."
137
+ return $false
138
+ }
139
+
140
+ # Stage the change
141
+ if (![GitHandler]::Add("pom.xml")) {
142
+ Write-Host "# ERROR: Failed to stage the change."
143
+ return $false
144
+ }
145
+ }
146
+ } else {
147
+ Write-Host "# ERROR: error occurs while updating the content of pom.xml"
148
+ return $false
149
+ }
150
+ } else {
151
+ Write-Host "# ERROR: No pom file is found at this directory. Nothing to update."
152
+ return $false
153
+ }
154
+ } else {
155
+ Write-Host "# There is no dependencies defined in configuration file. Skipped."
156
+ }
157
+
158
+ return $true
159
+ }
160
+
161
+ <#
162
+ .Description
163
+ Update dotnet package file content.
164
+
165
+ .Parameter Dependencies
166
+ A list of dependencies of the project that package file belongs to.
167
+
168
+ .Parameter ProjectFileContent
169
+ Content to be update of a project file.
170
+
171
+ .Parameter TeamProjectName
172
+ Name ofthe repository team project
173
+
174
+ .Parameter IsPackagesConfig
175
+ If the current package is packages.config which requires different treatment.
176
+
177
+ .Outputs
178
+ Updated file content or $null of error occured
179
+ #>
180
+ function Update-DotnetPackageFileContent {
181
+ param (
182
+ [Parameter(Mandatory)]
183
+ [string[]]$Dependencies,
184
+ [Parameter(Mandatory)]
185
+ [string]$ProjectFileContent,
186
+ [Parameter(Mandatory)]
187
+ [string]$TeamProjectName,
188
+ [Parameter(Mandatory)]
189
+ [boolean]$IsPackagesConfig
190
+ )
191
+ # Update each .csproj file with dependency versions.
192
+ foreach ($dependency in $Dependencies) {
193
+ $packageName = $script:repositories."$dependency".packageName
194
+ if ([string]::IsNullOrEmpty($packageName)) { continue }
195
+ # Version 1 of xml markup for <PackageReference/>
196
+ # This pattern has a match group names 'prefix' and 'suffix'.
197
+ # That will be used to preserv the remaining of the markup,
198
+ # apart from the version which will be updated.
199
+ $dependencyVersion = $script:repositories."$dependency".version
200
+
201
+ if ($IsPackagesConfig) {
202
+ $matchPattern = "(?<prefix>\<package \s*id=\`"$packageName.*\`" \s*version=\`").*(?<suffix>\`"\s*targetFramework=\`".*\`"\s*/\>)"
203
+ if ($ProjectFileContent -match "$matchPattern") {
204
+ Write-Host "# Version variable matches dependency $packageName. Update."
205
+
206
+ # Make sure that the version exists for the dependency. Else bail out.
207
+ if (!$(Test-TagExist `
208
+ -RepositoryName $dependency `
209
+ -Version $dependencyVersion `
210
+ -TeamProjectName $TeamProjectName)) {
211
+ Write-Host "# ERROR: Tag $dependencyVersion for repository $dependency does not exist."
212
+ return $null
213
+ }
214
+
215
+ # This reuse the matched group so make sure we don't lose the original package name.
216
+ $replaceString = '${prefix}' + "$dependencyVersion" + '${suffix}'
217
+ $ProjectFileContent = $ProjectFileContent -replace "$matchPattern",$replaceString
218
+ }
219
+ } else {
220
+ $matchPattern = "(?<prefix>\<PackageReference \s*Include=\`"$packageName.*\`" \s*Version=\`").*(?<suffix>\`"\s*/\>)"
221
+ if ($ProjectFileContent -match "$matchPattern") {
222
+ Write-Host "# Version variable matches dependency $packageName. Update."
223
+
224
+ # Make sure that the version exists for the dependency. Else bail out.
225
+ if (!$(Test-TagExist `
226
+ -RepositoryName $dependency `
227
+ -Version $dependencyVersion `
228
+ -TeamProjectName $TeamProjectName)) {
229
+ Write-Host "# ERROR: Tag $dependencyVersion for repository $dependency does not exist."
230
+ return $null
231
+ }
232
+
233
+ # This reuse the matched group so make sure we don't lose the original package name.
234
+ $replaceString = '${prefix}' + "$dependencyVersion" + '${suffix}'
235
+ $ProjectFileContent = $ProjectFileContent -replace "$matchPattern",$replaceString
236
+ }
237
+
238
+ # Version 2 of xml markup for <PackageReference></PackageReference>
239
+ $matchPattern = "(?<prefix>\<PackageReference \s*Include=\`"$packageName.*\`"\s*\>.*\r\n.*\<Version\>)(?<version>.*)(?<suffix>\</Version\>.*\r\n.*\</PackageReference\>)"
240
+ if ($ProjectFileContent -match "$matchPattern") {
241
+ Write-Host "# Version variable matches dependency $packageName. Update."
242
+
243
+ # Make sure that the version exists for the dependency. Else bail out.
244
+ if (!$(Test-TagExist `
245
+ -RepositoryName $dependency `
246
+ -Version $dependencyVersion `
247
+ -TeamProjectName $TeamProjectName)) {
248
+ Write-Host "# ERROR: Tag $dependencyVersion for repository $dependency does not exist."
249
+ return $null
250
+ }
251
+
252
+ # This reuse the matched group so make sure we don't lose the original package name.
253
+ $replaceString = '${prefix}' + "$dependencyVersion" + '${suffix}'
254
+ $ProjectFileContent = $ProjectFileContent -replace "$matchPattern",$replaceString
255
+ }
256
+
257
+ # If HintPath exists. This is when a project is a .Net Framework. Update the Hint Path.
258
+ $matchPattern = "(?<prefix>\<HintPath\>\s*.*$packageName.*)\d+\.\d+\.\d+.*(?<suffix>\\lib.*\<\/HintPath\>)"
259
+ if ($ProjectFileContent -match "$matchPattern") {
260
+ Write-Host "# Version variable matches dependency $packageName. Update."
261
+
262
+ # Make sure that the version exists for the dependency. Else bail out.
263
+ if (!$(Test-TagExist `
264
+ -RepositoryName $dependency `
265
+ -Version $dependencyVersion `
266
+ -TeamProjectName $TeamProjectName)) {
267
+ Write-Host "# ERROR: Tag $dependencyVersion for repository $dependency does not exist."
268
+ return $null
269
+ }
270
+
271
+ # This reuse the matched group so make sure we don't lose the original package name.
272
+ $replaceString = '${prefix}' + "$dependencyVersion" + '${suffix}'
273
+ $ProjectFileContent = $ProjectFileContent -replace "$matchPattern",$replaceString
274
+ }
275
+ }
276
+ }
277
+ return $ProjectFileContent
278
+ }
279
+
280
+ <#
281
+ .Description
282
+ Update package dependencies for a package file
283
+ which can be .csproj or packages.config file.
284
+
285
+ .Parameter FilePath
286
+ Path to a package file
287
+
288
+ .Parameter Dependencies
289
+ List of dependencies to be updated
290
+
291
+ .Parameter TeamProjectName
292
+ Name of a Team Project that the changes should be
293
+ made to.
294
+
295
+ .Outputs
296
+ true or false
297
+ #>
298
+ function Update-DotnetPackageDependenciesPerFile {
299
+ param (
300
+ [Parameter(Mandatory)]
301
+ [string]$FilePath,
302
+ [Parameter(Mandatory)]
303
+ [string[]]$Dependencies,
304
+ [Parameter(Mandatory)]
305
+ [string]$TeamProjectName
306
+ )
307
+ Write-Host ""
308
+ Write-Host "# Updating package file $FilePath"
309
+ $projFileContent = $(Get-Content $FilePath -Raw)
310
+ $isPackagesConfig = $FilePath -match ".*packages.config"
311
+ $updatedContent = Update-DotnetPackageFileContent `
312
+ -Dependencies $Dependencies `
313
+ -ProjectFileContent $projFileContent `
314
+ -TeamProjectName $TeamProjectName `
315
+ -IsPackagesConfig $isPackagesConfig
316
+
317
+ # Check if content has been updated.
318
+ if ($updatedContent -ne $null) {
319
+ if ($updatedContent -ne $projFileContent) {
320
+ Write-Host "# Dependency version has been updated. Update the $FilePath content."
321
+ if (![FileHandler]::SetContent($FilePath, $updatedContent)) {
322
+ Write-Host "# ERROR: Failed to update the $FilePath content."
323
+ return $false
324
+ }
325
+
326
+ # Stage the change
327
+ if (![GitHandler]::Add("$FilePath")) {
328
+ Write-Host "# ERROR: Failed to stage the change."
329
+ return $false
330
+ }
331
+ }
332
+ } else {
333
+ Write-Host "# ERROR: error occurs while updating content of package file."
334
+ return $false
335
+ }
336
+ return $true
337
+ }
338
+
339
+ <#
340
+ .Description
341
+ Update dependencies of all Dotnet packages in a repository.
342
+
343
+ .Parameter RepositoryName
344
+ Name of a repository
345
+
346
+ .Parameter TeamProjectName
347
+ Name ofthe repository team project
348
+
349
+ .Outputs
350
+ true or false
351
+ #>
352
+ function Update-DotnetPackageDependencies {
353
+ param (
354
+ [Parameter(Mandatory)]
355
+ [string]$RepositoryName,
356
+ [Parameter(Mandatory)]
357
+ [string]$TeamProjectName
358
+ )
359
+
360
+ Write-Host ""
361
+ Write-Host "Update Dotnet Package Dependencies"
362
+ Write-Host "================================="
363
+
364
+ $dependencies = $script:repositories."$RepositoryName".dependencies
365
+ # Make sure only update if there are dependencies
366
+ if ($dependencies -ne $null -and $dependencies.count -gt 0) {
367
+ # Update each .csproj file.
368
+ foreach ($project in $(Get-ChildItem -Filter *.csproj -Recurse)) {
369
+ if (!$(Update-DotnetPackageDependenciesPerFile `
370
+ -FilePath $project.FullName `
371
+ -Dependencies $dependencies `
372
+ -TeamProjectName $TeamProjectName)) {
373
+ Write-Host "# ERROR: Failed to update package file $($project.FullName)"
374
+ return $false
375
+ }
376
+ }
377
+
378
+ # Update each packages.config file.
379
+ foreach ($project in $(Get-ChildItem -Filter packages.config -Recurse)) {
380
+ if (!$(Update-DotnetPackageDependenciesPerFile `
381
+ -FilePath $project.FullName `
382
+ -Dependencies $dependencies `
383
+ -TeamProjectName $TeamProjectName)) {
384
+ Write-Host "# ERROR: Failed to update package file $($project.FullName)"
385
+ return $false
386
+ }
387
+ }
388
+ } else {
389
+ Write-Host "# There is no dependencies defined in configuration file. Skipped."
390
+ }
391
+
392
+ return $true
393
+ }
394
+
395
+ <#
396
+ .Description
397
+ Take a package file content and update the input repository version.
398
+
399
+ .Parameter RepositoryName
400
+ Name of the dependency to update
401
+
402
+ .Parameter PackageFileContent
403
+ Content of the package file to update
404
+
405
+ .Parameter IsRemotePackage
406
+ Whether the current package file is remote_package.json.
407
+
408
+ .Parameter TeamProjectName
409
+ Name ofthe repository team project
410
+
411
+ .Outputs
412
+ Updated file content. $null if something goes wrong.
413
+ #>
414
+ function Update-NodePackageDependency {
415
+ param (
416
+ [Parameter(Mandatory)]
417
+ [string]$RepositoryName,
418
+ [Parameter(Mandatory)]
419
+ [string]$PackageFileContent,
420
+ [Parameter(Mandatory)]
421
+ [boolean]$IsRemotePackage,
422
+ [Parameter(Mandatory)]
423
+ [string]$TeamProjectName
424
+ )
425
+ $packageName = $script:repositories."$RepositoryName".packageName
426
+ if ([string]::IsNullOrEmpty($packageName)) { return $PackageFileContent }
427
+ # This pattern has a match group name 'name'. That will be used to preserve the actual matched package name.
428
+ $matchPattern = "\`"(?<name>$packageName(\.[A-Za-z]+)*)\`"\s*:\s*\`".*\`""
429
+ if ($PackageFileContent -match "$matchPattern") {
430
+ Write-Host "# Version variable matches dependency $packageName. Try to update."
431
+ $dependencyVersion = $script:repositories."$RepositoryName".version
432
+ # Make sure that the version exists for the dependency. Else bail out.
433
+ if (!$IsRemotePackage -and
434
+ !$(Test-TagExist `
435
+ -RepositoryName $RepositoryName `
436
+ -Version $dependencyVersion `
437
+ -TeamProjectName $TeamProjectName)) {
438
+ Write-Host "# ERROR: Tag $dependencyVersion for repository $RepositoryName does not exist."
439
+ return $null
440
+ }
441
+
442
+ # This reuse the matched group so make sure we don't lose the original package name.
443
+ $replaceString = '"${name}": "^' + $dependencyVersion + '"'
444
+ $PackageFileContent = $PackageFileContent -replace "$matchPattern",$replaceString
445
+ } else {
446
+ Write-Host "# Nothing to update for dependency $packageName"
447
+ }
448
+ return $PackageFileContent
449
+ }
450
+
451
+ <#
452
+ .Description
453
+ Update a package file with a input list of dependencies.
454
+
455
+ .Parameter RepositoryName
456
+ Name of the current repository
457
+
458
+ .Parameter dependencies
459
+ List of dependencies obtained from configration file.
460
+
461
+ .Parameter PackageFileName
462
+ Name of the package file
463
+
464
+ .Parameter TeamProjectName
465
+ Name ofthe repository team project
466
+
467
+ .Outputs
468
+ true or false
469
+ #>
470
+ function Update-NodeDependenciesSub {
471
+ param (
472
+ [Parameter(Mandatory)]
473
+ [string]$RepositoryName,
474
+ [Parameter(Mandatory)]
475
+ [string[]]$Dependencies,
476
+ [Parameter(Mandatory)]
477
+ [string]$PackageFileName,
478
+ [Parameter(Mandatory)]
479
+ [string]$TeamProjectName
480
+ )
481
+
482
+ # Update each file.
483
+ foreach ($project in $(Get-ChildItem -Filter $PackageFileName -Recurse)) {
484
+ $pkgFileContent = $(Get-Content $project.FullName -Raw)
485
+ $changeMade = $false
486
+ # Update each package file with dependency versions.
487
+ foreach ($dependency in $Dependencies) {
488
+ $returnedContent = Update-NodePackageDependency `
489
+ -RepositoryName $dependency `
490
+ -PackageFileContent $pkgFileContent `
491
+ -IsRemotePackage $false `
492
+ -TeamProjectName $TeamProjectName
493
+ if ($returnedContent -eq $null) {
494
+ Write-Host "# ERROR: Failed to update dependency $dependency"
495
+ return $false
496
+ }
497
+
498
+ if ($returnedContent -ne $pkgFileContent) {
499
+ $pkgFileContent = $returnedContent
500
+ $changeMade = $true
501
+ }
502
+ }
503
+
504
+ # If is remote_package.json, then also update internal dependencies.
505
+ if ($PackageFileName -match "remote_package.json") {
506
+ $returnedContent = Update-NodePackageDependency `
507
+ -RepositoryName $RepositoryName `
508
+ -PackageFileContent $pkgFileContent `
509
+ -IsRemotePackage $true `
510
+ -TeamProjectName $TeamProjectName
511
+ if ($returnedContent -eq $null) {
512
+ Write-Host "# ERROR: Failed to update dependency $dependency"
513
+ return $false
514
+ }
515
+
516
+ if ($returnedContent -ne $pkgFileContent) {
517
+ $pkgFileContent = $returnedContent
518
+ $changeMade = $true
519
+ }
520
+ }
521
+
522
+ # Check if package files have been updated.
523
+ if ($changeMade) {
524
+ Write-Host "# Dependency version has been updated. Update the $($project.FullName) content."
525
+ if (![FileHandler]::SetContent($project.FullName, $pkgFileContent)) {
526
+ Write-Host "# ERROR: Failed to update the $project.FullName content."
527
+ return $false
528
+ }
529
+
530
+ # Stage the change
531
+ if (![GitHandler]::Add("$($project.FullName)")) {
532
+ Write-Host "# ERROR: Failed to stage the change."
533
+ return $false
534
+ }
535
+ }
536
+ }
537
+ return $true
538
+ }
539
+
540
+ <#
541
+ .Description
542
+ Update dependencies of all Node packages in a repository.
543
+
544
+ .Parameter RepositoryName
545
+ Name of a repository
546
+
547
+ .Parameter TeamProjectName
548
+ Name ofthe repository team project
549
+
550
+ .Outputs
551
+ true or false
552
+ #>
553
+ function Update-NodePackageDependencies {
554
+ param (
555
+ [Parameter(Mandatory)]
556
+ [string]$RepositoryName,
557
+ [Parameter(Mandatory)]
558
+ [string]$TeamProjectName
559
+ )
560
+
561
+ Write-Host ""
562
+ Write-Host "Update Node Package Dependencies"
563
+ Write-Host "================================="
564
+
565
+ $dependencies = $script:repositories."$RepositoryName".dependencies
566
+ # Make sure only update if there are dependencies
567
+ if ($dependencies -ne $null -and $dependencies.count -gt 0) {
568
+ # Update package.json files
569
+ Write-Host "# Update package.json files"
570
+ if (!$(Update-NodeDependenciesSub `
571
+ -RepositoryName $RepositoryName `
572
+ -Dependencies $dependencies `
573
+ -PackageFileName "package.json" `
574
+ -TeamProjectName $TeamProjectName)) {
575
+ Write-Host "# ERROR: Failed to update 'package.json'"
576
+ return $false
577
+ }
578
+
579
+ # Update remote-package.json files
580
+ Write-Host "# Update remote_package.json files"
581
+ if (!$(Update-NodeDependenciesSub `
582
+ -RepositoryName $RepositoryName `
583
+ -Dependencies $dependencies `
584
+ -PackageFileName "remote_package.json" `
585
+ -TeamProjectName $TeamProjectName)) {
586
+ Write-Host "# ERROR: Failed to update 'remote_package.json'"
587
+ return $false
588
+ }
589
+ } else {
590
+ Write-Host "# There is no dependencies defined in configuration file. Skipped."
591
+ }
592
+
593
+ return $true
594
+ }
595
+
596
+ <#
597
+ .Description
598
+ Update dependencies of all Python packages in a repository.
599
+ In Python, package version is determined by what being
600
+ present at run time. Thus, this function only update the
601
+ package version being used for testing pipeline.
602
+
603
+ .Parameter Dependencies
604
+ An array of dependencies
605
+
606
+ .Parameter SharedVariableContent
607
+ Content to be updated.
608
+
609
+ .Parameter TeamProjectName
610
+ Name ofthe repository team project
611
+
612
+ .Outputs
613
+ Updated content. $null if error occurs
614
+ #>
615
+ function Update-PythonPackageContent {
616
+ param (
617
+ [Parameter(Mandatory)]
618
+ [string[]]$Dependencies,
619
+ [Parameter(Mandatory)]
620
+ [string]$SharedVariableContent,
621
+ [Parameter(Mandatory)]
622
+ [string]$TeamProjectName
623
+ )
624
+ foreach ($dependency in $Dependencies) {
625
+ $versionVariableName = $script:repositories."$dependency".versionVariableName
626
+ if ([string]::IsNullOrEmpty($versionVariableName)) { continue }
627
+ $matchPattern = "(?<prefix>name\s*:\s*$versionVariableName\s*\r\n\s*value\s*:\s*)'==.*'"
628
+ if ($SharedVariableContent -match $matchPattern) {
629
+ Write-Host "# Version variable matches dependency $versionVariableName. Update."
630
+ $dependencyVersion = $script:repositories."$dependency".version
631
+
632
+ # Make sure that the version exists for the dependency. Else bail out.
633
+ if (!$(Test-TagExist `
634
+ -RepositoryName $dependency `
635
+ -Version $dependencyVersion `
636
+ -TeamProjectName $TeamProjectName)) {
637
+ Write-Host "# ERROR: Tag $dependencyVersion for repository $dependency does not exist."
638
+ return $null
639
+ }
640
+
641
+ $replaceString = '${prefix}' + "'==$dependencyVersion'"
642
+ $SharedVariableContent = $SharedVariableContent -replace `
643
+ $matchPattern, `
644
+ $replaceString
645
+ } else {
646
+ Write-Host "# Nothing to update for dependency $versionVariableName"
647
+ }
648
+ }
649
+ return $SharedVariableContent
650
+ }
651
+
652
+ <#
653
+ .Description
654
+ Update dependencies of all Python packages in a repository.
655
+ In Python, package version is determined by what being
656
+ present at run time. Thus, this function only update the
657
+ package version being used for testing pipeline.
658
+
659
+ .Parameter RepositoryName
660
+ Name of a repository
661
+
662
+ .Parameter TeamProjectName
663
+ Name ofthe repository team project
664
+
665
+ .Outputs
666
+ true or false
667
+ #>
668
+ function Update-PythonPackageDependencies {
669
+ param (
670
+ [Parameter(Mandatory)]
671
+ [string]$RepositoryName,
672
+ [Parameter(Mandatory)]
673
+ [string]$TeamProjectName
674
+ )
675
+
676
+ Write-Host ""
677
+ Write-Host "Update Python Package Dependencies"
678
+ Write-Host "================================="
679
+
680
+ $dependencies = $script:repositories."$RepositoryName".dependencies
681
+ if ($dependencies -ne $null -and $dependencies.count -gt 0) {
682
+ # Check if shared-variables.yml exists
683
+ if (Test-Path ci\shared-variables.yml) {
684
+ $sharedVariablesContent = $(Get-Content ci\shared-variables.yml -Raw)
685
+ $updatedContent = Update-PythonPackageContent `
686
+ -Dependencies $dependencies `
687
+ -SharedVariableContent $sharedVariablesContent `
688
+ -TeamProjectName $TeamProjectName
689
+
690
+ if ($updatedContent -ne $null) {
691
+ # Check if shared-variables.yml has been updated.
692
+ if ($updatedContent -ne $sharedVariablesContent) {
693
+ Write-Host "# Dependency version has been updated. Update the shared-variables.yml content."
694
+ if (![FileHandler]::SetContent("ci\shared-variables.yml", $updatedContent)) {
695
+ Write-Host "# ERROR: Failed to update the shared-variables.yml content."
696
+ return $false
697
+ }
698
+
699
+ # Stage the change
700
+ if (![GitHandler]::Add("ci\shared-variables.yml")) {
701
+ Write-Host "# ERROR: Failed to stage the change."
702
+ return $false
703
+ }
704
+ }
705
+ } else {
706
+ Write-Host "# ERROR: error occured during the update of the shared-variables.yml"
707
+ return $false
708
+ }
709
+ } else {
710
+ Write-Host "# No shared-variables.yml file is found at this directory. Nothing to update."
711
+ }
712
+ } else {
713
+ Write-Host "# There is no dependencies defined in configuration file. Skipped."
714
+ }
715
+
716
+ return $true
717
+ }
718
+
719
+ <#
720
+ .Description
721
+ Update dependencies of all Golang packages in a repository.
722
+
723
+ .Parameter Dependencies
724
+ An array of dependencies
725
+
726
+ .Parameter SharedVariableContent
727
+ Content to be updated.
728
+
729
+ .Parameter TeamProjectName
730
+ Name ofthe repository team project
731
+
732
+ .Outputs
733
+ Updated content. $null if error occurs
734
+ #>
735
+ function Update-GoPackageContent {
736
+ param (
737
+ [Parameter(Mandatory)]
738
+ [string[]]$Dependencies,
739
+ [Parameter(Mandatory)]
740
+ [string]$GoModContent,
741
+ [Parameter(Mandatory)]
742
+ [string]$TeamProjectName
743
+ )
744
+ foreach ($dependency in $Dependencies) {
745
+ $matchPattern = "(?<prefix>(require|replace)\s*((?!$dependency).)*$dependency\s*)v\d+\.\d+\.\d+((?!\s).)*"
746
+ if ($GoModContent -match $matchPattern) {
747
+ Write-Host "# go.mod content match $dependency. Update."
748
+ $dependencyVersion = $script:repositories."$dependency".version
749
+
750
+ # Make sure that the version exists for the dependency. Else bail out.
751
+ if (!$(Test-TagExist `
752
+ -RepositoryName $dependency `
753
+ -Version $dependencyVersion `
754
+ -TeamProjectName $TeamProjectName)) {
755
+ Write-Host "# ERROR: Tag $dependencyVersion for repository $dependency does not exist."
756
+ return $null
757
+ }
758
+ $replaceString = '${prefix}' + "v$dependencyVersion"
759
+ $GoModContent = $GoModContent -replace `
760
+ $matchPattern, `
761
+ $replaceString
762
+ } else {
763
+ Write-Host "# Nothing to update for dependency $dependency"
764
+ }
765
+ }
766
+ return $GoModContent
767
+ }
768
+
769
+ <#
770
+ .Description
771
+ Update dependencies of all Golang packages in a repository.
772
+ This function updates go.mod but won't update go.sum. This
773
+ is not future proof, but enough for GO MVP implementation.
774
+
775
+ .Parameter RepositoryName
776
+ Name of a repository
777
+
778
+ .Parameter TeamProjectName
779
+ Name ofthe repository team project
780
+
781
+ .Outputs
782
+ true or false
783
+ #>
784
+ function Update-GoPackageDependencies {
785
+ param (
786
+ [Parameter(Mandatory)]
787
+ [string]$RepositoryName,
788
+ [Parameter(Mandatory)]
789
+ [string]$TeamProjectName
790
+ )
791
+
792
+ Write-Host ""
793
+ Write-Host "Update Go Package Dependencies"
794
+ Write-Host "================================="
795
+
796
+ # TODO: If go.sum is ever required, this approach needs to be changed. "go mod"
797
+ # will be required and dependencies will need to be available publicly to use
798
+ # "go mod". At the point of implementation, using "go mod" requires changes to
799
+ # changes to release process flow and need to be carefully considered. Thus,
800
+ # is an overkill for MVP version of go support at this point.
801
+ if (Test-Path go.sum) {
802
+ Write-Host "# ERROR: go.sum is not currently handled. " +
803
+ "Updating go.sum requires dependencies to be available publicly, " +
804
+ "so updating go.mod is not enough."
805
+ return $false
806
+ }
807
+
808
+ $dependencies = $script:repositories."$RepositoryName".dependencies
809
+ if ($dependencies -ne $null -and $dependencies.count -gt 0) {
810
+ # Check if shared-variables.yml exists
811
+ if (Test-Path go.mod) {
812
+ $goModContent = $(Get-Content go.mod -Raw)
813
+ $updatedContent = Update-GoPackageContent `
814
+ -Dependencies $dependencies `
815
+ -GoModContent $goModContent `
816
+ -TeamProjectName $TeamProjectName
817
+
818
+ if ($updatedContent -ne $null) {
819
+ # Check if go.mod has been updated.
820
+ if ($updatedContent -ne $goModContent) {
821
+ Write-Host "# Dependency version has been updated. Update the go.mod content."
822
+ if (![FileHandler]::SetContent("go.mod", $updatedContent)) {
823
+ Write-Host "# ERROR: Failed to update the go.mod content."
824
+ return $false
825
+ }
826
+
827
+ # Stage the change
828
+ if (![GitHandler]::Add("go.mod")) {
829
+ Write-Host "# ERROR: Failed to stage the change."
830
+ return $false
831
+ }
832
+ }
833
+ } else {
834
+ Write-Host "# ERROR: error occured during the update of the go.mod"
835
+ return $false
836
+ }
837
+ } else {
838
+ Write-Host "# No go.mod file is found at this directory. Nothing to update."
839
+ }
840
+ } else {
841
+ Write-Host "# There is no dependencies defined in configuration file. Skipped."
842
+ }
843
+
844
+ return $true
845
+ }
846
+
847
+ <#
848
+ .Description
849
+ Update dependencies of all packages in a repository.
850
+ This determine the type of package based on repository name.
851
+ Any change will be automatically staged.
852
+
853
+ NOTE: This check if a required version exist for
854
+ each valid dependency. If none is found, it will result
855
+ in a false.
856
+
857
+ .Parameter Configuration
858
+ A configuration object
859
+
860
+ .Parameter TeamProjectName
861
+ Name ofthe repository team project
862
+
863
+ .Outputs
864
+ true or false
865
+ #>
866
+ function Update-PackageDependencies {
867
+ param (
868
+ [Parameter(Mandatory)]
869
+ [object]$Configuration,
870
+ [Parameter(Mandatory)]
871
+ [string]$TeamProjectName
872
+ )
873
+
874
+ Write-Host ""
875
+ Write-Host "# Update package dependencies"
876
+ Write-Host "============================="
877
+
878
+ # Initialise the script variables
879
+ Initialize-GlobalVariables -Configuration $Configuration
880
+
881
+ # Get repository name
882
+ $repoName = Get-RepositoryName
883
+
884
+ $succeeded = $true
885
+ # Determine the type of package based on languages
886
+ switch -Wildcard ("$repoName") {
887
+ "*java" {
888
+ Write-Host "# $repoName is a Maven package."
889
+ $succeeded = Update-MavenPackageDependencies `
890
+ -RepositoryName $repoName -TeamProjectName $TeamProjectName
891
+ Break
892
+ }
893
+ "*dotnet" {
894
+ Write-Host "# $repoName is a Dotnet package."
895
+ $succeeded = Update-DotnetPackageDependencies `
896
+ -RepositoryName $repoName -TeamProjectName $TeamProjectName
897
+ Break
898
+ }
899
+ "*node" {
900
+ Write-Host "# $repoName is a Node package."
901
+ $succeeded = Update-NodePackageDependencies `
902
+ -RepositoryName $repoName -TeamProjectName $TeamProjectName
903
+ Break
904
+ }
905
+ "*python" {
906
+ Write-Host "# $repoName is a Python package."
907
+ $succeeded = Update-PythonPackageDependencies `
908
+ -RepositoryName $repoName -TeamProjectName $TeamProjectName
909
+ Break
910
+ }
911
+ "*go" {
912
+ Write-Host "# $repoName is a Golang package."
913
+ $succeeded = Update-GoPackageDependencies `
914
+ -RepositoryName $repoName -TeamProjectName $TeamProjectName
915
+ Break
916
+ }
917
+ Default {
918
+ Write-Host "# $repoName is of type that do not need to update package."
919
+ Break
920
+ }
921
+ }
922
+
923
+ return $succeeded
924
+ }
925
+
926
+ Export-ModuleMember -Function Update-PackageDependencies