2019-05-23 07:18:48 +03:00
|
|
|
<#
|
|
|
|
.Synopsis
|
|
|
|
Convert Output from AL Compiler and output to host in Azure DevOps format
|
|
|
|
.Description
|
|
|
|
This function is a contribution from Microsoft MVP Kamil Sacek, read about it here:
|
|
|
|
https://dynamicsuser.net/nav/b/kine/posts/alc-exe-output-formatting-for-tfs-vsts
|
|
|
|
.Parameter AlcOutput
|
|
|
|
One or more lines of outout from the AL Compiler
|
|
|
|
.Parameter Failon
|
|
|
|
Specify if you want the AzureDevOps output to fail on Error or Warning
|
2022-10-23 17:13:08 +03:00
|
|
|
.Parameter GitHubActions
|
|
|
|
Include this switch, if you are running GitHub Actions
|
2020-01-30 11:37:48 +03:00
|
|
|
.Parameter DoNotWriteToHost
|
|
|
|
Include this switch to return the converted result instead of outputting the result to the Host
|
2022-10-23 22:57:26 +03:00
|
|
|
.Parameter basePath
|
|
|
|
Base Path of the files in the ALC output, to convert file paths to relative paths
|
2019-05-23 07:18:48 +03:00
|
|
|
.Example
|
2020-07-31 10:16:25 +03:00
|
|
|
Compile-AppInBcContainer -containerName test -credential $credential -appProjectFolder "C:\Users\freddyk\Documents\AL\Test" -AzureDevOps
|
2021-08-31 10:22:02 +03:00
|
|
|
.Example
|
|
|
|
Compile-AppInBcContainer -containerName test -credential $credential -appProjectFolder "C:\Users\freddyk\Documents\AL\Test" -GitHubActions
|
2019-05-23 07:18:48 +03:00
|
|
|
.Example
|
|
|
|
& .\alc.exe /project:$appProjectFolder /packagecachepath:$appSymbolsFolder /out:$appOutputFile | Convert-AlcOutputToAzureDevOps
|
|
|
|
#>
|
2021-08-31 10:22:02 +03:00
|
|
|
Function Convert-AlcOutputToDevOps {
|
2019-09-03 12:42:17 +03:00
|
|
|
Param (
|
2019-05-23 07:18:48 +03:00
|
|
|
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
|
|
|
|
$AlcOutput,
|
|
|
|
[Parameter(Position=1)]
|
|
|
|
[ValidateSet('none','error','warning')]
|
2020-01-30 11:37:48 +03:00
|
|
|
[string] $FailOn,
|
2024-08-26 13:30:03 +03:00
|
|
|
[switch] $gitHubActions = $bcContainerHelperConfig.IsGitHubActions,
|
2022-10-23 21:23:35 +03:00
|
|
|
[switch] $doNotWriteToHost,
|
|
|
|
[string] $basePath = ''
|
2019-05-23 07:18:48 +03:00
|
|
|
)
|
|
|
|
|
2021-07-06 12:03:31 +03:00
|
|
|
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
|
2021-07-05 08:46:50 +03:00
|
|
|
try {
|
2022-10-23 21:23:35 +03:00
|
|
|
if ($basePath) {
|
2022-10-23 21:45:37 +03:00
|
|
|
$basePath = "$($basePath.TrimEnd('\'))\"
|
2022-10-23 20:29:03 +03:00
|
|
|
}
|
2021-07-01 22:44:04 +03:00
|
|
|
$hasError = $false
|
|
|
|
$hasWarning = $false
|
|
|
|
|
|
|
|
foreach($line in $AlcOutput) {
|
|
|
|
switch -regex ($line) {
|
2023-05-04 11:54:39 +03:00
|
|
|
"^warning (\w{2,3}\d{4}):(.*('.*').*|.*)$" {
|
2021-07-01 22:44:04 +03:00
|
|
|
if ($null -ne $Matches[3]) {
|
2022-10-23 21:23:35 +03:00
|
|
|
$file = $Matches[3]
|
|
|
|
if ($file -like "$($basePath)*") {
|
2022-10-23 22:09:36 +03:00
|
|
|
$file = ".\$($file.SubString($basePath.Length))".Replace('\','/')
|
2022-10-23 21:23:35 +03:00
|
|
|
}
|
2021-08-31 10:22:02 +03:00
|
|
|
if ($gitHubActions) {
|
2022-10-23 20:55:02 +03:00
|
|
|
$newLine = "::warning file=$($file)::code=$($Matches[1]) $($Matches[2])"
|
2021-08-31 10:22:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2022-10-23 21:23:35 +03:00
|
|
|
$newLine = "##vso[task.logissue type=warning;sourcepath=$($file);$($Matches[1]);]$($Matches[2])"
|
2021-08-31 10:22:02 +03:00
|
|
|
}
|
2021-07-01 22:44:04 +03:00
|
|
|
} else {
|
2021-08-31 10:22:02 +03:00
|
|
|
if ($gitHubActions) {
|
2022-10-23 20:55:02 +03:00
|
|
|
$newLine = "::warning::$($Matches[1]) $($Matches[2])"
|
2021-08-31 10:22:02 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$newLine = "##vso[task.logissue type=warning;code=$($Matches[1]);]$($Matches[2])"
|
|
|
|
}
|
2019-05-23 07:18:48 +03:00
|
|
|
}
|
2021-07-01 22:44:04 +03:00
|
|
|
|
|
|
|
$hasWarning = $true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
"^(.*)\((\d+),(\d+)\): error (\w{2,3}\d{4}): (.*)$"
|
|
|
|
#Objects\codeunit\Cod50130.name.al(62,30): error AL0118: The name '"Parent Object"' does not exist in the current context
|
|
|
|
{
|
2022-10-23 21:23:35 +03:00
|
|
|
$file = $Matches[1]
|
|
|
|
if ($file -like "$($basePath)*") {
|
2022-10-23 22:09:36 +03:00
|
|
|
$file = ".\$($file.SubString($basePath.Length))".Replace('\','/')
|
2022-10-23 21:23:35 +03:00
|
|
|
}
|
2021-08-31 10:22:02 +03:00
|
|
|
if ($gitHubActions) {
|
2022-10-23 20:55:02 +03:00
|
|
|
$newLine = "::error file=$($file),line=$($Matches[2]),col=$($Matches[3])::$($Matches[4]) $($Matches[5])"
|
2021-08-31 10:22:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2022-10-23 21:23:35 +03:00
|
|
|
$newLine = "##vso[task.logissue type=error;sourcepath=$($file);linenumber=$($Matches[2]);columnnumber=$($Matches[3]);code=$($Matches[4]);]$($Matches[5])"
|
2021-08-31 10:22:02 +03:00
|
|
|
}
|
2021-07-01 22:44:04 +03:00
|
|
|
$hasError = $true
|
|
|
|
break
|
2019-05-23 07:18:48 +03:00
|
|
|
}
|
2023-05-04 11:54:39 +03:00
|
|
|
"^(.*)error (\w{2,3}\d{4}): (.*)$"
|
2021-07-01 22:44:04 +03:00
|
|
|
#error AL0999: Internal error: System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException
|
|
|
|
{
|
2021-08-31 10:22:02 +03:00
|
|
|
if ($gitHubActions) {
|
2022-10-23 20:55:02 +03:00
|
|
|
$newLine = "::error::$($Matches[2]) $($Matches[3])"
|
2021-08-31 10:22:02 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$newLine = "##vso[task.logissue type=error;code=$($Matches[2]);]$($Matches[3])"
|
|
|
|
}
|
2021-07-01 22:44:04 +03:00
|
|
|
$hasError = $true
|
|
|
|
break
|
2020-01-30 11:37:48 +03:00
|
|
|
}
|
2023-05-04 11:54:39 +03:00
|
|
|
"^(.*)\((\d+),(\d+)\): warning (\w{2,3}\d{4}): (.*)$"
|
2021-07-01 22:44:04 +03:00
|
|
|
#Prepared for unified warning format
|
|
|
|
#Objects\codeunit\Cod50130.name.al(62,30): warning AL0118: The name '"Parent Object"' does not exist in the current context
|
|
|
|
{
|
2022-10-23 21:23:35 +03:00
|
|
|
$file = $Matches[1]
|
|
|
|
if ($file -like "$($basePath)*") {
|
2022-10-23 22:09:36 +03:00
|
|
|
$file = ".\$($file.SubString($basePath.Length))".Replace('\','/')
|
2022-10-23 21:23:35 +03:00
|
|
|
}
|
2021-08-31 10:22:02 +03:00
|
|
|
if ($gitHubActions) {
|
2022-10-23 20:55:02 +03:00
|
|
|
$newLine = "::warning file=$($file),line=$($Matches[2]),col=$($Matches[3])::$($Matches[4]) $($Matches[5])"
|
2021-08-31 10:22:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2022-10-23 21:23:35 +03:00
|
|
|
$newLine = "##vso[task.logissue type=warning;sourcepath=$($file);linenumber=$($Matches[2]);columnnumber=$($Matches[3]);code=$($Matches[4]);]$($Matches[5])"
|
2021-08-31 10:22:02 +03:00
|
|
|
}
|
2021-07-01 22:44:04 +03:00
|
|
|
$hasWarning = $true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
default {
|
|
|
|
$newLine = $line
|
|
|
|
break
|
2020-01-30 11:37:48 +03:00
|
|
|
}
|
2019-05-23 07:18:48 +03:00
|
|
|
}
|
2021-07-01 22:44:04 +03:00
|
|
|
if ($doNotWriteToHost) {
|
|
|
|
$newLine
|
2021-01-17 20:07:33 +03:00
|
|
|
}
|
2021-07-01 22:44:04 +03:00
|
|
|
else {
|
|
|
|
Write-Host $newLine
|
2021-01-17 20:07:33 +03:00
|
|
|
}
|
2021-07-01 22:44:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$errLine = ""
|
2022-10-23 17:13:08 +03:00
|
|
|
if ($gitHubActions) {
|
|
|
|
if ($FailOn -eq 'warning' -and $hasWarning) {
|
|
|
|
$errLine = "::Error::Failing build as warnings exists"
|
2022-10-23 20:29:03 +03:00
|
|
|
$host.SetShouldExit(1)
|
2022-10-23 17:13:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-08-31 10:22:02 +03:00
|
|
|
if (($FailOn -eq 'error' -and $hasError) -or ($FailOn -eq 'warning' -and ($hasError -or $hasWarning))) {
|
|
|
|
$errLine = "##vso[task.complete result=Failed;]Failed."
|
|
|
|
}
|
|
|
|
elseif ($failOn -eq 'error' -and $hasWarning) {
|
|
|
|
$errLine = "##vso[task.complete result=SucceededWithIssues;]Succeeded With Issues."
|
|
|
|
}
|
2021-07-01 22:44:04 +03:00
|
|
|
}
|
|
|
|
if ($errLine) {
|
|
|
|
if ($doNotWriteToHost) {
|
|
|
|
$errLine
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Host $errLine
|
2019-05-23 07:18:48 +03:00
|
|
|
}
|
|
|
|
}
|
2021-07-05 08:46:50 +03:00
|
|
|
}
|
|
|
|
catch {
|
2021-07-01 22:44:04 +03:00
|
|
|
TrackException -telemetryScope $telemetryScope -errorRecord $_
|
2021-07-05 08:46:50 +03:00
|
|
|
throw
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
TrackTrace -telemetryScope $telemetryScope
|
|
|
|
}
|
2019-05-23 07:18:48 +03:00
|
|
|
}
|
2022-10-23 17:13:08 +03:00
|
|
|
Set-Alias -Name Convert-AlcOutputToAzureDevOps -Value Convert-AlcOutputToDevOps
|
|
|
|
Export-ModuleMember -Function Convert-AlcOutputToDevOps -Alias Convert-AlcOutputToAzureDevOps
|