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,318 @@
1
+ # All tests for 'Test-ConfigFile' function
2
+ Describe 'Test-ConfigFile' {
3
+ It 'valid config file' {
4
+ $config = '{
5
+ "name": "APIs Test Environment Configuration",
6
+ "repositories": {
7
+ "ci-test-repo-1": {
8
+ "releaseVersion": "4.3.0",
9
+ "tags": [
10
+ "4.3.0"
11
+ ],
12
+ "pullRequests": [
13
+ {
14
+ "source": "release/v4.3.0",
15
+ "target": "main"
16
+ }
17
+ ],
18
+ "definitions": [
19
+ {
20
+ "name": "ci-test-repo-1",
21
+ "defaultBranch": "main",
22
+ "yamlFileName": "build-and-test.yml"
23
+ }
24
+ ],
25
+ "branches": [
26
+ {
27
+ "refName": "refs/heads/hotfix/v5.3.1",
28
+ "refBase": "refs/heads/main"
29
+ }
30
+ ],
31
+ "submodules": []
32
+ },
33
+ "ci-test-repo-3": {
34
+ "releaseVersion": "4.3.0",
35
+ "tags": [
36
+ "4.3.0"
37
+ ],
38
+ "pullRequests": [
39
+ {
40
+ "source": "release/v4.3.0",
41
+ "target": "main",
42
+ "comment": true
43
+ }
44
+ ],
45
+ "definitions": [
46
+ {
47
+ "name": "ci-test-repo-3-test",
48
+ "defaultBranch": "main",
49
+ "yamlFileName": "build-and-test.yml",
50
+ "triggers": [
51
+ {
52
+ "definitionName": "ci-test-repo-1-test",
53
+ "requiresSuccessfulBuild": true,
54
+ "branchFilters": [
55
+ "+refs/heads/main"
56
+ ],
57
+ "triggerType": "buildCompletion"
58
+ }
59
+ ]
60
+ }
61
+ ],
62
+ "policies": [
63
+ {
64
+ "definition": "ci-test-repo-3-test",
65
+ "type": "Build",
66
+ "refName": "refs/heads/main",
67
+ "matchKind": "Exact"
68
+ }
69
+ ],
70
+ "submodules": [
71
+ "ci-test-repo-1"
72
+ ]
73
+ }
74
+ },
75
+ "policies": [
76
+ {
77
+ "type": "Required reviewers"
78
+ }
79
+ ]
80
+ }' | ConvertFrom-Json
81
+ $result = Test-ConfigFile -Configuration $config
82
+ $result | Should -BeExactly $true
83
+ }
84
+
85
+ It 'missing submodule definition' {
86
+ $config = '{
87
+ "repositories": {
88
+ "repo1": {
89
+ "submodules": [
90
+ "repo2"
91
+ ]
92
+ }
93
+ }
94
+ }' | ConvertFrom-Json
95
+ $result = Test-Submodules `
96
+ -Configuration $config `
97
+ -Submodules $config.repositories.repo1.submodules
98
+ $result | Should -BeExactly $false
99
+ }
100
+
101
+ It 'invalid tag' {
102
+ $result = Test-Tags -Tags $("a.b.c")
103
+ $result | Should -BeExactly $false
104
+ }
105
+
106
+ It 'invalid pull request source and target' {
107
+ # No 'source' is specified
108
+ $pullrequests1 = '[
109
+ {
110
+ "target": "main"
111
+ }
112
+ ]' | ConvertFrom-Json
113
+ $result = Test-PullRequests -PullRequest $pullrequests1
114
+ $result | Should -BeExactly $false
115
+
116
+ # No 'target' is specified
117
+ $pullrequests2 = '[
118
+ {
119
+ "source": "main"
120
+ }
121
+ ]' | ConvertFrom-Json
122
+ $result = Test-PullRequests -PullRequest $pullrequests2
123
+ $result | Should -BeExactly $false
124
+ }
125
+
126
+ It 'invalid pull request comment' {
127
+ # Invalid 'comment' value
128
+ $pullrequests = '[
129
+ {
130
+ "source": "source",
131
+ "target": "target",
132
+ "comment": 1
133
+ }
134
+ ]' | ConvertFrom-Json
135
+ $result = Test-PullRequests -PullRequest $pullrequests
136
+ $result | Should -BeExactly $false
137
+ }
138
+
139
+ It 'invalid definition general' {
140
+ # No 'name' is pecified
141
+ $definitions = '[
142
+ {
143
+ "defaultBranch": "main",
144
+ "yamlFileName": "build-and-test.yml"
145
+ }
146
+ ]' | ConvertFrom-Json
147
+ $result = Test-Definitions -Definitions $definitions
148
+ $result | Should -BeExactly $false
149
+
150
+ # No 'defaultBranch' is pecified
151
+ $definitions = '[
152
+ {
153
+ "name": "test-repo",
154
+ "yamlFileName": "build-and-test.yml"
155
+ }
156
+ ]' | ConvertFrom-Json
157
+ $result = Test-Definitions -Definitions $definitions
158
+ $result | Should -BeExactly $false
159
+
160
+ # No 'yamlFileName' is pecified
161
+ $definitions = '[
162
+ {
163
+ "name": "test-repo",
164
+ "defaultBranch": "main"
165
+ }
166
+ ]' | ConvertFrom-Json
167
+ $result = Test-Definitions -Definitions $definitions
168
+ $result | Should -BeExactly $false
169
+ }
170
+
171
+ It 'invalid definition triggers' {
172
+ # No 'definitionName' is pecified
173
+ $triggers = '[
174
+ {
175
+ "requiresSuccessfulBuild": true,
176
+ "branchFilters": ["+refs/heads/main"],
177
+ "triggerType": "buildCompletion"
178
+ }
179
+ ]' | ConvertFrom-Json
180
+ $result = Test-Triggers -Triggers $triggers
181
+ $result | Should -BeExactly $false
182
+
183
+ # Incorrect 'requiresSuccessfulBuild' is pecified
184
+ $triggers = '[
185
+ {
186
+ "definitionName": "ci-test-repo-1-test",
187
+ "requiresSuccessfulBuild": 1,
188
+ "branchFilters": ["+refs/heads/main"],
189
+ "triggerType": "buildCompletion"
190
+ }
191
+ ]' | ConvertFrom-Json
192
+ $result = Test-Triggers -Triggers $triggers
193
+ $result | Should -BeExactly $false
194
+
195
+ # No 'branchFilters' is pecified
196
+ $triggers = '[
197
+ {
198
+ "definitionName": "ci-test-repo-1-test",
199
+ "requiresSuccessfulBuild": true,
200
+ "triggerType": "buildCompletion"
201
+ }
202
+ ]' | ConvertFrom-Json
203
+ $result = Test-Triggers -Triggers $triggers
204
+ $result | Should -BeExactly $false
205
+
206
+ # Empty 'branchFilters' is pecified
207
+ $triggers = '[
208
+ {
209
+ "definitionName": "ci-test-repo-1-test",
210
+ "requiresSuccessfulBuild": true,
211
+ "branchFilters": [],
212
+ "triggerType": "buildCompletion"
213
+ }
214
+ ]' | ConvertFrom-Json
215
+ $result = Test-Triggers -Triggers $triggers
216
+ $result | Should -BeExactly $false
217
+
218
+ # Incorrect 'triggerType' is pecified
219
+ $triggers = '[
220
+ {
221
+ "definitionName": "ci-test-repo-1-test",
222
+ "requiresSuccessfulBuild": true,
223
+ "branchFilters": ["+refs/heads/main"],
224
+ "triggerType": "Something else"
225
+ }
226
+ ]' | ConvertFrom-Json
227
+ $result = Test-Triggers -Triggers $triggers
228
+ $result | Should -BeExactly $false
229
+ }
230
+
231
+ It 'invalid branches' {
232
+ # 'refName' not specified
233
+ $branches = '[
234
+ {
235
+ "base": "main"
236
+ }
237
+ ]' | ConvertFrom-Json
238
+ $result = Test-Branches -Branches $branches
239
+ $result | Should -BeExactly $false
240
+
241
+ # 'refBase' not specified
242
+ $branches = '[
243
+ {
244
+ "name": "hotfix/v5.3.1"
245
+ }
246
+ ]' | ConvertFrom-Json
247
+ $result = Test-Branches -Branches $branches
248
+ $result | Should -BeExactly $false
249
+ }
250
+
251
+ It 'invalid policies type' {
252
+ # Invalid 'type'
253
+ $policies = '[
254
+ {
255
+ "type": "Test type"
256
+ }
257
+ ]' | ConvertFrom-Json
258
+ $result = Test-Policies -Policies $policies
259
+ $result | Should -BeExactly $false
260
+ }
261
+
262
+ It 'invalid policies type "Build"' {
263
+ # No 'definition'
264
+ $policies = '[
265
+ {
266
+ "type": "Build",
267
+ "refName": "refs/heads/main",
268
+ "matchKind": "Exact"
269
+ }
270
+ ]' | ConvertFrom-Json
271
+ $result = Test-Policies -Policies $policies
272
+ $result | Should -BeExactly $false
273
+
274
+ # No 'refName'
275
+ $policies = '[
276
+ {
277
+ "definition": "ci-test-repo-3-test",
278
+ "type": "Build",
279
+ "matchKind": "Exact"
280
+ }
281
+ ]' | ConvertFrom-Json
282
+ $result = Test-Policies -Policies $policies
283
+ $result | Should -BeExactly $false
284
+
285
+ # Invalid 'refName'
286
+ $policies = '[
287
+ {
288
+ "definition": "ci-test-repo-3-test",
289
+ "type": "Build",
290
+ "refName": "heads/main",
291
+ "matchKind": "Exact"
292
+ }
293
+ ]' | ConvertFrom-Json
294
+ $result = Test-Policies -Policies $policies
295
+ $result | Should -BeExactly $false
296
+
297
+ # No 'matchKind'
298
+ $policies = '[
299
+ {
300
+ "definition": "ci-test-repo-3-test",
301
+ "type": "Build",
302
+ "refName": "refs/heads/main"
303
+ }
304
+ ]' | ConvertFrom-Json
305
+ $result = Test-Policies -Policies $policies
306
+ $result | Should -BeExactly $false
307
+ }
308
+
309
+ It 'Valid policies type "Required reviewers"' {
310
+ $policies = '[
311
+ {
312
+ "type": "Required reviewers"
313
+ }
314
+ ]' | ConvertFrom-Json
315
+ $result = Test-Policies -Policies $policies
316
+ $result | Should -BeExactly $true
317
+ }
318
+ }
@@ -0,0 +1,344 @@
1
+ <#
2
+ .Description
3
+ Test if there exist a definition for each submodule.
4
+
5
+ .Parameter Configuration
6
+ The full configuration of the test environment
7
+
8
+ .Parameter Submodules
9
+ The list of submodules to be tested
10
+
11
+ .Outputs
12
+ true or false
13
+ #>
14
+ function Test-Submodules {
15
+ param(
16
+ [Parameter(Mandatory)]
17
+ [object]$Configuration,
18
+ [Parameter(Mandatory)]
19
+ [string[]]$Submodules
20
+ )
21
+
22
+ foreach ($submodule in $Submodules) {
23
+ if ($Configuration.repositories."$submodule" -eq $null) {
24
+ Write-Host "# ERROR: No definition of submodule '$submodule' found."
25
+ return $false
26
+ }
27
+ }
28
+ return $true
29
+ }
30
+
31
+ <#
32
+ .Description
33
+ Test if tags are in valid format
34
+
35
+ .Parameter Tags
36
+ List of tags to be tested
37
+
38
+ .Outputs
39
+ true or false
40
+ #>
41
+ function Test-Tags {
42
+ param(
43
+ [Parameter(Mandatory)]
44
+ [string[]]$Tags
45
+ )
46
+
47
+ foreach ($tag in $Tags) {
48
+ if (!($tag -match "\d+\.\d+\.\d+")) {
49
+ Write-Host "# ERROR: Invalid tag number '$tag'"
50
+ return $false
51
+ }
52
+ }
53
+ return $true
54
+ }
55
+
56
+ <#
57
+ .Description
58
+ Test if pull request definitions are valid
59
+
60
+ .Parameter PullRequests
61
+ List of pull requests to be tested.
62
+
63
+ .Outputs
64
+ true or false
65
+ #>
66
+ function Test-PullRequests {
67
+ param(
68
+ [Parameter(Mandatory)]
69
+ [object[]]$PullRequests
70
+ )
71
+
72
+ foreach ($pr in $PullRequests) {
73
+ if ($pr.source -eq $null) {
74
+ Write-Host "# ERROR: No source reference is defined for pull request '$pr'"
75
+ return $false
76
+ }
77
+
78
+ if ($pr.target -eq $null) {
79
+ Write-Host "# ERROR: No target reference is defined for pull request '$pr'"
80
+ return $false
81
+ }
82
+
83
+ # Validate comment option
84
+ if ($pr.comment -ne $null `
85
+ -and "$($pr.comment)" -ne "true" `
86
+ -and "$($pr.comment)" -ne "$false") {
87
+ Write-Host "# ERROR: Pull request comment option can only be true or false."
88
+ return $false
89
+ }
90
+ }
91
+ return $true
92
+ }
93
+
94
+ <#
95
+ .Description
96
+ Test if definitions triggers are valid. We currently
97
+ only consider 'buildCompletion' trigger.
98
+
99
+ .Parameter Triggers
100
+ List of triggers to be tested
101
+
102
+ .Outputs
103
+ true or false
104
+ #>
105
+ function Test-Triggers {
106
+ param(
107
+ [Parameter(Mandatory)]
108
+ [object[]]$Triggers
109
+ )
110
+
111
+ foreach ($trigger in $Triggers) {
112
+ if ([string]::IsNullOrEmpty($trigger.definitionName)) {
113
+ Write-Host "# ERROR: 'definitionName' is not defined in 'trigger' configuration. '$trigger'"
114
+ return $false
115
+ }
116
+
117
+ if ("$trigger.requiresSuccessfulBuild" -ne "true" `
118
+ -and "$trigger.requiresSuccessfulBuild" -ne "true") {
119
+ Write-Host "# ERROR: 'requiresSuccessfulBuild' is not defined or not a boolean type. '$trigger'"
120
+ return $false
121
+ }
122
+
123
+ if ($trigger.branchFilters -eq $null `
124
+ -or $trigger.branchFilters.count -eq 0) {
125
+ Write-Host "# ERROR: 'branchFilters' array cannot be undefined or empty. '$trigger'"
126
+ return $false
127
+ }
128
+
129
+ if ($trigger.triggerType -eq "buildCompletion") {
130
+ Write-Host "# ERROR: 'triggerType' can only be 'buildCompletion'. '$trigger'"
131
+ return $false
132
+ }
133
+ }
134
+ return $true
135
+ }
136
+
137
+ <#
138
+ .Description
139
+ Test if definitions are valid
140
+
141
+ .Parameter Definitions
142
+ List of defnitions to be tested
143
+
144
+ .Outputs
145
+ true or false
146
+ #>
147
+ function Test-Definitions {
148
+ param(
149
+ [Parameter(Mandatory)]
150
+ [object[]]$Definitions
151
+ )
152
+
153
+ foreach ($definition in $Definitions) {
154
+ # Test general settings
155
+ if ([string]::IsNullOrEmpty($definition.name)) {
156
+ Write-Host "# ERROR: Definition name cannot be empty or not defined. '$definition'"
157
+ return $false
158
+ }
159
+
160
+ if ([string]::IsNullOrEmpty($definition.defaultBranch)) {
161
+ Write-Host "# ERROR: 'defaultBranch' is not defined. '$definition'"
162
+ return $false
163
+ }
164
+
165
+ if ([string]::IsNullOrEmpty($definition.yamlFileName)) {
166
+ Write-Host "# ERROR: 'yamlFileName' is not defined. '$definition'"
167
+ return $false
168
+ }
169
+
170
+ # Test triggers. We currently only consider 'buildCompletion' trigger.
171
+ if (!(Test-Triggers -Triggers $definition.triggers)) {
172
+ return $false
173
+ }
174
+ }
175
+ return $true
176
+ }
177
+
178
+ <#
179
+ .Description
180
+ Test if branches are valid
181
+
182
+ .Parameter Branches
183
+ List of branches to be tested
184
+
185
+ .Outputs
186
+ true or false
187
+ #>
188
+ function Test-Branches {
189
+ param(
190
+ [Parameter(Mandatory)]
191
+ [object[]]$Branches
192
+ )
193
+
194
+ foreach ($branch in $Branches) {
195
+ if ([string]::IsNullOrEmpty($branch.name)) {
196
+ Write-Host "# ERROR: 'name' cannot be empty. '$branch'"
197
+ return $false
198
+ }
199
+
200
+ if ([string]::IsNullOrEmpty($branch.base)) {
201
+ Write-Host "# ERROR: 'base' cannot be empty. '$branch'"
202
+ return $false
203
+ }
204
+ }
205
+ return $true
206
+ }
207
+
208
+ <#
209
+ .Description
210
+ Test if policies are valid
211
+
212
+ .Parameter Policies
213
+ List of policies to be tested
214
+
215
+ .Outputs
216
+ true or false
217
+ #>
218
+ function Test-Policies {
219
+ param(
220
+ [Parameter(Mandatory)]
221
+ [object[]]$Policies
222
+ )
223
+
224
+ foreach ($policy in $Policies) {
225
+ switch ($policy.type) {
226
+ "Build"
227
+ {
228
+ if ([string]::IsNullOrEmpty($policy.definition)) {
229
+ Write-Host "# ERROR: 'definition' cannot be empty. '$policy'"
230
+ return $false
231
+ }
232
+
233
+ if ([string]::IsNullOrEmpty($policy.refName)) {
234
+ Write-Host "# ERROR: 'refName' cannot be empty. '$policy'"
235
+ return $false
236
+ } elseif (!($policy.refName -match "refs/.*")) {
237
+ Write-Host "# ERROR: 'refName' must start with'refs/'"
238
+ return $false
239
+ }
240
+
241
+ if ([string]::IsNullOrEmpty($policy.matchKind)) {
242
+ Write-Host "# ERROR: 'matchKind' cannot be empty. '$policy'"
243
+ return $false
244
+ }
245
+ }
246
+ "Required reviewers"
247
+ {
248
+ # Currently for this type we will always add a default user
249
+ # to all repositories.
250
+ break
251
+ }
252
+ Default
253
+ {
254
+ Write-Host "# ERROR: Only 'Build' and 'Required reviewers' policies are currently supported."
255
+ return $false
256
+ }
257
+ }
258
+ }
259
+ return $true
260
+ }
261
+
262
+ <#
263
+ .Description
264
+ Verify if a configuration file is valid.
265
+
266
+ .Parameter Configuration
267
+ A configuration object, reflecting what is specified in the configuration file
268
+
269
+ .Outputs
270
+ true or false
271
+ #>
272
+ function Test-ConfigFile {
273
+ param (
274
+ [Parameter(Mandatory)]
275
+ [object]$Configuration
276
+ )
277
+
278
+ Write-Host ""
279
+ Write-Host "Verify input configuration file"
280
+ Write-Host "==============================="
281
+ # Test if repositories are empty
282
+
283
+ if ($Configuration.repositories -ne $null) {
284
+ foreach ($repoProperty in $Configuration.repositories | Get-Member -MemberType "NoteProperty") {
285
+ Write-Host ""
286
+ Write-Host "# Processing repository '$($repoProperty.name)'"
287
+ $repository = $Configuration.repositories."$($repoProperty.name)"
288
+
289
+ # Test missing submodule definition
290
+ if ($respository.submodules -ne $null `
291
+ -and $repository.submodules.count -gt 0 `
292
+ -and !$(Test-Submodules `
293
+ -Configuration $Configuration `
294
+ -Submodules $repository.submodules)) {
295
+ return $false
296
+ }
297
+
298
+ # Test valid tag
299
+ if ($respository.tags -ne $null `
300
+ -and $repository.tags.count -gt 0 `
301
+ -and !$(Test-Tags -Tags $repository.tags)) {
302
+ return $false
303
+ }
304
+
305
+ # Test pull request configuration
306
+ if ($respository.pullRequests -ne $null `
307
+ -and $repository.pullRequests.count -gt 0 `
308
+ -and !$(Test-PullRequests -PullRequests $repository.pullRequests)) {
309
+ return $false
310
+ }
311
+
312
+ # Test definitions
313
+ if ($respository.definitions -ne $null `
314
+ -and $repository.definitions.count -gt 0 `
315
+ -and !$(Test-Definitions -Definitions $repository.definitions)) {
316
+ return $false
317
+ }
318
+
319
+ # Test branches
320
+ if ($respository.branches -ne $null `
321
+ -and $repository.branches.count -gt 0 `
322
+ -and !$(Test-Branches -Branches $repository.branches)) {
323
+ return $false
324
+ }
325
+
326
+ # Test policies
327
+ if ($respository.policies -ne $null `
328
+ -and $repository.policies.count -gt 0 `
329
+ -and !$(Test-Policies -Policies $repository.policies)) {
330
+ return $false
331
+ }
332
+ }
333
+ } else {
334
+ Write-Host "# WARNINGS: Cannot find 'repositories' entry."
335
+ }
336
+
337
+ # Test cross-repository policies
338
+ if ($Configuration.policies -ne $null `
339
+ -and $Configuration.policies.count -gt 0 `
340
+ -and !$(Test-policies -Policies $Configuration.policies)) {
341
+ return $false
342
+ }
343
+ return $true
344
+ }