Skip to content
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

PowerPlatform integration #927

Merged
merged 200 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 196 commits
Commits
Show all changes
200 commits
Select commit Hold shift + click to select a range
28587c8
manual merge
freddydk Feb 6, 2024
61d73da
merge2
freddydk Feb 6, 2024
001e310
add actions
freddydk Feb 6, 2024
77ddef8
artifactname
freddydk Feb 6, 2024
53731eb
add output
freddydk Feb 6, 2024
2ed8d32
add readme
freddydk Feb 6, 2024
d2e2b75
types
freddydk Feb 6, 2024
ce083a4
update
freddydk Feb 7, 2024
fecf9bb
use lcal
freddydk Feb 7, 2024
6963a61
sourcetype
freddydk Feb 7, 2024
8022654
use shell
freddydk Feb 7, 2024
bf6453a
shell
freddydk Feb 7, 2024
47ad0d2
dollar
freddydk Feb 7, 2024
de82825
=
freddydk Feb 7, 2024
582a71a
dump
freddydk Feb 7, 2024
376948f
add shell
freddydk Feb 7, 2024
9035958
special containerhelper
freddydk Feb 7, 2024
f92dc84
replace packageid
freddydk Feb 7, 2024
ee3e932
pwsh
freddydk Feb 7, 2024
4559743
checkout algo
freddydk Feb 7, 2024
9bb1242
try pwsh
freddydk Feb 8, 2024
0773e54
use powershell
freddydk Feb 8, 2024
be8e07f
dump action info
freddydk Feb 8, 2024
7807ef4
use path
freddydk Feb 8, 2024
273ba51
json
freddydk Feb 8, 2024
6a8b114
dumps
freddydk Feb 8, 2024
0b35a46
transfer actions repo
freddydk Feb 8, 2024
feca0e9
:
freddydk Feb 8, 2024
c497bba
actionsrepo
freddydk Feb 8, 2024
7346e59
split repo
freddydk Feb 8, 2024
3bd1e90
x
freddydk Feb 8, 2024
048939d
remove 8
freddydk Feb 8, 2024
bcf778d
use pwsh
freddydk Feb 8, 2024
2e1570b
actions
freddydk Feb 8, 2024
5969637
s
freddydk Feb 8, 2024
10590cb
add prosp
freddydk Feb 8, 2024
2228eff
use Keys collection
freddydk Feb 8, 2024
99b11b9
remove ht
freddydk Feb 8, 2024
0c9d82a
add envname
freddydk Feb 8, 2024
0a917c1
read settings
freddydk Feb 8, 2024
98f3659
get keys
freddydk Feb 8, 2024
8cc88b0
err
freddydk Feb 8, 2024
c0ab28a
move test
freddydk Feb 8, 2024
4db5151
get art
freddydk Feb 9, 2024
28cfd58
remove try
freddydk Feb 9, 2024
b5bab25
unpack
freddydk Feb 9, 2024
3b08903
var name
freddydk Feb 9, 2024
6439c79
spell
freddydk Feb 9, 2024
54bf7f7
outputs
freddydk Feb 9, 2024
c490c96
dumps
freddydk Feb 9, 2024
82d4ebd
shell
freddydk Feb 9, 2024
080a275
id
freddydk Feb 9, 2024
e4989e8
syntax
freddydk Feb 9, 2024
b10d6ec
update readme
freddydk Feb 9, 2024
db20e93
fix push
freddydk Feb 9, 2024
c388864
bug
freddydk Feb 9, 2024
ff1370e
remove dumps
freddydk Feb 9, 2024
1fe1841
pull
freddydk Feb 9, 2024
6d4d544
add environment name
freddydk Feb 9, 2024
99b6911
secrets
freddydk Feb 9, 2024
f5dd7c5
prefix
freddydk Feb 9, 2024
65fae5b
actionsRepo
freddydk Feb 9, 2024
1fca026
actionsRepo
freddydk Feb 9, 2024
5c71aee
PSA
freddydk Feb 9, 2024
bb1ec8c
fix CI tests
freddydk Feb 10, 2024
41f55fc
fix ci tests
freddydk Feb 10, 2024
a80c770
remove preview in docs and fix casing
freddydk Feb 10, 2024
d2fd160
fix casing
freddydk Feb 10, 2024
f7bdb7c
remove test warning
freddydk Feb 10, 2024
a63806a
Update Actions/GetArtifactsForDeployment/README.md
freddydk Feb 17, 2024
80677ac
Merge branch 'main' into PPP
freddydk Feb 19, 2024
d09c620
Merge branch 'main' into PPP
freddydk Feb 20, 2024
77a72e4
Merge branch 'main' into PPP
freddydk Feb 20, 2024
cd2aa39
use preview
freddydk Feb 20, 2024
30d23f5
release notes
freddydk Feb 20, 2024
a69f02b
Increment powerplatform solution version
freddydk Feb 23, 2024
1e8be56
Do not use branch settings for PP Development
freddydk Feb 23, 2024
7330e9d
review
freddydk Mar 4, 2024
c88646e
Increment version number fails if no AL project exists
freddydk Mar 4, 2024
3f63c2e
fix tests
freddydk Mar 5, 2024
54ba405
use pwsh
freddydk Mar 5, 2024
169a6ac
use issue3369
freddydk Mar 6, 2024
b4d1316
Update Actions/AL-Go-Helper.ps1
freddydk Mar 13, 2024
719de5d
review
freddydk Mar 13, 2024
fa834a5
Merge branch 'PPP' of https://github.com/freddydk/AL-Go into PPP
freddydk Mar 13, 2024
9387faf
Update Actions/BuildPowerPlatform/action.yaml
freddydk Mar 13, 2024
f457e06
Update Actions/BuildPowerPlatform/action.yaml
freddydk Mar 13, 2024
716a576
review
freddydk Mar 13, 2024
0e3d72a
Update Templates/Per Tenant Extension/.github/workflows/PushPowerPlat…
freddydk Mar 13, 2024
07a6978
Update Actions/GetArtifactsForDeployment/GetArtifactsForDeployment.ps1
freddydk Mar 13, 2024
d971800
review
freddydk Mar 13, 2024
34574f3
Merge branch 'PPP' of https://github.com/freddydk/AL-Go into PPP
freddydk Mar 13, 2024
7b6bcb4
Update Templates/Per Tenant Extension/.github/workflows/PushPowerPlat…
freddydk Mar 13, 2024
0b3dc43
review
freddydk Mar 13, 2024
730a79a
Merge branch 'PPP' of https://github.com/freddydk/AL-Go into PPP
freddydk Mar 13, 2024
43b02ec
rename
freddydk Mar 13, 2024
ed930ec
rename
freddydk Mar 13, 2024
b75bb4e
rename
freddydk Mar 13, 2024
faa599b
review
freddydk Mar 13, 2024
fe5424a
Merge branch 'main' into PPP
freddydk Mar 13, 2024
1ebccff
review
freddydk Mar 13, 2024
9dd6a58
Merge branch 'PPP' of https://github.com/freddydk/AL-Go into PPP
freddydk Mar 13, 2024
c53bc32
remove actionsrepo parameter
freddydk Mar 13, 2024
9a57b77
colon
freddydk Mar 13, 2024
0398ce3
fix path
freddydk Mar 13, 2024
2071d75
only determine path
freddydk Mar 13, 2024
9d1b5ad
set all
freddydk Mar 13, 2024
6342ef8
line
freddydk Mar 13, 2024
b22f726
Merge branch 'main' into PPP
freddydk Mar 25, 2024
d72d9f4
Update Templates/Per Tenant Extension/.github/workflows/PullPowerPlat…
freddydk Mar 25, 2024
c66a62a
Update Actions/BuildPowerPlatform/UpdateEnvironmentAndCompany.ps1
freddydk Mar 25, 2024
042cf3e
Update Templates/Per Tenant Extension/.github/workflows/PullPowerPlat…
freddydk Mar 25, 2024
6b5c7be
Update Actions/IncrementVersionNumber/IncrementVersionNumber.ps1
freddydk Mar 25, 2024
28218eb
Update Actions/PullPowerPlatformChanges/action.yaml
freddydk Mar 25, 2024
45edf70
review
freddydk Mar 25, 2024
bb5b16f
review comments
freddydk Mar 25, 2024
700d9c9
fix tests
freddydk Mar 25, 2024
933c188
Update Actions/SetActionsRepoAndRef.ps1
freddydk Apr 3, 2024
dc1e316
Update Actions/SetActionsRepoAndRef.ps1
freddydk Apr 3, 2024
14864ac
misspelled
freddydk Apr 3, 2024
0e62409
Merge branch 'main' into PPP
freddydk Apr 3, 2024
2e70cec
Update Templates/Per Tenant Extension/.github/workflows/PullPowerPlat…
freddydk Apr 3, 2024
60b1c33
remove duplicate check
freddydk Apr 3, 2024
914060f
Merge branch 'PPP' of https://github.com/freddydk/AL-Go into PPP
freddydk Apr 3, 2024
5266e08
add def
freddydk Apr 3, 2024
d1c1935
split build (#202)
freddydk Apr 3, 2024
a561e8e
update names
freddydk Apr 3, 2024
b35d946
use not cancelled
freddydk Apr 3, 2024
1399fcc
add PowerPlatform End 2 End test
freddydk Apr 8, 2024
5a375c6
remove copy
freddydk Apr 8, 2024
529cbdb
fix e2e
freddydk Apr 8, 2024
622e857
name
freddydk Apr 8, 2024
895d8d6
fix tests
freddydk Apr 8, 2024
030b0e4
Merge branch 'main' into PPP
freddydk Apr 8, 2024
0ebeee8
Update Actions/IncrementVersionNumber/IncrementVersionNumber.psm1
freddydk Apr 9, 2024
8c58369
Update Actions/IncrementVersionNumber/IncrementVersionNumber.psm1
freddydk Apr 9, 2024
d73f55c
Update Actions/IncrementVersionNumber/IncrementVersionNumber.ps1
freddydk Apr 9, 2024
7b9f32c
Update Templates/AppSource App/.github/workflows/_BuildPowerPlatformS…
freddydk Apr 9, 2024
c3279d0
set reponame
freddydk Apr 9, 2024
e1081eb
Merge branch 'PPP' of https://github.com/freddydk/AL-Go into PPP
freddydk Apr 9, 2024
3179ecb
Only run whoami when debug
freddydk Apr 10, 2024
1d0affb
fix e2e
freddydk Apr 10, 2024
fc1da92
spelling mistake
freddydk Apr 10, 2024
3eeaa49
Merge branch 'main' into PPP
freddydk Apr 10, 2024
f9d530e
move script to script file
freddydk Apr 10, 2024
f8f6838
Merge branch 'PPP' of https://github.com/freddydk/AL-Go into PPP
freddydk Apr 10, 2024
f1ebc3a
PSA
freddydk Apr 10, 2024
609b2e5
Merge branch 'main' into PPP
freddydk Apr 11, 2024
25f30b2
Merge branch 'main' into PPP
freddydk Apr 13, 2024
4911068
move release notes
freddydk Apr 13, 2024
23eecff
release notes
freddydk Apr 13, 2024
c243ee6
release notes 2
freddydk Apr 13, 2024
e456250
Merge branch 'main' into PPP
freddydk Apr 16, 2024
bd988c9
remove who-am-i
freddydk Apr 16, 2024
dc63da3
add PPP to release
freddydk Apr 19, 2024
bfb6378
dollar
freddydk Apr 19, 2024
0b0214e
stupid me
freddydk Apr 19, 2024
26ed8e6
Power Platform - Add unit test (#203)
andersgMSFT Apr 19, 2024
e16d40c
Merge branch 'main' into PPP
freddydk Apr 19, 2024
7c3d75d
set erroraction pref for local runs
freddydk Apr 19, 2024
ed150d0
Ppp (#204)
andersgMSFT Apr 19, 2024
97cb73f
use new-item
freddydk Apr 20, 2024
03ad966
file casing
freddydk Apr 20, 2024
41c6fd5
casing
freddydk Apr 20, 2024
eafcedd
casing
freddydk Apr 20, 2024
6ae66dd
standard
freddydk Apr 20, 2024
2118bfd
casing
freddydk Apr 20, 2024
19508a6
S
freddydk Apr 20, 2024
f4370b3
use joinpath
freddydk Apr 20, 2024
e547608
W
freddydk Apr 20, 2024
1ea9aa9
review
freddydk Apr 25, 2024
ee8a03b
review
freddydk Apr 25, 2024
dcdd1f1
ScriptAnalyzer
freddydk Apr 26, 2024
9afe7bb
Update Actions/BuildPowerPlatform/BuildPowerPlatform.ps1
freddydk May 1, 2024
8e83dd7
Update Actions/PullPowerPlatformChanges/GitCommitChanges.ps1
freddydk May 1, 2024
366d564
Update Actions/BuildPowerPlatform/BuildPowerPlatform.ps1
freddydk May 1, 2024
da3b3b8
Update Actions/PullPowerPlatformChanges/GitCommitChanges.ps1
freddydk May 1, 2024
d5937b6
Update Templates/Per Tenant Extension/.github/workflows/CreateRelease…
freddydk May 1, 2024
8af4f24
review
freddydk May 1, 2024
358d28b
Merge branch 'main' into PPP
freddydk May 2, 2024
64bee61
merge
freddydk May 2, 2024
9373885
Merge branch 'PPP' of https://github.com/freddydk/AL-Go into PPP
freddydk May 2, 2024
a63f55b
merge
freddydk May 2, 2024
100a7c0
Merge branch 'main' into PPP
freddydk May 2, 2024
bdabac6
move release notes
freddydk May 2, 2024
94db63e
review
freddydk May 2, 2024
8ab73b4
fix deliver and deploy
freddydk May 3, 2024
d6fbae7
deliver and deploy optional
freddydk May 3, 2024
01a716f
content
freddydk May 3, 2024
ad9a2bc
replace
freddydk May 3, 2024
ad100ed
remove buildpp
freddydk May 3, 2024
49c2b28
remove BuildPP from AppSource
freddydk May 3, 2024
c89fbab
needs
freddydk May 3, 2024
fe029c8
check buildPP
freddydk May 3, 2024
ad1fc36
include yamlclass
freddydk May 3, 2024
fe20f49
Test failure
freddydk May 4, 2024
91b1497
Update Actions/PullPowerPlatformChanges/action.yaml
freddydk May 13, 2024
1ef31f4
remove powerplatform workflow if no PP
freddydk May 13, 2024
791dcd4
add notes
freddydk May 13, 2024
b440755
always modify workflow
freddydk May 13, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: |
. (Join-Path "." "Tests/runtests.ps1")

- name: Test AL-GO Workflows
- name: Test AL-Go Workflows
if: github.repository_owner == 'microsoft'
run: |
try {
Expand Down
34 changes: 21 additions & 13 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $defaultCICDPullRequestBranches = @( 'main' )
$runningLocal = $local.IsPresent
$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"
$microsoftTelemetryConnectionString = "InstrumentationKey=84bd9223-67d4-4378-8590-9e4a46023be2;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/"
$notSecretProperties = @("Scopes","TenantId","BlobName","ContainerName","StorageAccountName","ServerUrl")
$notSecretProperties = @("Scopes","TenantId","BlobName","ContainerName","StorageAccountName","ServerUrl","ppUserName")
freddydk marked this conversation as resolved.
Show resolved Hide resolved

$runAlPipelineOverrides = @(
"DockerPull"
Expand Down Expand Up @@ -554,6 +554,7 @@ function ReadSettings {
"type" = "PTE"
"unusedALGoSystemFiles" = @()
"projects" = @()
"powerPlatformSolutionFolder" = ""
"country" = "us"
"artifact" = ""
"companyName" = ""
Expand Down Expand Up @@ -2301,12 +2302,30 @@ function RetryCommand {
}
}

function GetMatchingProjects {
Param(
[string[]] $projects,
[string] $selectProjects = ''
)

if ($selectProjects) {
# Filter the project list based on the projects parameter
if ($selectProjects.StartsWith('[')) {
$selectProjects = ($selectProjects | ConvertFrom-Json) -join ","
}
$projectArr = $selectProjects.Split(',').Trim()
$projects = @($projects | Where-Object { $project = $_; if ($projectArr | Where-Object { $project -like $_ }) { $project } })
}
return $projects
}

function GetProjectsFromRepository {
Param(
[string] $baseFolder,
[string[]] $projectsFromSettings,
[string] $selectProjects = ''
)

if ($projectsFromSettings) {
$projects = $projectsFromSettings
}
Expand All @@ -2318,18 +2337,7 @@ function GetProjectsFromRepository {
$projects += @(".")
}
}
if ($selectProjects) {
# Filter the project list based on the projects parameter
if ($selectProjects.StartsWith('[')) {
$selectProjects = ($selectProjects | ConvertFrom-Json) -join ","
}
$projectArr = $selectProjects.Split(',').Trim()
$projects = @($projects | Where-Object { $project = $_; if ($projectArr | Where-Object { $project -like $_ }) { $project } })
if ($projects.Count -eq 0) {
throw "No projects matches '$selectProjects'"
}
}
return $projects
return @(GetMatchingProjects -projects $projects -selectProjects $selectProjects)
}

function Get-PackageVersion($PackageName) {
Expand Down
7 changes: 7 additions & 0 deletions Actions/AL-Go-TestRepoHelper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,20 @@ function Test-SettingsJson {
Test-Shell -json $json -settingsDescription $settingsDescription -property 'shell'
Test-Shell -json $json -settingsDescription $settingsDescription -property 'gitHubRunnerShell'

if ($json.Keys -contains 'bcContainerHelperVersion') {
if ($json.bcContainerHelperVersion -ne 'latest' -and $json.bcContainerHelperVersion -ne 'preview') {
OutputWarning -Message "Using a specific version of BcContainerHelper in $settingsDescription is not recommended and will lead to build failures in the future. Consider removing the setting."
}
}

if ($type -eq 'Repo') {
# Test for things that should / should not exist in a repo settings file
Test-Property -settingsDescription $settingsDescription -json $json -key 'templateUrl' -should
}
if ($type -eq 'Project') {
# GitHubRunner should not be in a project settings file (only read from repo or workflow settings)
Test-Property -settingsDescription $settingsDescription -json $json -key 'githubRunner' -shouldnot
Test-Property -settingsDescription $settingsDescription -json $json -key 'bcContainerHelperVersion' -shouldnot
}
if ($type -eq 'Workflow') {
# Test for things that should / should not exist in a workflow settings file
Expand Down
274 changes: 274 additions & 0 deletions Actions/BuildPowerPlatform/BuildPowerPlatform.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
[CmdletBinding()]
param(
[Parameter(mandatory = $true)]
[string] $solutionFolder,
[Parameter(mandatory = $false)]
[string] $companyId,
[Parameter(mandatory = $false)]
[string] $environmentName,
[Parameter(mandatory = $false)]
[string] $appBuild,
[Parameter(mandatory = $false)]
[string] $appRevision
)
$ErrorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0

function Update-PowerAppSettings {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string] $SolutionFolder,
[Parameter(Mandatory = $true)]
[string] $environmentName,
[Parameter(Mandatory = $true)]
[string] $companyId
)

# There are multiple files that contain the BC connection info for PowerApps with different structures
# So instead of parsing all of them, we simple find the current connection strings and run a replace operation.
# Note: The connection string has a format of: "EnvironmentName,CompanyId" where companyId is a guid. So the
# replace operation should be safe to run a all json and XML files.
Write-Host "Updating PowerApp settings"
$currentPowerAppSettings = Get-CurrentPowerAppSettings -solutionFolder $SolutionFolder
if ($null -eq $currentPowerAppSettings) {
Write-Host "::Notice::No Power Apps found"
return
}

Write-Host "Number of Business Central Power App connections found: "$currentPowerAppSettings.Count
$newSettings = "$environmentName,$companyId"
foreach ($currentSetting in $currentPowerAppSettings) {
if ($currentSetting -eq $newSettings) {
Write-Host "No changes needed for: "$currentSetting
continue
}
Update-PowerAppFiles -oldSetting $currentSetting -newSetting $newSettings -solutionFolder $SolutionFolder
}
}

function Update-PowerAppFiles {
param(
[Parameter(mandatory = $true)]
[string] $solutionFolder,
[Parameter(mandatory = $true)]
[string] $oldSetting,
[Parameter(mandatory = $true)]
[string] $newSetting
)

$powerAppFiles = Get-ChildItem -Recurse -File "$solutionFolder/CanvasApps"
foreach ($file in $powerAppFiles) {
# only check json and xml files
if (($file.Extension -eq ".json") -or ($file.Extension -eq ".xml")) {
$fileContent = Get-Content $file.FullName
if (Select-String -Pattern $oldSetting -InputObject $fileContent) {
$fileContent = $fileContent -creplace $oldSetting, $newSetting
Set-Content -Path $file.FullName -Value $fileContent
Write-Host "Updated: $($file.FullName)"
}
}
}
}

function Get-CurrentPowerAppSettings {
param (
[Parameter(mandatory = $true)]
[string] $solutionFolder
)

if (-not (Test-Path -Path "$solutionFolder/CanvasApps")) {
# No Canvas apps present in the solution
return @()
}

$currentSettingsList = @()
$connectionsFilePaths = Get-ChildItem -Path "$solutionFolder/CanvasApps" -Recurse -File -Include "Connections.json" | Select-Object -ExpandProperty FullName
foreach ($connectionsFilePath in $connectionsFilePaths) {
$jsonFile = Get-Content $connectionsFilePath | ConvertFrom-Json

# We don't know the name of the connector node, so we need to loop through all of them
$ConnectorNodeNames = ($jsonFile | Get-Member -MemberType NoteProperty).Name

foreach ($connectorNodeName in $ConnectorNodeNames) {
$connectorNode = $jsonFile.$connectorNodeName
# Find the Business Central connection node
if ($connectorNode.connectionRef.displayName -eq "Dynamics 365 Business Central") {
$currentEnvironmentAndCompany = ($connectorNode.datasets | Get-Member -MemberType NoteProperty).Name

if ($null -eq $currentEnvironmentAndCompany) {
# Connections sections for Power Automate flow does not have a dataset node
# Note: Flows are handled in a different function
continue
}

if (!$currentSettingsList.Contains($currentEnvironmentAndCompany)) {
$currentSettingsList += $currentEnvironmentAndCompany

# The Business Central environment can be inconsistent - Either starting with a capital letter or all caps.
# Add both variants to ensure we find all connections
$currentSettingsParts = @($currentEnvironmentAndCompany.Split(","))
$currentSettingsList += "$($currentSettingsParts[0].ToUpperInvariant()),$($currentSettingsParts[1])"
}
}
}
}
return $currentSettingsList
}

function Update-FlowSettings {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string] $SolutionFolder,
[Parameter(Mandatory = $true)]
[string] $environmentName,
[Parameter(Mandatory = $true)]
[string] $companyId
)

Write-Host "Updating Flow settings"
$flowFilePaths = Get-ChildItem -Path (Join-Path $SolutionFolder 'Workflows') -Recurse -Filter '*.json' | Select-Object -ExpandProperty FullName

if ($null -eq $flowFilePaths) {
Write-Host "::Notice::No Power Automate flows found"
return
}

foreach ($flowFilePath in $flowFilePaths) {
Update-FlowFile -FilePath $flowFilePath -CompanyId $companyId -EnvironmentName $environmentName
}
}

function Update-FlowFile {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string] $filePath,
[Parameter(Mandatory = $true)]
[string] $companyId,
[Parameter(Mandatory = $true)]
[string] $environmentName
)
# Read the JSON file
$jsonObject = Get-Content $filePath | ConvertFrom-Json
$shouldUpdate = $false

# Update all flow triggers
$triggersObject = $jsonObject.properties.definition.triggers
$triggers = $triggersObject | Get-Member -MemberType Properties
foreach ($trigger in $triggers) {
$triggerInputs = $triggersObject.($trigger.Name).inputs

if ($triggerInputs | Get-Member -MemberType Properties -name 'parameters') {
# Business Central triggers have connection information in the input parameters
if (Update-ParameterObject -parametersObject $triggerInputs.parameters -CompanyId $companyId -EnvironmentName $environmentName) {
$shouldUpdate = $true
}
}
}

# Update all flow actions
$actionsObject = $jsonObject.properties.definition.actions
$actions = $actionsObject | Get-Member -MemberType Properties
foreach ($action in $actions) {
$actionInput = $actionsObject.($action.Name).inputs
if ($actionInput | Get-Member -MemberType Properties -name 'parameters') {
# Business Central actions have connection information in the input parameters
if (Update-ParameterObject -parametersObject $actionInput.parameters -CompanyId $companyId -EnvironmentName $environmentName) {
$shouldUpdate = $true
}
}
}
if ($shouldUpdate) {
# Save the updated JSON back to the file
$jsonObject | ConvertTo-Json -Depth 100 | Set-Content $filePath
Write-Host "Updated: $filePath"
}
else {
Write-Host "No update needed for: $filePath"
}
}

function Update-ParameterObject {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[System.Object] $parametersObject,
[Parameter(Mandatory = $true)]
[string] $companyId,
[Parameter(Mandatory = $true)]
[string] $environmentName
)
# Check if paramers are for Business Central
if ((-not $parametersObject.company) -or (-not $parametersObject.bcEnvironment)) {
return $false
}

$oldCompany = $parametersObject.company
$oldBcEnvironment = $parametersObject.bcenvironment

# Check if parameters are already set to the correct values
if (($oldCompany -eq $companyId) -and ($oldBcEnvironment -eq $environmentName)) {
return $false
}

$enviromentVariablePlaceHolder = "@parameters("

# Check if parameters are set using a different approach (e.g. environment variables or passed in parameters)
if ($oldCompany.contains($enviromentVariablePlaceHolder) -or $oldBcEnvironment.contains($enviromentVariablePlaceHolder)) {
return $false
}

$parametersObject.company = $companyId
$parametersObject.bcEnvironment = $environmentName

return $true
}

function Update-SolutionVersionNode {
param(
[Parameter(mandatory = $true)]
[string] $appBuild,
[Parameter(mandatory = $true)]
[string] $appRevision,
[Parameter(mandatory = $true)]
[xml] $xmlFile
)

if ($appBuild -and $appRevision) {
$versionNode = $xmlFile.SelectSingleNode("//Version")
$versionNodeText = $versionNode.'#text'

$versionParts = $versionNodeText.Split('.')
# Only update the last two parts of the version number - major and minor version should be set manually
$newVersionNumber = $versionParts[0] + '.' + $versionParts[1] + '.' + $appBuild + '.' + $appRevision

Write-Host "New version: "$newVersionNumber
$versionNode.'#text' = $newVersionNumber
}

}

if ($appBuild -and $appRevision) {
Write-Host "Updating Power Platform solution file ($solutionFolder)"
$solutionDefinitionFile = Join-Path $solutionFolder 'other/Solution.xml'
if (-not (Test-Path -Path $solutionDefinitionFile)) {
throw "Solution file not found: $solutionDefinitionFile"
}
$xmlFile = [xml](Get-Content -Encoding UTF8 -Path $solutionDefinitionFile)
Update-SolutionVersionNode -appBuild $appBuild -appRevision $appRevision -xmlFile $xmlFile
$xmlFile.Save($solutionDefinitionFile)
}
else {
Write-Host "Skip solution version update since appBuild and appRevision are not set"
}

if ($environmentName -and $companyId) {
Write-Host "Updating the Power Platform solution Business Central connection settings"
Write-Host "New connections settings: $environmentName, $companyId"
Update-PowerAppSettings -SolutionFolder $SolutionFolder -EnvironmentName $environmentName -CompanyId $companyId
Update-FlowSettings -SolutionFolder $SolutionFolder -EnvironmentName $environmentName -CompanyId $companyId
}
else {
Write-Host "Skip Business Central connection settings update since EnvironmentName and CompanyId are not set"
}
22 changes: 22 additions & 0 deletions Actions/BuildPowerPlatform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build Power Platform
Build the Power Platform solution

## INPUT

### ENV variables
none

### Parameters
| Name | Required | Description | Default value |
| :-- | :-: | :-- | :-- |
| shell | | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell |
| solutionFolder | Yes | The Power Platform solution path | |
| outputFolder | Yes | Output folder where the zip file will be placed | |
| outputFileName | Yes | The name of the output zip file | |
| companyId | | The Business Central company ID | |
| environmentName | | The Business Central environment name | |
| appBuild | | The app build number | |
| appRevision | | The app revision number | |

## OUTPUT
none
Loading
Loading