Skip to content

Commit 96baa72

Browse files
authored
Merge branch 'main' into ExtendedDebugLogging
2 parents 13eebc5 + b763a6b commit 96baa72

File tree

4 files changed

+132
-22
lines changed

4 files changed

+132
-22
lines changed

Actions/IncrementVersionNumber/IncrementVersionNumber.ps1

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ if ($projectList.Count -eq 0 -and $PPprojects.Count -eq 0) {
5757
$repositorySettingsPath = Join-Path $baseFolder $RepoSettingsFile # $RepoSettingsFile is defined in AL-Go-Helper.ps1
5858

5959
# Increment version number in AL Projects
60+
$allAppFolders = @()
6061
if ($projectList.Count -gt 0) {
61-
$allAppFolders = @()
6262
$repoVersionExistsInRepoSettings = Test-SettingExists -settingsFilePath $repositorySettingsPath -settingName 'repoVersion'
6363
$repoVersionInRepoSettingsWasUpdated = $false
6464
foreach ($project in $projectList) {
@@ -89,25 +89,13 @@ if ($projectList.Count -gt 0) {
8989
$projectSettings = ReadSettings -baseFolder $baseFolder -project $project
9090
ResolveProjectFolders -baseFolder $baseFolder -project $project -projectSettings ([ref] $projectSettings)
9191

92-
# Set version in app manifests (app.json files)
93-
Set-VersionInAppManifests -projectPath $projectPath -projectSettings $projectSettings -newValue $versionNumber
94-
95-
# Collect all project's app folders
96-
$allAppFolders += $projectSettings.appFolders | ForEach-Object { Join-Path $projectPath $_ -Resolve }
97-
$allAppFolders += $projectSettings.testFolders | ForEach-Object { Join-Path $projectPath $_ -Resolve }
98-
$allAppFolders += $projectSettings.bcptTestFolders | ForEach-Object { Join-Path $projectPath $_ -Resolve }
92+
Set-VersionInAppManifests -projectPath $projectPath -projectSettings $projectSettings -newValue $versionNumber -updatedAppFolders ([ref] $allAppFolders)
9993
}
94+
}
10095

101-
if (-not $skipUpdatingDependencies) {
102-
# Set dependencies in app manifests
103-
if ($allAppFolders.Count -eq 0) {
104-
Write-Host "No App folders found for projects $projects"
105-
}
106-
else {
107-
# Set dependencies in app manifests
108-
Set-DependenciesVersionInAppManifests -appFolders $allAppFolders
109-
}
110-
}
96+
if (-not $skipUpdatingDependencies) {
97+
# Set dependencies in app manifests
98+
Set-DependenciesVersionInAppManifests -appFolders $allAppFolders
11199
}
112100

113101
# Increment version number in PowerPlatform Solution

Actions/IncrementVersionNumber/IncrementVersionNumber.psm1

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,33 @@ function Test-SettingExists {
189189
Name of the project (relative to the base folder).
190190
.Parameter newValue
191191
New version number. If the version number starts with a +, the new version number will be added to the old version number. Else the new version number will replace the old version number.
192+
.Parameter updatedAppFolders
193+
[ref] Array of paths to the app folders that were updated. This is used to avoid updating the same app folder multiple times.
192194
#>
193-
function Set-VersionInAppManifests($projectPath, $projectSettings, $newValue) {
195+
function Set-VersionInAppManifests($projectPath, $projectSettings, $newValue, [ref] $updatedAppFolders) {
194196

195197
# Check if the project uses repoVersion versioning strategy
196198
$useRepoVersion = (($projectSettings.PSObject.Properties.Name -eq "versioningStrategy") -and (($projectSettings.versioningStrategy -band 16) -eq 16))
197199
if ($useRepoVersion) {
198200
$newValue = $projectSettings.repoVersion
199201
}
200202

203+
if (-not $updatedAppFolders.Value) {
204+
$updatedAppFolders.Value = @()
205+
}
206+
201207
$allAppFolders = @($projectSettings.appFolders) + @($projectSettings.testFolders) + @($projectSettings.bcptTestFolders)
202208
# Set version in app.json files
203209
$allAppFolders | ForEach-Object {
204-
$appFolder = Join-Path $projectPath $_
205-
$appJson = Join-Path $appFolder "app.json"
210+
$appFolder = Join-Path $projectPath $_ -Resolve
206211

207-
Set-VersionInSettingsFile -settingsFilePath $appJson -settingName 'version' -newValue $newValue
212+
# Update the app only if it's not already updated
213+
if (-not ($updatedAppFolders.Value -contains $appFolder)) {
214+
$appJson = Join-Path $appFolder "app.json"
215+
Set-VersionInSettingsFile -settingsFilePath $appJson -settingName 'version' -newValue $newValue
216+
217+
$updatedAppFolders.Value += @($appFolder)
218+
}
208219
}
209220
}
210221

RELEASENOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ AL-Go now offers a dataexplorer dashboard to get started with AL-Go telemetry. A
77
- Issue 1770 Wrong type of _projects_ setting in settings schema
88
- Issue 1787 Publish to Environment from PR fails in private repos
99
- Issue 1722 Check if apps are already installed on a higher version before deploying
10+
- Issue 1774 Increment Version Number with +0.1 can increment some version numbers twice
1011

1112
### Add custom jobs to AL-Go workflows
1213

Tests/IncrementVersionNumber.Action.Test.ps1

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,113 @@ Describe "Set-VersionInSettingsFile tests" {
374374
Remove-Item $settingsFile -Force -ErrorAction Ignore
375375
}
376376
}
377+
378+
Describe 'Set-VersionInAppManifests tests' {
379+
BeforeAll {
380+
. (Join-Path -Path $PSScriptRoot -ChildPath "..\Actions\AL-Go-Helper.ps1" -Resolve)
381+
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "..\Actions\IncrementVersionNumber\IncrementVersionNumber.psm1" -Resolve) -Force
382+
}
383+
384+
BeforeEach {
385+
$testProjectPath = Join-Path ([System.IO.Path]::GetTempPath()) "TestProject"
386+
New-Item -ItemType Directory -Path $testProjectPath -Force | Out-Null
387+
388+
# Create mock app folders for TestProject
389+
$appFolders = @('App1', 'App2', 'Test1', 'BCPTTest1')
390+
foreach ($folder in $appFolders) {
391+
New-Item -ItemType Directory -Path (Join-Path $testProjectPath $folder) -Force | Out-Null
392+
New-Item -ItemType File -Path (Join-Path $testProjectPath $folder 'app.json') -Force | Out-Null
393+
$appJsonContent = @{
394+
"version" = "0.1"
395+
"name" = $folder
396+
}
397+
$appJsonContent | ConvertTo-Json | Set-Content (Join-Path $testProjectPath $folder 'app.json') -Encoding UTF8
398+
}
399+
400+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'testProjectSettings', Justification = 'False positive.')]
401+
$testProjectSettings = @{
402+
appFolders = @($appFolders[0..1]) # App1, App2
403+
testFolders = @($appFolders[2]) # Test1
404+
bcptTestFolders = @($appFolders[3]) # BCPTTest1
405+
}
406+
407+
# Create another project folder that points to the same app folders
408+
$anotherTestProjectPath = Join-Path ([System.IO.Path]::GetTempPath()) "AnotherTestProject"
409+
New-Item -ItemType Directory -Path $anotherTestProjectPath -Force | Out-Null
410+
411+
Push-Location $anotherTestProjectPath
412+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'anotherTestProjectSettings', Justification = 'False positive.')]
413+
$anotherTestProjectSettings = @{
414+
appFolders = @($appFolders[0..1]) | ForEach-Object { Resolve-Path (Join-Path $testProjectPath $_) -Relative } # App1, App2
415+
testFolders = @($appFolders[2]) | ForEach-Object { Resolve-Path (Join-Path $testProjectPath $_) -Relative } # Test1
416+
bcptTestFolders = @($appFolders[3]) | ForEach-Object { Resolve-Path (Join-Path $testProjectPath $_) -Relative } # BCPTTest1
417+
}
418+
419+
$anotherTestProjectAppFolder = 'Another TestProjectApp'
420+
New-Item -ItemType Directory -Path (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder) -Force | Out-Null
421+
New-Item -ItemType File -Path (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder 'app.json') -Force | Out-Null
422+
$anotherTestProjectAppJsonContent = @{
423+
"version" = "0.2"
424+
"name" = $anotherTestProjectAppFolder
425+
}
426+
$anotherTestProjectAppJsonContent | ConvertTo-Json | Set-Content (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder 'app.json') -Encoding UTF8
427+
428+
Pop-Location
429+
}
430+
431+
It 'Set-VersionInAppManifests updates all app.json files once and increments the version' {
432+
$updatedAppFolders = @()
433+
$testProjectSettings = @{
434+
versioningStrategy = 0
435+
appFolders = @('App1', 'App2')
436+
testFolders = @('Test1')
437+
bcptTestFolders = @('BCPTTest1')
438+
}
439+
440+
Set-VersionInAppManifests -projectPath $testProjectPath -projectSettings $testProjectSettings -newValue '+0.1' -updatedAppFolders ([ref] $updatedAppFolders)
441+
442+
$updatedAppFolders.Count | Should -Be 4
443+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App1' -Resolve)
444+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App2' -Resolve)
445+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'Test1' -Resolve)
446+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'BCPTTest1' -Resolve)
447+
448+
Set-VersionInAppManifests -projectPath $anotherTestProjectPath -projectSettings $anotherTestProjectSettings -newValue '+0.1' -updatedAppFolders ([ref] $updatedAppFolders)
449+
450+
$updatedAppFolders.Count | Should -Be 4
451+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App1' -Resolve)
452+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App2' -Resolve)
453+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'Test1' -Resolve)
454+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'BCPTTest1' -Resolve)
455+
456+
# Add the new app folder to the settings for anotherTestProject
457+
$anotherTestProjectSettings.appFolders += @($anotherTestProjectAppFolder)
458+
459+
Set-VersionInAppManifests -projectPath $anotherTestProjectPath -projectSettings $anotherTestProjectSettings -newValue '+0.1' -updatedAppFolders ([ref] $updatedAppFolders)
460+
$updatedAppFolders.Count | Should -Be 5
461+
$updatedAppFolders | Should -Contain (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder -Resolve)
462+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App1' -Resolve)
463+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App2' -Resolve)
464+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'Test1' -Resolve)
465+
$updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'BCPTTest1' -Resolve)
466+
467+
# Verify the app.json files have been updated only once and the version is incremented
468+
$appJsonFiles = Get-ChildItem -Path $testProjectPath -Recurse -Filter 'app.json'
469+
$appJsonFiles | ForEach-Object {
470+
$appJsonContent = Get-Content $_.FullName -Encoding UTF8 | ConvertFrom-Json
471+
$appJsonContent.version | Should -Be "0.2" # 0.1 + 0.1
472+
}
473+
474+
$anotherAppJsonFiles = Get-ChildItem -Path $anotherTestProjectPath -Recurse -Filter 'app.json'
475+
$anotherAppJsonFiles | ForEach-Object {
476+
$appJsonContent = Get-Content $_.FullName -Encoding UTF8 | ConvertFrom-Json
477+
$appJsonContent.version | Should -Be "0.3" # 0.2 + 0.1
478+
}
479+
}
480+
481+
AfterEach {
482+
# Clean up the projects directory
483+
Remove-Item -Path $testProjectPath -Recurse -Force -ErrorAction Ignore
484+
Remove-Item -Path $anotherTestProjectPath -Recurse -Force -ErrorAction Ignore
485+
}
486+
}

0 commit comments

Comments
 (0)