-
Notifications
You must be signed in to change notification settings - Fork 30
/
AL-Go-TestRepoHelper.ps1
311 lines (289 loc) · 9.49 KB
/
AL-Go-TestRepoHelper.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
function Test-Property {
Param(
[HashTable] $json,
[string] $settingsDescription,
[string] $key,
[switch] $must,
[switch] $should,
[switch] $maynot,
[switch] $shouldnot
)
$exists = $json.Keys -contains $key
if ($exists) {
if ($maynot) {
OutputError "Property '$key' may not exist in $settingsDescription. See https://aka.ms/algosettings#$key"
}
elseif ($shouldnot) {
OutputWarning -Message "Property '$key' should not exist in $settingsDescription. See https://aka.ms/algosettings#$key"
}
}
else {
if ($must) {
OutputError "Property '$key' must exist in $settingsDescription. See https://aka.ms/algosettings#$key"
}
elseif ($should) {
OutputWarning -Message "Property '$key' should exist in $settingsDescription. See https://aka.ms/algosettings#$key"
}
}
}
function Test-Shell {
Param(
[HashTable] $json,
[string] $settingsDescription,
[string] $property
)
if ($json.Keys -contains $property) {
$shell = $json.$property
if ($shell -ne 'powershell' -and $shell -ne 'pwsh') {
OutputError "$property is '$shell', must be 'powershell' or 'pwsh' in $settingsDescription. See https://aka.ms/algosettings#$property"
}
}
}
function Test-SettingsJson {
Param(
[hashtable] $json,
[string] $settingsDescription,
[ValidateSet('Repo','Project','Workflow','Variable')]
[string] $type
)
Test-Shell -json $json -settingsDescription $settingsDescription -property 'shell'
Test-Shell -json $json -settingsDescription $settingsDescription -property 'gitHubRunnerShell'
if ($json.Keys -contains 'bcContainerHelperVersion') {
if ($json.bcContainerHelperVersion -ne 'latest' -and $json.bcContainerHelperVersion -ne 'preview') {
OutputWarning -Message "Using a specific version of BcContainerHelper in $settingsDescription is not recommended and will lead to build failures in the future. Consider removing the setting."
}
}
if ($type -eq 'Repo') {
# Test for things that should / should not exist in a repo settings file
Test-Property -settingsDescription $settingsDescription -json $json -key 'templateUrl' -should
}
if ($type -eq 'Project') {
# Test for things that should / should not exist in a project settings file
Test-Property -settingsDescription $settingsDescription -json $json -key 'bcContainerHelperVersion' -shouldnot
}
if ($type -eq 'Workflow') {
# Test for things that should / should not exist in a workflow settings file
}
if ($type -eq 'Variable') {
# Test for things that should / should not exist in a settings variable
}
if ($type -eq 'Project' -or $type -eq 'Workflow') {
# templateUrl should not be in Project or Workflow settings
Test-Property -settingsDescription $settingsDescription -json $json -key 'templateUrl' -maynot
# schedules and runs-on should not be in Project or Workflow settings
# These properties are used in Update AL-Go System Files, hence they should only be in Repo settings
'nextMajorSchedule','nextMinorSchedule','currentSchedule','runs-on' | ForEach-Object {
Test-Property -settingsDescription $settingsDescription -json $json -key $_ -shouldnot
}
}
}
function Test-JsonStr {
Param(
[string] $jsonStr,
[string] $settingsDescription,
[ValidateSet('Repo','Project','Workflow','Variable')]
[string] $type
)
if ($jsonStr -notlike '{*') {
OutputError "Settings in $settingsDescription is not recognized as JSON (does not start with '{'))"
}
try {
$json = $jsonStr | ConvertFrom-Json | ConvertTo-HashTable
Test-SettingsJson -json $json -settingsDescription $settingsDescription -type:$type
}
catch {
OutputError "$($_.Exception.Message.Replace("`r",'').Replace("`n",' ')) in $settingsDescription"
}
}
function Test-JsonFile {
Param(
[string] $jsonFile,
[string] $baseFolder,
[ValidateSet('Repo','Project','Workflow')]
[string] $type
)
$settingsFile = $jsonFile.Substring($baseFolder.Length+1)
Write-Host "Checking AL-Go $type settings file in $settingsFile (type = $type)"
Test-JsonStr -org -jsonStr (Get-Content -Path $jsonFile -Raw -Encoding UTF8) -settingsDescription $settingsFile -type $type
}
function TestRunnerPrerequisites {
try {
invoke-gh version
}
catch {
OutputWarning -Message "GitHub CLI is not installed"
}
try {
invoke-git version
}
catch {
OutputWarning -Message "Git is not installed"
}
}
function TestALGoRepository {
Param(
[string] $baseFolder = $ENV:GITHUB_WORKSPACE
)
if ($ENV:ALGoOrgSettings) {
Write-Host "Checking AL-Go Org Settings variable (ALGoOrgSettings)"
Test-JsonStr -jsonStr "$ENV:ALGoOrgSettings" -settingsDescription 'ALGoOrgSettings variable' -type 'Variable'
}
if ($ENV:ALGoRepoSettings) {
Write-Host "Checking AL-Go Repo Settings variable (ALGoRepoSettings)"
Test-JsonStr -jsonStr "$ENV:ALGoRepoSettings" -settingsDescription 'ALGoRepoSettings variable' -type 'Variable'
}
Write-Host "BaseFolder: $baseFolder"
# Test .json files are formatted correctly
# Get-ChildItem needs -force to include folders starting with . (e.x. .github / .AL-Go) on Linux
Get-ChildItem -Path $baseFolder -Filter '*.json' -Recurse -Force | ForEach-Object {
if ($_.Directory.Name -eq '.AL-Go' -and $_.BaseName -eq 'settings') {
Test-JsonFile -jsonFile $_.FullName -baseFolder $baseFolder -type 'Project'
}
elseif ($_.Directory.Name -eq '.github' -and $_.BaseName -like '*ettings') {
if ($_.BaseName -eq 'AL-Go-Settings') {
$type = 'Repo'
}
else {
$type = 'Workflow'
}
Test-JsonFile -jsonFile $_.FullName -baseFolder $baseFolder -type $type
}
}
}
function Write-Big {
Param(
[string] $str
)
$chars = @{
"0" = @(
" ___ "
" / _ \ "
"| | | |"
"| | | |"
"| |_| |"
" \___/ "
)
"1" = @(
" __ "
"/_ |"
" | |"
" | |"
" | |"
" |_|"
)
"2" = @(
" ___ "
"|__ \ "
" ) |"
" / / "
" / /_ "
"|____|"
)
"3" = @(
" ____ "
"|___ \ "
" __) |"
" |__ < "
" ___) |"
"|____/ "
)
"4" = @(
" _ _ "
"| || | "
"| || |_ "
"|__ _|"
" | | "
" |_| "
)
"5" = @(
" _____ "
"| ____|"
"| |__ "
"|___ \ "
" ___) |"
"|____/ "
)
"6" = @(
" __ "
" / / "
" / /_ "
"| '_ \ "
"| (_) |"
" \___/ "
)
"7" = @(
" ______ "
"|____ |"
" / / "
" / / "
" / / "
" /_/ "
)
"8" = @(
" ___ "
" / _ \ "
"| (_) |"
" > _ < "
"| (_) |"
" \___/ "
)
"9" = @(
" ___ "
" / _ \ "
"| (_) |"
" \__, |"
" / / "
" /_/ "
)
"." = @(
" "
" "
" "
" "
" _ "
"(_)"
)
"v" = @(
" "
" "
"__ __"
"\ \ / /"
" \ V / "
" \_(_)"
)
"p" = @(
" _____ _ "
"| __ \ (_) "
"| |__) | __ _____ ___ _____ __"
"| ___/ '__/ _ \ \ / / |/ _ \ \ /\ / /"
"| | | | | __/\ V /| | __/\ V V / "
"|_| |_| \___| \_/ |_|\___| \_/\_/ "
)
"d" = @(
" _____ "
"| __ \ "
"| | | | _____ __"
"| | | |/ _ \ \ / /"
"| |__| | __/\ V / "
"|_____/ \___| \_(_)"
)
"a" = @(
" _ _____ __ _____ _ _ _ _ _ "
" /\ | | / ____| / _| / ____(_) | | | | | | | "
" / \ | | ______| | __ ___ | |_ ___ _ __ | | __ _| |_| |__| |_ _| |__ "
" / /\ \ | | |______| | |_ |/ _ \ | _/ _ \| '__| | | |_ | | __| __ | | | | '_ \ "
" / ____ \| |____ | |__| | (_) | | || (_) | | | |__| | | |_| | | | |_| | |_) | "
"/_/ \_\______| \_____|\___/ |_| \___/|_| \_____|_|\__|_| |_|\__,_|_.__/ "
)
}
$lines = $chars."a".Count
for ($line = 0; $line -lt $lines; $line++) {
foreach ($ch in $str.ToCharArray()) {
if ($chars.Keys -contains $ch) {
$bigCh = $chars."$ch"
Write-Host -noNewline $bigCh[$line]
}
}
Write-Host
}
}