Skip to content

Commit 14cb3ea

Browse files
authored
Merge branch 'main' into aholstrup/inlinepowershell
2 parents c1ca386 + 12381e4 commit 14cb3ea

8 files changed

Lines changed: 73 additions & 13 deletions

File tree

Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ else {
285285
$json = @{"matrix" = @{ "include" = @() }; "fail-fast" = $false }
286286
$deploymentEnvironments.Keys | Sort-Object | ForEach-Object {
287287
$deploymentEnvironment = $deploymentEnvironments."$_"
288-
$json.matrix.include += @{ "environment" = $_; "os" = "$(ConvertTo-Json -InputObject @($deploymentEnvironment."runs-on".Split(',').Trim()) -compress)"; "shell" = $deploymentEnvironment."shell" }
288+
$buildMode = "Default"
289+
if ($deploymentEnvironment.ContainsKey("buildMode") -and $deploymentEnvironment."buildMode") {
290+
$buildMode = $deploymentEnvironment."buildMode"
291+
}
292+
$json.matrix.include += @{ "environment" = $_; "os" = "$(ConvertTo-Json -InputObject @($deploymentEnvironment."runs-on".Split(',').Trim()) -compress)"; "shell" = $deploymentEnvironment."shell"; "buildMode" = $buildMode }
289293
}
290294
$environmentsMatrixJson = $json | ConvertTo-Json -Depth 99 -compress
291295
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "EnvironmentsMatrixJson=$environmentsMatrixJson"

Actions/GetArtifactsForDeployment/GetArtifactsForDeployment.ps1

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,32 @@ Param(
44
[Parameter(HelpMessage = "Artifacts version to download (current, prerelease, draft, latest or version number)", Mandatory = $true)]
55
[string] $artifactsVersion,
66
[Parameter(HelpMessage = "Folder in which the artifacts will be downloaded", Mandatory = $true)]
7-
[string] $artifactsFolder
7+
[string] $artifactsFolder,
8+
[Parameter(HelpMessage = "Build mode used when building the artifacts", Mandatory = $false)]
9+
[string] $buildMode = 'Default'
810
)
911

1012
Import-Module (Join-Path -Path $PSScriptRoot "GetArtifactsForDeployment.psm1")
1113
. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)
1214
DownloadAndImportBcContainerHelper
1315

16+
# If buildMode is 'Default', set it to empty string (no prefix in artifact names)
17+
$buildModePrefix = $buildMode
18+
if ($buildMode -eq 'Default') {
19+
$buildModePrefix = ''
20+
}
21+
1422
# Get artifacts for all projects
1523
$projects = "*"
16-
$artifactsToDownload = @("Apps","TestApps","Dependencies","PowerPlatformSolution")
1724

18-
Write-Host "Get artifacts for version: '$artifactsVersion' for these projects: '$projects' to folder: '$artifactsFolder'"
25+
# Default artifact types (used for releases which only support default buildMode)
26+
$defaultArtifactTypes = @("Apps","TestApps","Dependencies","PowerPlatformSolution")
27+
28+
# Artifact types with buildMode prefix (used for workflow artifacts)
29+
# PowerPlatformSolution is always built with 'default' buildMode, so it never has a prefix
30+
$buildModeArtifactTypes = @("$($buildModePrefix)Apps","$($buildModePrefix)TestApps","$($buildModePrefix)Dependencies","PowerPlatformSolution")
31+
32+
Write-Host "Get artifacts for version: '$artifactsVersion' (build mode: $buildMode) for these projects: '$projects' to folder: '$artifactsFolder'"
1933

2034
$artifactsFolder = Join-Path $ENV:GITHUB_WORKSPACE $artifactsFolder
2135
if (!(Test-Path $artifactsFolder)) {
@@ -38,7 +52,8 @@ if ($artifactsVersion -eq "current" -or $artifactsVersion -eq "prerelease" -or $
3852
if (!($release)) {
3953
throw "Unable to locate $artifactsVersion release"
4054
}
41-
$artifactsToDownload | ForEach-Object {
55+
# Releases only contain default buildMode artifacts
56+
$defaultArtifactTypes | ForEach-Object {
4257
DownloadRelease -token $token -projects $projects -api_url $ENV:GITHUB_API_URL -repository $ENV:GITHUB_REPOSITORY -release $release -path $artifactsFolder -mask $_ -unpack
4358
}
4459
}
@@ -72,13 +87,13 @@ elseif ($artifactsVersion -like "PR_*") {
7287
$expiredArtifacts = @()
7388
$lastKnownGoodBuildArtifacts = @()
7489
# Get PR artifacts
75-
$artifactsToDownload | ForEach-Object {
90+
$buildModeArtifactTypes | ForEach-Object {
7691
$prArtifacts += GetArtifactsFromWorkflowRun -workflowRun $latestPRBuildId -token $token -api_url $ENV:GITHUB_API_URL -repository $ENV:GITHUB_REPOSITORY -mask $_ -projects $projects -expiredArtifacts ([ref]$expiredArtifacts)
7792
}
7893
# Get last known good build artifacts referenced from PR
7994
if ($lastKnownGoodBuildId -ne 0) {
8095
Write-Host "Last known good build id: $lastKnownGoodBuildId"
81-
$artifactsToDownload | ForEach-Object {
96+
$buildModeArtifactTypes | ForEach-Object {
8297
$lastKnownGoodBuildArtifacts += GetArtifactsFromWorkflowRun -workflowRun $lastKnownGoodBuildId -token $token -api_url $ENV:GITHUB_API_URL -repository $ENV:GITHUB_REPOSITORY -mask $_ -projects $projects -expiredArtifacts ([ref]$expiredArtifacts)
8398
}
8499
}
@@ -106,7 +121,7 @@ else {
106121

107122
if ($searchArtifacts) {
108123
$allArtifacts = @()
109-
$artifactsToDownload | ForEach-Object {
124+
$buildModeArtifactTypes | ForEach-Object {
110125
$allArtifacts += @(GetArtifacts -token $token -api_url $ENV:GITHUB_API_URL -repository $ENV:GITHUB_REPOSITORY -mask $_ -projects $projects -version $artifactsVersion -branch $ENV:GITHUB_REF_NAME)
111126
}
112127
if ($allArtifacts) {

Actions/GetArtifactsForDeployment/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ none
1616
| token | | The GitHub token running the action | github.token |
1717
| artifactsVersion | Yes | Artifacts version to download (current, prerelease, draft, latest or version number) | |
1818
| artifactsFolder | Yes | Folder in which the artifacts will be downloaded | |
19+
| buildMode | | Build mode used when building the artifacts | Default |
1920

2021
## OUTPUT
2122

Actions/GetArtifactsForDeployment/action.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inputs:
1515
artifactsFolder:
1616
description: Folder in which the artifacts will be downloaded
1717
required: true
18+
buildMode:
19+
description: Build mode used when building the artifacts
20+
required: false
21+
default: 'Default'
1822
runs:
1923
using: composite
2024
steps:
@@ -24,9 +28,10 @@ runs:
2428
_token: ${{ inputs.token }}
2529
_artifactsVersion: ${{ inputs.artifactsVersion }}
2630
_artifactsFolder: ${{ inputs.artifactsFolder }}
31+
_buildMode: ${{ inputs.buildMode }}
2732
run: |
2833
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "GetArtifactsForDeployment" -Action {
29-
${{ github.action_path }}/GetArtifactsForDeployment.ps1 -token $ENV:_token -artifactsVersion $ENV:_artifactsVersion -artifactsFolder $ENV:_artifactsFolder
34+
${{ github.action_path }}/GetArtifactsForDeployment.ps1 -token $ENV:_token -artifactsVersion $ENV:_artifactsVersion -artifactsFolder $ENV:_artifactsFolder -buildMode $ENV:_buildMode
3035
}
3136
branding:
3237
icon: terminal

RELEASENOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Issues
22

33
- Issue 2113 Using the action "Create Online Dev. Environment" fails in Initialization phase
4+
- Issue 2107 Publish a specific build mode to an environment
45
- Issue 1915 CICD fails on releases/26.x branch - '26.x' cannot be recognized as a semantic version string
56

67
### The default pull request trigger is changing

Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ jobs:
147147
shell: ${{ matrix.shell }}
148148
artifactsVersion: ${{ github.event.inputs.appVersion }}
149149
artifactsFolder: '.artifacts'
150+
buildMode: ${{ matrix.buildMode }}
150151

151152
- name: Deploy to Business Central
152153
id: Deploy

Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ jobs:
147147
shell: ${{ matrix.shell }}
148148
artifactsVersion: ${{ github.event.inputs.appVersion }}
149149
artifactsFolder: '.artifacts'
150+
buildMode: ${{ matrix.buildMode }}
150151

151152
- name: Deploy to Business Central
152153
id: Deploy

Tests/DetermineDeploymentEnvironments.Test.ps1

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ Describe "DetermineDeploymentEnvironments Action Test" {
5858
$env:Settings = @{ "type" = "PTE"; "runs-on" = "ubuntu-latest"; "shell" = "pwsh"; "environments" = @(); "excludeEnvironments" = @( 'github-pages' ); "alDoc" = @{ "continuousDeployment" = $false; "deployToGitHubPages" = $false } } | ConvertTo-Json -Compress
5959
. (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD'
6060
PassGeneratedOutput
61-
$EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="another";"os"="[""ubuntu-latest""]";"shell"="pwsh"};@{"environment"="test";"os"="[""ubuntu-latest""]";"shell"="pwsh"})};"fail-fast"=$false}
61+
$EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="another";"os"="[""ubuntu-latest""]";"shell"="pwsh";"buildMode"="Default"};@{"environment"="test";"os"="[""ubuntu-latest""]";"shell"="pwsh";"buildMode"="Default"})};"fail-fast"=$false}
6262
$DeploymentEnvironmentsJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"test"=@{"EnvironmentType"="SaaS";"EnvironmentName"="test";"Branches"=@();"BranchesFromPolicy"=@();"Projects"="*";"DependencyInstallMode"="install";"Scope"=$null;"syncMode"=$null;"buildMode"=$null;"continuousDeployment"=$null;"runs-on"=@("ubuntu-latest");"shell"="pwsh";"ppEnvironmentUrl"="";"companyId"="";"includeTestAppsInSandboxEnvironment"=$false;"excludeAppIds"=@()};"another"=@{"EnvironmentType"="SaaS";"EnvironmentName"="another";"Branches"=@();"BranchesFromPolicy"=@();"Projects"="*";"DependencyInstallMode"="install";"Scope"=$null;"syncMode"=$null;"buildMode"=$null;"continuousDeployment"=$null;"runs-on"=@("ubuntu-latest");"shell"="pwsh";"ppEnvironmentUrl"="";"companyId"="";"includeTestAppsInSandboxEnvironment"=$false;"excludeAppIds"=@()}}
6363
$EnvironmentCount | Should -Be 2
6464

6565
. (Join-Path $scriptRoot $scriptName) -getEnvironments 'test' -type 'CD'
6666
PassGeneratedOutput
67-
$EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="test";"os"="[""ubuntu-latest""]";"shell"="pwsh"})};"fail-fast"=$false}
67+
$EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="test";"os"="[""ubuntu-latest""]";"shell"="pwsh";"buildMode"="Default"})};"fail-fast"=$false}
6868
$DeploymentEnvironmentsJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"test"=@{"EnvironmentType"="SaaS";"EnvironmentName"="test";"Branches"=@();"BranchesFromPolicy"=@();"Projects"="*";"DependencyInstallMode"="install";"Scope"=$null;"syncMode"=$null;"buildMode"=$null;"continuousDeployment"=$null;"runs-on"=@("ubuntu-latest");"shell"="pwsh";"ppEnvironmentUrl"="";"companyId"="";"includeTestAppsInSandboxEnvironment"=$false;"excludeAppIds"=@()}}
6969
$EnvironmentCount | Should -Be 1
7070
}
@@ -81,7 +81,7 @@ Describe "DetermineDeploymentEnvironments Action Test" {
8181
$env:Settings = @{ "type" = "PTE"; "runs-on" = "ubuntu-latest"; "shell" = "pwsh"; "environments" = @(); "excludeEnvironments" = @( 'github-pages' ); "alDoc" = @{ "continuousDeployment" = $false; "deployToGitHubPages" = $false } } | ConvertTo-Json -Compress
8282
. (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD'
8383
PassGeneratedOutput
84-
$EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="another";"os"="[""ubuntu-latest""]";"shell"="pwsh"})};"fail-fast"=$false}
84+
$EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="another";"os"="[""ubuntu-latest""]";"shell"="pwsh";"buildMode"="Default"})};"fail-fast"=$false}
8585
$DeploymentEnvironmentsJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"another"=@{"EnvironmentType"="SaaS";"EnvironmentName"="another";"Branches"=@();"BranchesFromPolicy"=@();"Projects"="*";"DependencyInstallMode"="install";"Scope"=$null;"syncMode"=$null;"buildMode"=$null;"continuousDeployment"=$null;"runs-on"=@("ubuntu-latest");"shell"="pwsh";"ppEnvironmentUrl"="";"companyId"="";"includeTestAppsInSandboxEnvironment"=$false;"excludeAppIds"=@()}}
8686
$EnvironmentCount | Should -Be 1
8787

@@ -107,7 +107,7 @@ Describe "DetermineDeploymentEnvironments Action Test" {
107107
# Only another environment should be included when deploying from main
108108
. (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD'
109109
PassGeneratedOutput
110-
$EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="another";"os"="[""ubuntu-latest""]";"shell"="pwsh"})};"fail-fast"=$false}
110+
$EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="another";"os"="[""ubuntu-latest""]";"shell"="pwsh";"buildMode"="Default"})};"fail-fast"=$false}
111111
$DeploymentEnvironmentsJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"another"=@{"EnvironmentType"="SaaS";"EnvironmentName"="another";"Branches"=@();"BranchesFromPolicy"=@();"Projects"="*";"DependencyInstallMode"="install";"Scope"=$null;"syncMode"=$null;"buildMode"=$null;"continuousDeployment"=$null;"runs-on"=@("ubuntu-latest");"shell"="pwsh";"ppEnvironmentUrl"="";"companyId"="";"includeTestAppsInSandboxEnvironment"=$false;"excludeAppIds"=@()}}
112112
$EnvironmentCount | Should -Be 1
113113
($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "another"
@@ -239,6 +239,38 @@ Describe "DetermineDeploymentEnvironments Action Test" {
239239
($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "test (PROD)"
240240
}
241241

242+
# Test that buildMode from DeployTo settings is correctly included in the matrix
243+
It 'Test calling action directly - Custom buildMode from DeployTo settings is included in matrix' {
244+
Mock InvokeWebRequest -ParameterFilter { $uri -like '*/environments' } -MockWith {
245+
return @{"Content" = (ConvertTo-Json -Compress -Depth 99 -InputObject @{ "environments" = @( @{ "name" = "test"; "protection_rules" = @() } ) })}
246+
}
247+
248+
$settings = @{
249+
"type" = "PTE"
250+
"runs-on" = "ubuntu-latest"
251+
"shell" = "pwsh"
252+
"environments" = @()
253+
"excludeEnvironments" = @( 'github-pages' )
254+
"alDoc" = @{ "continuousDeployment" = $false; "deployToGitHubPages" = $false }
255+
"DeployToTest" = @{
256+
"buildMode" = "CustomBuildMode"
257+
}
258+
}
259+
260+
$env:Settings = $settings | ConvertTo-Json -Compress -Depth 5
261+
. (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD'
262+
PassGeneratedOutput
263+
264+
# Verify buildMode is correctly set to CustomBuildMode in the matrix
265+
$matrix = $EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse
266+
$matrix.matrix.include[0].buildMode | Should -Be "CustomBuildMode"
267+
$EnvironmentCount | Should -Be 1
268+
269+
# Verify buildMode is correctly set in DeploymentEnvironmentsJson
270+
$deployEnvs = $DeploymentEnvironmentsJson | ConvertFrom-Json | ConvertTo-HashTable -recurse
271+
$deployEnvs.test.buildMode | Should -Be "CustomBuildMode"
272+
}
273+
242274
# Unknown environment - createEnvIfNotExists = false (default) - should throw error
243275
It 'Test calling action directly - Unknown environment without createEnvIfNotExists should throw' {
244276
Mock InvokeWebRequest -ParameterFilter { $uri -like '*/environments' } -MockWith {

0 commit comments

Comments
 (0)