Skip to content

Commit 3a5d393

Browse files
authored
Merge branch 'main' into DeployToEnvVar
2 parents 8716c6e + 0e080a3 commit 3a5d393

File tree

13 files changed

+376
-86
lines changed

13 files changed

+376
-86
lines changed
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
2+
if ($env:GITHUB_ACTIONS -eq "true") {
3+
$runningLocal = $false
4+
} else {
5+
$runningLocal = $true
6+
}
7+
8+
# Colors
9+
$colorCodeRed = '31'
10+
$colorCodeGreen = '32'
11+
$colorCodeYellow = '33'
12+
$colorCodeBlue = '34'
13+
$colorCodeMagenta = '35'
14+
$colorCodeCyan = '36'
15+
16+
<#
17+
.SYNOPSIS
18+
Writes debug information about the function call and its parameters if extended debug logging is enabled or running locally.
19+
.DESCRIPTION
20+
Writes debug information about the function call and its parameters to the console if extended debug logging is enabled or running locally.
21+
Automatically retrieves the caller's name and arguments from the call stack.
22+
#>
23+
function OutputDebugFunctionCall {
24+
try {
25+
$caller = (Get-PSCallStack)[1]
26+
$callerName = $caller.Command
27+
$callerParameters = $caller.InvocationInfo.BoundParameters
28+
29+
OutputDebug "Function '$callerName' called with parameters:"
30+
if ($callerParameters.Count -eq 0) {
31+
OutputDebug "None"
32+
}
33+
foreach ($key in $callerParameters.Keys) {
34+
$val = $callerParameters[$key]
35+
OutputDebug "-$($key): $val"
36+
}
37+
} catch {
38+
OutputDebug "Unable to retrieve function information from call stack."
39+
}
40+
}
41+
42+
<#
43+
.SYNOPSIS
44+
Starts a console log group.
45+
.DESCRIPTION
46+
Starts a console log group. All subsequent log messages will be grouped under this message until OutputGroupEnd is called.
47+
If running locally, it writes a simple message to the console. If running in GitHub Actions, it uses the `::group::` command to create a collapsible group in the log.
48+
.PARAMETER Message
49+
Name/Title of the group.
50+
#>
51+
function OutputGroupStart {
52+
param (
53+
[Parameter(Mandatory = $true)]
54+
[string] $Message
55+
)
56+
57+
if ($runningLocal) {
58+
Write-Host "==== Group start: $Message ===="
59+
} else {
60+
Write-Host "::group::$Message"
61+
}
62+
}
63+
64+
<#
65+
.SYNOPSIS
66+
Ends a console log group.
67+
.DESCRIPTION
68+
Ends a console log group started with OutputGroupStart. All subsequent log messages will be outside of this group.
69+
#>
70+
function OutputGroupEnd {
71+
if ($runningLocal) {
72+
Write-Host "==== Group end ===="
73+
} else {
74+
Write-Host "::endgroup::"
75+
}
76+
}
77+
78+
<#
79+
.SYNOPSIS
80+
Writes to console with optional color.
81+
.DESCRIPTION
82+
Writes a message to the console with an optional color. If no color is specified, the message is written in the default console color.
83+
.PARAMETER Message
84+
Message to be written to console.
85+
.PARAMETER Color
86+
Optional color for the message. Valid values are 'Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan'.
87+
#>
88+
function OutputColor {
89+
param (
90+
[Parameter(Mandatory = $true)]
91+
[string] $Message,
92+
[Parameter(Mandatory = $false)]
93+
[ValidateSet('Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan')]
94+
[string] $Color
95+
)
96+
97+
if ($Color) {
98+
$colorCode = 0
99+
switch ($Color) {
100+
'Red' { $colorCode = $colorCodeRed }
101+
'Green' { $colorCode = $colorCodeGreen }
102+
'Yellow' { $colorCode = $colorCodeYellow }
103+
'Blue' { $colorCode = $colorCodeBlue }
104+
'Magenta' { $colorCode = $colorCodeMagenta }
105+
'Cyan' { $colorCode = $colorCodeCyan }
106+
}
107+
# char 27 is the escape character for ANSI codes which works in both PS 5 and 7.
108+
Write-Host "$([char] 27)[${colorCode}m$Message$([char] 27)[0m"
109+
} else {
110+
Write-Host $Message
111+
}
112+
}
113+
114+
<#
115+
.SYNOPSIS
116+
Write an error message to the console.
117+
.DESCRIPTION
118+
Writes an error message to the console. Throws an exception if running locally, otherwise formats the message for GitHub Actions.
119+
.PARAMETER Message
120+
Message to be written to console.
121+
#>
122+
function OutputError {
123+
Param(
124+
[string] $message
125+
)
126+
127+
if ($runningLocal) {
128+
throw $message
129+
}
130+
else {
131+
Write-Host "::Error::$($message.Replace("`r",'').Replace("`n",' '))"
132+
$host.SetShouldExit(1)
133+
}
134+
}
135+
136+
<#
137+
.SYNOPSIS
138+
Write a warning message to the console.
139+
.DESCRIPTION
140+
Writes a warning message to the console. Uses Write-Warning if running locally, otherwise formats the message for GitHub Actions.
141+
.PARAMETER Message
142+
Message to be written to console.
143+
#>
144+
function OutputWarning {
145+
Param(
146+
[string] $message
147+
)
148+
149+
if ($runningLocal) {
150+
Write-Warning $message
151+
}
152+
else {
153+
Write-Host "::Warning::$message"
154+
}
155+
}
156+
157+
<#
158+
.SYNOPSIS
159+
Write a notice message to the console.
160+
.DESCRIPTION
161+
Writes a notice message to the console. Uses regular Write-Host if running locally, otherwise formats the message for GitHub Actions.
162+
.PARAMETER Message
163+
Message to be written to console.
164+
#>
165+
function OutputNotice {
166+
Param(
167+
[string] $message
168+
)
169+
170+
if ($runningLocal) {
171+
Write-Host $message
172+
}
173+
else {
174+
Write-Host "::Notice::$message"
175+
}
176+
}
177+
178+
<#
179+
.SYNOPSIS
180+
Mask a value in the log.
181+
.DESCRIPTION
182+
Masks a value in the log to prevent sensitive information from being displayed. If running locally, it writes the masked value to the console.
183+
.PARAMETER Value
184+
The value to be masked in the log.
185+
#>
186+
function MaskValueInLog {
187+
Param(
188+
[string] $value
189+
)
190+
191+
if (!$runningLocal) {
192+
Write-Host "`r::add-mask::$value"
193+
}
194+
}
195+
196+
<#
197+
.SYNOPSIS
198+
Write a debug message to the console.
199+
.DESCRIPTION
200+
Writes a debug message to the console. Uses Write-Debug if running locally, otherwise formats the message for GitHub Actions.
201+
.PARAMETER Message
202+
Message to be written to console.
203+
#>
204+
function OutputDebug {
205+
Param(
206+
[string] $message
207+
)
208+
209+
if ($runningLocal) {
210+
Write-Debug $message
211+
}
212+
else {
213+
Write-Host "::Debug::[AL-Go]$message"
214+
}
215+
}
216+
217+
Export-ModuleMember -Function OutputColor, OutputDebugFunctionCall, OutputGroupStart, OutputGroupEnd, OutputError, OutputWarning, OutputNotice, MaskValueInLog, OutputDebug
218+
Export-ModuleMember -Variable debugLoggingEnabled

Actions/AL-Go-Helper.ps1

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Param(
44

55
$gitHubHelperPath = Join-Path $PSScriptRoot 'Github-Helper.psm1'
66
$readSettingsModule = Join-Path $PSScriptRoot '.Modules/ReadSettings.psm1'
7+
$debugLoggingModule = Join-Path $PSScriptRoot '.Modules/DebugLogHelper.psm1'
78
if (Test-Path $gitHubHelperPath) {
89
Import-Module $gitHubHelperPath
910
# If we are adding more dependencies here, then localDevEnv and cloudDevEnv needs to be updated
@@ -13,6 +14,10 @@ if (Test-Path $readSettingsModule) {
1314
Import-Module $readSettingsModule
1415
}
1516

17+
if (Test-Path $debugLoggingModule) {
18+
Import-Module $debugLoggingModule
19+
}
20+
1621
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
1722

1823
$ALGoFolderName = '.AL-Go'
@@ -22,7 +27,6 @@ $RepoSettingsFile = Join-Path '.github' 'AL-Go-Settings.json'
2227
$defaultCICDPushBranches = @( 'main', 'release/*', 'feature/*' )
2328
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'defaultCICDPullRequestBranches', Justification = 'False positive.')]
2429
$defaultCICDPullRequestBranches = @( 'main' )
25-
$runningLocal = $local.IsPresent
2630
$defaultBcContainerHelperVersion = "preview" # Must be double quotes. Will be replaced by BcContainerHelperVersion if necessary in the deploy step - ex. "https://github.com/organization/navcontainerhelper/archive/refs/heads/branch.zip"
2731
$notSecretProperties = @("Scopes","TenantId","BlobName","ContainerName","StorageAccountName","ServerUrl","ppUserName","GitHubAppClientId","EnvironmentName")
2832

@@ -183,69 +187,6 @@ function ConvertTo-HashTable() {
183187
}
184188
}
185189

186-
function OutputError {
187-
Param(
188-
[string] $message
189-
)
190-
191-
if ($runningLocal) {
192-
throw $message
193-
}
194-
else {
195-
Write-Host "::Error::$($message.Replace("`r",'').Replace("`n",' '))"
196-
$host.SetShouldExit(1)
197-
}
198-
}
199-
200-
function OutputWarning {
201-
Param(
202-
[string] $message
203-
)
204-
205-
if ($runningLocal) {
206-
Write-Host -ForegroundColor Yellow "WARNING: $message"
207-
}
208-
else {
209-
Write-Host "::Warning::$message"
210-
}
211-
}
212-
213-
function OutputNotice {
214-
Param(
215-
[string] $message
216-
)
217-
218-
if ($runningLocal) {
219-
Write-Host $message
220-
}
221-
else {
222-
Write-Host "::Notice::$message"
223-
}
224-
}
225-
226-
function MaskValueInLog {
227-
Param(
228-
[string] $value
229-
)
230-
231-
if (!$runningLocal) {
232-
Write-Host "`r::add-mask::$value"
233-
}
234-
}
235-
236-
function OutputDebug {
237-
Param(
238-
[string] $message
239-
)
240-
241-
if ($runningLocal) {
242-
Write-Host $message
243-
}
244-
else {
245-
Write-Host "::Debug::$message"
246-
}
247-
}
248-
249190
function GetUniqueFolderName {
250191
Param(
251192
[string] $baseFolder,

Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
[ValidateSet('CD','Publish','All')]
66
[string] $type
77
)
8+
OutputDebugFunctionCall
89

910
function IsGitHubPagesAvailable() {
11+
OutputDebugFunctionCall
1012
$headers = GetHeaders -token $env:GITHUB_TOKEN
1113
$url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/pages"
14+
OutputDebug "Url: $url"
1215
try {
1316
Write-Host "Requesting GitHub Pages settings from GitHub"
1417
$ghPages = (InvokeWebRequest -Headers $headers -Uri $url).Content | ConvertFrom-Json
@@ -20,8 +23,10 @@ function IsGitHubPagesAvailable() {
2023
}
2124

2225
function GetGitHubEnvironments() {
26+
OutputDebugFunctionCall
2327
$headers = GetHeaders -token $env:GITHUB_TOKEN
2428
$url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/environments"
29+
OutputDebug "Url: $url"
2530
try {
2631
Write-Host "Requesting environments from GitHub"
2732
$ghEnvironments = @(((InvokeWebRequest -Headers $headers -Uri $url).Content | ConvertFrom-Json).environments)
@@ -34,6 +39,7 @@ function GetGitHubEnvironments() {
3439
}
3540

3641
function Get-BranchesFromPolicy($ghEnvironment) {
42+
OutputDebugFunctionCall
3743
if ($ghEnvironment) {
3844
# Environment is defined in GitHub - check protection rules
3945
$headers = GetHeaders -token $env:GITHUB_TOKEN

Actions/IncrementVersionNumber/IncrementVersionNumber.ps1

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ if ($projectList.Count -eq 0 -and $PPprojects.Count -eq 0) {
5757
$repositorySettingsPath = Join-Path $baseFolder $RepoSettingsFile # $RepoSettingsFile is defined in AL-Go-Helper.ps1
5858

5959
# Increment version number in AL Projects
60+
$allAppFolders = @()
6061
if ($projectList.Count -gt 0) {
61-
$allAppFolders = @()
6262
$repoVersionExistsInRepoSettings = Test-SettingExists -settingsFilePath $repositorySettingsPath -settingName 'repoVersion'
6363
$repoVersionInRepoSettingsWasUpdated = $false
6464
foreach ($project in $projectList) {
@@ -89,25 +89,13 @@ if ($projectList.Count -gt 0) {
8989
$projectSettings = ReadSettings -baseFolder $baseFolder -project $project
9090
ResolveProjectFolders -baseFolder $baseFolder -project $project -projectSettings ([ref] $projectSettings)
9191

92-
# Set version in app manifests (app.json files)
93-
Set-VersionInAppManifests -projectPath $projectPath -projectSettings $projectSettings -newValue $versionNumber
94-
95-
# Collect all project's app folders
96-
$allAppFolders += $projectSettings.appFolders | ForEach-Object { Join-Path $projectPath $_ -Resolve }
97-
$allAppFolders += $projectSettings.testFolders | ForEach-Object { Join-Path $projectPath $_ -Resolve }
98-
$allAppFolders += $projectSettings.bcptTestFolders | ForEach-Object { Join-Path $projectPath $_ -Resolve }
92+
Set-VersionInAppManifests -projectPath $projectPath -projectSettings $projectSettings -newValue $versionNumber -updatedAppFolders ([ref] $allAppFolders)
9993
}
94+
}
10095

101-
if (-not $skipUpdatingDependencies) {
102-
# Set dependencies in app manifests
103-
if ($allAppFolders.Count -eq 0) {
104-
Write-Host "No App folders found for projects $projects"
105-
}
106-
else {
107-
# Set dependencies in app manifests
108-
Set-DependenciesVersionInAppManifests -appFolders $allAppFolders
109-
}
110-
}
96+
if (-not $skipUpdatingDependencies) {
97+
# Set dependencies in app manifests
98+
Set-DependenciesVersionInAppManifests -appFolders $allAppFolders
11199
}
112100

113101
# Increment version number in PowerPlatform Solution

0 commit comments

Comments
 (0)