Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Actions/.Modules/ReadSettings.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ function GetDefaultSettings
}
"fullBuildPatterns" = @()
"excludeEnvironments" = @()
"noMatchingEnvironmentsAction" = "ignore"
"alDoc" = [ordered]@{
"continuousDeployment" = $false
"deployToGitHubPages" = $true
Expand Down
5 changes: 5 additions & 0 deletions Actions/.Modules/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,11 @@
},
"description": "An array of environments to be excluded from the build. See https://aka.ms/ALGoSettings#excludeenvironments"
},
"noMatchingEnvironmentsAction": {
"type": "string",
"pattern": "^(ignore|warning|error)$",
"description": "Specifies what happens when deployment environments are found but all are excluded by branch policies or deployment type filters. Allowed values are ignore, warning and error. See https://aka.ms/ALGoSettings#nomatchingenvironmentsaction"
},
"alDoc": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,15 @@ else {
}
}
if (!$includeEnvironment) {
Write-Host "Environment $environmentName is not setup for deployments from branch $ENV:GITHUB_REF_NAME"
if ($deploymentSettings.BranchesFromPolicy -and $deploymentSettings.BranchesFromPolicy.Count -gt 0) {
Write-Host "Environment $environmentName is not setup for deployments from branch '$($ENV:GITHUB_REF_NAME)' (GitHub policy allows branches: $($deploymentSettings.BranchesFromPolicy -join ', '))"
}
elseif ($deploymentSettings.Branches -and $deploymentSettings.Branches.Count -gt 0) {
Write-Host "Environment $environmentName is not setup for deployments from branch '$($ENV:GITHUB_REF_NAME)' (allowed branches in settings: $($deploymentSettings.Branches -join ', '))"
}
else {
Write-Host "Environment $environmentName is not setup for deployments from branch '$($ENV:GITHUB_REF_NAME)' (no branch policy defined - only 'main' is allowed by default)"
}
}
}
if ($includeEnvironment) {
Expand Down Expand Up @@ -304,3 +312,18 @@ Write-Host "EnvironmentCount=$($deploymentEnvironments.Keys.Count)"

Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "UnknownEnvironment=$unknownEnvironment"
Write-Host "UnknownEnvironment=$unknownEnvironment"

# Handle noMatchingEnvironmentsAction when environments were found but all filtered out
if ($deploymentEnvironments.Keys.Count -eq 0 -and $environments -and @($environments).Count -gt 0) {
$noMatchAction = if ($settings.ContainsKey('noMatchingEnvironmentsAction')) { $settings.noMatchingEnvironmentsAction } else { 'ignore' }
$message = "No environments matched deployment criteria. $(@($environments).Count) environment(s) were found ($($environments -join ', ')) but all were excluded by branch policies or deployment type filters. Current branch: $ENV:GITHUB_REF_NAME"
switch ($noMatchAction) {
'warning' {
OutputWarning $message
}
'error' {
throw $message
}
# 'ignore' - current behavior, do nothing
}
}
25 changes: 13 additions & 12 deletions Actions/DumpWorkflowInfo/DumpWorkflowInfo.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Write-Host "Event name: $env:GITHUB_EVENT_NAME"
if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') {
Write-Host "Inputs:"
$eventPath = Get-Content -Encoding UTF8 -Path $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json
if ($null -ne $eventPath.inputs) {
$eventPath.inputs.psObject.Properties | Sort-Object { $_.Name } | ForEach-Object {
$property = $_.Name
$value = $eventPath.inputs."$property"
Write-Host "- $property = '$value'"
}
}
}
Write-Host "Event name: $env:GITHUB_EVENT_NAME"
Write-Host "Branch: $env:GITHUB_REF_NAME"
if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') {
Write-Host "Inputs:"
$eventPath = Get-Content -Encoding UTF8 -Path $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json
if ($null -ne $eventPath.inputs) {
$eventPath.inputs.psObject.Properties | Sort-Object { $_.Name } | ForEach-Object {
$property = $_.Name
$value = $eventPath.inputs."$property"
Write-Host "- $property = '$value'"
}
}
}
2 changes: 2 additions & 0 deletions Scenarios/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ The repository settings are only read from the repository settings file (.github
| <a id="assignPremiumPlan"></a>assignPremiumPlan | Setting assignPremiumPlan to true in your project setting file, causes the build container to be created with the AssignPremiumPlan set. This causes the auto-created user to have Premium Plan enabled. This setting is needed if your tests require premium plan enabled. | false |
| <a id="enableTaskScheduler"></a>enableTaskScheduler | Setting enableTaskScheduler to true in your project setting file, causes the build container to be created with the Task Scheduler running. | false |
| <a id="useCompilerFolder"></a>useCompilerFolder | Setting useCompilerFolder to true causes your pipelines to use containerless compiling. Unless you also set **doNotPublishApps** to true, setting useCompilerFolder to true won't give you any performance advantage, since AL-Go for GitHub will still need to create a container in order to publish and test the apps. In the future, publishing and testing will be split from building and there will be other options for getting an instance of Business Central for publishing and testing. **Note** when using UseCompilerFolder you need to sign apps using the new signing mechanism described [here](../Scenarios/Codesigning.md). | false |
| <a id="excludeEnvironments"></a>excludeEnvironments | excludeEnvironments can be an array of GitHub Environments, which should be excluded from the list of environments considered for deployment. github-pages is automatically added to this array and cannot be used as environment for deployment of AL-Go for GitHub projects. | [ ] |
| <a id="noMatchingEnvironmentsAction"></a>noMatchingEnvironmentsAction | Specifies what happens when deployment environments are found but all are excluded by branch policies or deployment type filters, resulting in nothing being deployed. Allowed values are **ignore** (workflow succeeds silently, current default behavior), **warning** (workflow succeeds but shows a visible warning annotation), and **error** (workflow fails with a clear error message). | ignore |
| <a id="workspaceCompilation"></a>workspaceCompilation | **PREVIEW:** Configuration for workspace compilation. This uses the AL tool to compile all apps in the workspace in a single operation, which can improve build performance for repositories with multiple apps. Like **useCompilerFolder**, this is containerless compiling.<br />**enabled** - Set to true to enable workspace compilation. Default: false.<br />**parallelism** - The number of parallel compilation processes. Set to 0 or -1 to use all available processors. Default: 1.<br /><br />**Current limitations:**<ul><li>Upgrade testing is not performed (previousApps are not downloaded).</li><li>AppSourceCop baseline validation against the previous release is not supported.</li><li>BCPT test folders are not compiled by workspace compilation.</li><li>Linux runners are not supported yet.</li></ul> | { "enabled": false, "parallelism": 1 } |
| <a id="excludeEnvironments"></a>excludeEnvironments| excludeEnvironments can be an array of GitHub Environments, which should be excluded from the list of environments considered for deployment. github-pages is automatically added to this array and cannot be used as environment for deployment of AL-Go for GitHub projects. | [ ] |
| <a id="trustMicrosoftNuGetFeeds"></a>trustMicrosoftNuGetFeeds | Unless this setting is set to false, AL-Go for GitHub will trust the NuGet feeds provided by Microsoft. The feeds provided by Microsoft contains all Microsoft apps, all Microsoft symbols and symbols for all AppSource apps. | true |
Expand Down
65 changes: 65 additions & 0 deletions Tests/DetermineDeploymentEnvironments.Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,69 @@ Describe "DetermineDeploymentEnvironments Action Test" {
$EnvironmentCount | Should -Be 0
$UnknownEnvironment | Should -Be 0
}

# noMatchingEnvironmentsAction = ignore (default) - should succeed silently when all environments are filtered out by branch policy
It 'Test calling action directly - noMatchingEnvironmentsAction ignore should succeed silently' {
Mock InvokeWebRequest -ParameterFilter { $uri -like '*/environments' } -MockWith {
return @{"Content" = (ConvertTo-Json -Compress -Depth 99 -InputObject @{ "environments" = @( @{ "name" = "test"; "protection_rules" = @() } ) })}
}

$settings = @{
"type" = "PTE"; "runs-on" = "ubuntu-latest"; "shell" = "pwsh"; "environments" = @(); "excludeEnvironments" = @( 'github-pages' )
"alDoc" = @{ "continuousDeployment" = $false; "deployToGitHubPages" = $false }
"noMatchingEnvironmentsAction" = "ignore"
"DeployToTest" = @{ "Branches" = @("release/*") }
}
$env:Settings = $settings | ConvertTo-Json -Compress
$env:GITHUB_REF_NAME = "feature/my-feature"

# Should succeed silently with 0 environments
. (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'Publish'
PassGeneratedOutput
$EnvironmentCount | Should -Be 0
}

# noMatchingEnvironmentsAction = warning - should succeed with a warning when all environments are filtered out by branch policy
It 'Test calling action directly - noMatchingEnvironmentsAction warning should output warning' {
Mock InvokeWebRequest -ParameterFilter { $uri -like '*/environments' } -MockWith {
return @{"Content" = (ConvertTo-Json -Compress -Depth 99 -InputObject @{ "environments" = @( @{ "name" = "test"; "protection_rules" = @() } ) })}
}

$settings = @{
"type" = "PTE"; "runs-on" = "ubuntu-latest"; "shell" = "pwsh"; "environments" = @(); "excludeEnvironments" = @( 'github-pages' )
"alDoc" = @{ "continuousDeployment" = $false; "deployToGitHubPages" = $false }
"noMatchingEnvironmentsAction" = "warning"
"DeployToTest" = @{ "Branches" = @("release/*") }
}
$env:Settings = $settings | ConvertTo-Json -Compress
$env:GITHUB_REF_NAME = "feature/my-feature"

# Should succeed but output a warning
# OutputWarning uses Write-Warning when running locally, but Write-Host (::Warning::) on GitHub Actions.
# Capture all output streams so we can check for the message in either case.
$allOutput = . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'Publish' *>&1
PassGeneratedOutput
$EnvironmentCount | Should -Be 0
# Verify the warning was emitted in any output stream
$allOutput | Should -Match "No environments matched deployment criteria"
}

# noMatchingEnvironmentsAction = error - should throw when all environments are filtered out by branch policy
It 'Test calling action directly - noMatchingEnvironmentsAction error should throw' {
Mock InvokeWebRequest -ParameterFilter { $uri -like '*/environments' } -MockWith {
return @{"Content" = (ConvertTo-Json -Compress -Depth 99 -InputObject @{ "environments" = @( @{ "name" = "test"; "protection_rules" = @() } ) })}
}

$settings = @{
"type" = "PTE"; "runs-on" = "ubuntu-latest"; "shell" = "pwsh"; "environments" = @(); "excludeEnvironments" = @( 'github-pages' )
"alDoc" = @{ "continuousDeployment" = $false; "deployToGitHubPages" = $false }
"noMatchingEnvironmentsAction" = "error"
"DeployToTest" = @{ "Branches" = @("release/*") }
}
$env:Settings = $settings | ConvertTo-Json -Compress
$env:GITHUB_REF_NAME = "feature/my-feature"

# Should throw with a clear error message
{ . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'Publish' } | Should -Throw "*No environments matched deployment criteria*"
}
}
Loading