-
Notifications
You must be signed in to change notification settings - Fork 170
Give a warning before trying to publish symbols-only packages #1795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
24c4c52
0eb0a76
9c7f8b4
09e53bc
687d718
f2cf24d
9faedc2
6df6f34
c82b46a
7e7b46d
34911af
1074645
9944de5
6924568
30d9e77
282f746
b15b339
072b03e
e50f890
e46aafa
e21a2c0
08f1363
e0baefb
c743f37
919f056
653d30f
a9233f8
247cbee
7c83581
7fb375f
358c354
c081bd3
ef12a55
ad84033
90e4464
0d1e268
bc4f66e
399f95f
2fd11c6
6cf06ef
11b606b
6880602
5c1e835
d1a114b
0c039c9
7940041
df3d496
f234e63
bf4a636
9c98d08
e7dd1ee
640432c
8582aa5
4142b08
d00775c
912c6fe
0f08f62
0dc2823
3d50f4d
00162c0
12b68c1
b152674
f0b1d7c
d3838c9
986b0e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| Import-Module (Join-Path $PSScriptRoot '..\TelemetryHelper.psm1' -Resolve) | ||
| . (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve) | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Installs the AL tool. | ||
| .DESCRIPTION | ||
| Installs the AL tool from the Microsoft.Dynamics.BusinessCentral.Development.Tools package. | ||
| .RETURNS | ||
| The path to the al.exe tool. | ||
| #> | ||
| function Install-ALTool { | ||
| $DevelopmentToolsPackage = "Microsoft.Dynamics.BusinessCentral.Development.Tools" | ||
| $alToolFolder = Install-DotNetTool -PackageName $DevelopmentToolsPackage | ||
| # Load the AL tool from the downloaded package | ||
| $alExe = Get-ChildItem -Path $alToolFolder -Filter "al*" | Where-Object { $_.Name -eq "al" -or $_.Name -eq "al.exe" } | Select-Object -First 1 -ExpandProperty FullName | ||
| if (-not $alExe) { | ||
| throw "Could not find al.exe in the $DevelopmentToolsPackage package." | ||
| } | ||
| return $alExe | ||
| } | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Analyzes the install apps to check if they are symbols packages. | ||
| .DESCRIPTION | ||
| Analyzes the install apps to check if they are symbols packages. | ||
| If an app is a symbols package, it outputs a warning message. | ||
| .PARAMETER AllInstallApps | ||
| The list of all install apps to analyze. | ||
| .PARAMETER ProjectPath | ||
| The path to the project where the apps are located. | ||
| #> | ||
| function Test-InstallApps() { | ||
| Param( | ||
| [string[]] $AllInstallApps, | ||
| [string] $ProjectPath | ||
| ) | ||
|
|
||
| if ($AllInstallApps.Count -eq 0) { | ||
| Write-Host "No install apps to analyze." | ||
| return | ||
| } | ||
|
|
||
| try { | ||
| # Install the AL tool and get the path to al.exe | ||
| $alExe = Install-ALTool | ||
|
|
||
| foreach ($app in $AllInstallApps) { | ||
| if (Test-Path -Path $app) { | ||
| $appFilePath = (Get-Item -Path $app).FullName | ||
| } else { | ||
| $appFilePath = Join-Path $ProjectPath $app -Resolve -ErrorAction SilentlyContinue | ||
| } | ||
|
|
||
| if ($appFilePath) { | ||
| $appFile = Get-Item -Path $appFilePath | ||
| $appFileName = $appFile.Name | ||
| Write-Host "Analyzing app file $appFileName" | ||
| if (IsSymbolsOnlyPackage -AppFilePath $appFile -AlExePath $alExe) { | ||
| # If package is not a runtime package and has no source code files, it is a symbols package | ||
| # Symbols packages are not meant to be published to a BC Environment | ||
| OutputWarning -Message "App $appFileName is a symbols package and should not be published. The workflow may fail if you try to publish it." | ||
| } | ||
| } else { | ||
| Write-Host "App file path for $app could not be resolved. Skipping symbols check." | ||
| } | ||
| } | ||
| } | ||
| catch { | ||
| Trace-Warning -Message "Something went wrong while analyzing install apps." | ||
| OutputDebug -message "Error: $_" | ||
| } | ||
| } | ||
|
|
||
| function IsSymbolsOnlyPackage { | ||
| param( | ||
| [string] $AppFilePath, | ||
|
||
| [string] $AlExePath | ||
| ) | ||
| . $AlExePath IsSymbolOnly $AppFilePath | Out-Null | ||
| return $LASTEXITCODE -eq 0 | ||
| } | ||
|
|
||
| Export-ModuleMember -Function Test-InstallApps | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,27 @@ Describe "RunPipeline Action Tests" { | |
| YamlTest -scriptRoot $scriptRoot -actionName $actionName -actionScript $actionScript -outputs $outputs | ||
| } | ||
|
|
||
| It 'Test warning for symbols packages' { | ||
| Import-Module (Join-Path $scriptRoot '.\RunPipeline.psm1' -Resolve) -Force | ||
| . (Join-Path $PSScriptRoot '../Actions/AL-Go-Helper.ps1') | ||
| Import-Module (Join-Path $PSScriptRoot '../Actions/TelemetryHelper.psm1') | ||
|
|
||
| # Mock the OutputWarning and Trace-Warning functions | ||
| Mock -CommandName OutputWarning -MockWith { param($Message) Write-Host "OutputWarning: $Message" } -ModuleName RunPipeline | ||
| Mock -CommandName Trace-Warning -MockWith { param($Message) Write-Host "Trace-Information: $Message" } -ModuleName RunPipeline | ||
|
|
||
| # Invoke the function with TestApp1 (a symbols package) and TestApp2 (a full app package) | ||
| $tempFolder = [System.IO.Path]::GetTempPath() | ||
| Test-InstallApps -AllInstallApps @(".\TestApps\EssentialBusinessHeadlinesFull.app", ".\TestApps\EssentialBusinessHeadlinesSymbols.app") -ProjectPath $PSScriptRoot -RunnerTempFolder $tempFolder | ||
|
|
||
| # Assert that the warning was output | ||
| Should -Invoke -CommandName 'OutputWarning' -Times 1 -ModuleName RunPipeline | ||
| Should -Invoke -CommandName 'OutputWarning' -Times 1 -ModuleName RunPipeline -ParameterFilter { $Message -like "*App EssentialBusinessHeadlinesSymbols.app is a symbols package and should not be published. The workflow may fail if you try to publish it." } | ||
|
|
||
| # Assert that Trace-Warning was not called | ||
| Assert-MockCalled Trace-Warning -Exactly 0 -ModuleName RunPipeline | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not trace the warning actually?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only trace a warning to telemetry if there is some internal error in the check. This asserts that it didn't fail during the analysis.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what I mean: why not also trace a warning also when symbols are about to be published? |
||
| } | ||
|
|
||
| # Call action | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check was added to fail early, if case the URL isn't accessible.
Now that apps are downloaded a couple of lines below, this check isn't necessary.