forked from microsoft/AL-Go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReadSettings.ps1
85 lines (76 loc) · 3.28 KB
/
ReadSettings.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
Param(
[Parameter(HelpMessage = "Project folder", Mandatory = $false)]
[string] $project = ".",
[Parameter(HelpMessage = "Build mode", Mandatory = $false)]
[string] $buildMode = "Default",
[Parameter(HelpMessage = "Specifies which properties to get from the settings file, default is all", Mandatory = $false)]
[string] $get = ""
)
. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)
$settings = ReadSettings -project $project -buildMode $buildMode
if ($get) {
$getSettings = $get.Split(',').Trim()
}
else {
$getSettings = @()
}
if ($ENV:GITHUB_EVENT_NAME -in @("pull_request_target", "pull_request")) {
$settings.doNotSignApps = $true
$settings.versioningStrategy = 15
}
if ($settings.appBuild -eq [int32]::MaxValue) {
$settings.versioningStrategy = 15
}
if ($settings.versioningstrategy -ne -1) {
switch ($settings.versioningStrategy -band 15) {
0 { # Use RUN_NUMBER and RUN_ATTEMPT
$settings.appBuild = $settings.runNumberOffset + [Int32]($ENV:GITHUB_RUN_NUMBER)
$settings.appRevision = [Int32]($ENV:GITHUB_RUN_ATTEMPT) - 1
}
1 { # Use RUN_ID and RUN_ATTEMPT
OutputError -message "Versioning strategy 1 is no longer supported"
}
2 { # USE DATETIME
$settings.appBuild = [Int32]([DateTime]::UtcNow.ToString('yyyyMMdd'))
$settings.appRevision = [Int32]([DateTime]::UtcNow.ToString('HHmmss'))
}
3 { # USE BUIlD from app.json and RUN_NUMBER
$settings.appBuild = -1
$settings.appRevision = $settings.runNumberOffset + [Int32]($ENV:GITHUB_RUN_NUMBER)
}
15 { # Use maxValue
$settings.appBuild = [Int32]::MaxValue
$settings.appRevision = 0
}
default {
OutputError -message "Unknown version strategy $versionStrategy"
exit
}
}
}
$outSettings = @{}
$settings.Keys | ForEach-Object {
$setting = $_
$settingValue = $settings."$setting"
if ($settingValue -is [String] -and ($settingValue.contains("`n") -or $settingValue.contains("`r"))) {
throw "Setting $setting contains line breaks, which is not supported"
}
$outSettings += @{ "$setting" = $settingValue }
if ($getSettings -contains $setting) {
if ($settingValue -is [System.Collections.Specialized.OrderedDictionary] -or $settingValue -is [hashtable] -or $settingValue -is [array]) {
Add-Content -Encoding UTF8 -Path $env:GITHUB_ENV -Value "$setting=$(ConvertTo-Json $settingValue -Depth 99 -Compress)"
}
else {
Add-Content -Encoding UTF8 -Path $env:GITHUB_ENV -Value "$setting=$settingValue"
}
}
}
Write-Host "SETTINGS:"
$outSettings | ConvertTo-Json -Depth 99 | Out-Host
Add-Content -Encoding UTF8 -Path $env:GITHUB_ENV -Value "Settings=$($outSettings | ConvertTo-Json -Depth 99 -Compress)"
$gitHubRunner = $settings.githubRunner.Split(',').Trim() | ConvertTo-Json -compress
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "GitHubRunnerJson=$githubRunner"
Write-Host "GitHubRunnerJson=$githubRunner"
$gitHubRunnerShell = $settings.githubRunnerShell
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "GitHubRunnerShell=$githubRunnerShell"
Write-Host "GitHubRunnerShell=$githubRunnerShell"