diff --git a/Actions/IncrementVersionNumber/IncrementVersionNumber.ps1 b/Actions/IncrementVersionNumber/IncrementVersionNumber.ps1 index 0d0730404..f459532cd 100644 --- a/Actions/IncrementVersionNumber/IncrementVersionNumber.ps1 +++ b/Actions/IncrementVersionNumber/IncrementVersionNumber.ps1 @@ -57,8 +57,8 @@ if ($projectList.Count -eq 0 -and $PPprojects.Count -eq 0) { $repositorySettingsPath = Join-Path $baseFolder $RepoSettingsFile # $RepoSettingsFile is defined in AL-Go-Helper.ps1 # Increment version number in AL Projects +$allAppFolders = @() if ($projectList.Count -gt 0) { - $allAppFolders = @() $repoVersionExistsInRepoSettings = Test-SettingExists -settingsFilePath $repositorySettingsPath -settingName 'repoVersion' $repoVersionInRepoSettingsWasUpdated = $false foreach ($project in $projectList) { @@ -89,25 +89,13 @@ if ($projectList.Count -gt 0) { $projectSettings = ReadSettings -baseFolder $baseFolder -project $project ResolveProjectFolders -baseFolder $baseFolder -project $project -projectSettings ([ref] $projectSettings) - # Set version in app manifests (app.json files) - Set-VersionInAppManifests -projectPath $projectPath -projectSettings $projectSettings -newValue $versionNumber - - # Collect all project's app folders - $allAppFolders += $projectSettings.appFolders | ForEach-Object { Join-Path $projectPath $_ -Resolve } - $allAppFolders += $projectSettings.testFolders | ForEach-Object { Join-Path $projectPath $_ -Resolve } - $allAppFolders += $projectSettings.bcptTestFolders | ForEach-Object { Join-Path $projectPath $_ -Resolve } + Set-VersionInAppManifests -projectPath $projectPath -projectSettings $projectSettings -newValue $versionNumber -updatedAppFolders ([ref] $allAppFolders) } +} - if (-not $skipUpdatingDependencies) { - # Set dependencies in app manifests - if ($allAppFolders.Count -eq 0) { - Write-Host "No App folders found for projects $projects" - } - else { - # Set dependencies in app manifests - Set-DependenciesVersionInAppManifests -appFolders $allAppFolders - } - } +if (-not $skipUpdatingDependencies) { + # Set dependencies in app manifests + Set-DependenciesVersionInAppManifests -appFolders $allAppFolders } # Increment version number in PowerPlatform Solution diff --git a/Actions/IncrementVersionNumber/IncrementVersionNumber.psm1 b/Actions/IncrementVersionNumber/IncrementVersionNumber.psm1 index 4cd4f617b..05aee5e47 100644 --- a/Actions/IncrementVersionNumber/IncrementVersionNumber.psm1 +++ b/Actions/IncrementVersionNumber/IncrementVersionNumber.psm1 @@ -189,8 +189,10 @@ function Test-SettingExists { Name of the project (relative to the base folder). .Parameter newValue 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. + .Parameter updatedAppFolders + [ref] Array of paths to the app folders that were updated. This is used to avoid updating the same app folder multiple times. #> -function Set-VersionInAppManifests($projectPath, $projectSettings, $newValue) { +function Set-VersionInAppManifests($projectPath, $projectSettings, $newValue, [ref] $updatedAppFolders) { # Check if the project uses repoVersion versioning strategy $useRepoVersion = (($projectSettings.PSObject.Properties.Name -eq "versioningStrategy") -and (($projectSettings.versioningStrategy -band 16) -eq 16)) @@ -198,13 +200,22 @@ function Set-VersionInAppManifests($projectPath, $projectSettings, $newValue) { $newValue = $projectSettings.repoVersion } + if (-not $updatedAppFolders.Value) { + $updatedAppFolders.Value = @() + } + $allAppFolders = @($projectSettings.appFolders) + @($projectSettings.testFolders) + @($projectSettings.bcptTestFolders) # Set version in app.json files $allAppFolders | ForEach-Object { - $appFolder = Join-Path $projectPath $_ - $appJson = Join-Path $appFolder "app.json" + $appFolder = Join-Path $projectPath $_ -Resolve - Set-VersionInSettingsFile -settingsFilePath $appJson -settingName 'version' -newValue $newValue + # Update the app only if it's not already updated + if (-not ($updatedAppFolders.Value -contains $appFolder)) { + $appJson = Join-Path $appFolder "app.json" + Set-VersionInSettingsFile -settingsFilePath $appJson -settingName 'version' -newValue $newValue + + $updatedAppFolders.Value += @($appFolder) + } } } diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 5b2fbf34c..77d47b039 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -7,6 +7,7 @@ AL-Go now offers a dataexplorer dashboard to get started with AL-Go telemetry. A - Issue 1770 Wrong type of _projects_ setting in settings schema - Issue 1787 Publish to Environment from PR fails in private repos - Issue 1722 Check if apps are already installed on a higher version before deploying +- Issue 1774 Increment Version Number with +0.1 can increment some version numbers twice ### Add custom jobs to AL-Go workflows diff --git a/Tests/IncrementVersionNumber.Action.Test.ps1 b/Tests/IncrementVersionNumber.Action.Test.ps1 index f9f3290c8..49cbdf445 100644 --- a/Tests/IncrementVersionNumber.Action.Test.ps1 +++ b/Tests/IncrementVersionNumber.Action.Test.ps1 @@ -374,3 +374,113 @@ Describe "Set-VersionInSettingsFile tests" { Remove-Item $settingsFile -Force -ErrorAction Ignore } } + +Describe 'Set-VersionInAppManifests tests' { + BeforeAll { + . (Join-Path -Path $PSScriptRoot -ChildPath "..\Actions\AL-Go-Helper.ps1" -Resolve) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "..\Actions\IncrementVersionNumber\IncrementVersionNumber.psm1" -Resolve) -Force + } + + BeforeEach { + $testProjectPath = Join-Path ([System.IO.Path]::GetTempPath()) "TestProject" + New-Item -ItemType Directory -Path $testProjectPath -Force | Out-Null + + # Create mock app folders for TestProject + $appFolders = @('App1', 'App2', 'Test1', 'BCPTTest1') + foreach ($folder in $appFolders) { + New-Item -ItemType Directory -Path (Join-Path $testProjectPath $folder) -Force | Out-Null + New-Item -ItemType File -Path (Join-Path $testProjectPath $folder 'app.json') -Force | Out-Null + $appJsonContent = @{ + "version" = "0.1" + "name" = $folder + } + $appJsonContent | ConvertTo-Json | Set-Content (Join-Path $testProjectPath $folder 'app.json') -Encoding UTF8 + } + + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'testProjectSettings', Justification = 'False positive.')] + $testProjectSettings = @{ + appFolders = @($appFolders[0..1]) # App1, App2 + testFolders = @($appFolders[2]) # Test1 + bcptTestFolders = @($appFolders[3]) # BCPTTest1 + } + + # Create another project folder that points to the same app folders + $anotherTestProjectPath = Join-Path ([System.IO.Path]::GetTempPath()) "AnotherTestProject" + New-Item -ItemType Directory -Path $anotherTestProjectPath -Force | Out-Null + + Push-Location $anotherTestProjectPath + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'anotherTestProjectSettings', Justification = 'False positive.')] + $anotherTestProjectSettings = @{ + appFolders = @($appFolders[0..1]) | ForEach-Object { Resolve-Path (Join-Path $testProjectPath $_) -Relative } # App1, App2 + testFolders = @($appFolders[2]) | ForEach-Object { Resolve-Path (Join-Path $testProjectPath $_) -Relative } # Test1 + bcptTestFolders = @($appFolders[3]) | ForEach-Object { Resolve-Path (Join-Path $testProjectPath $_) -Relative } # BCPTTest1 + } + + $anotherTestProjectAppFolder = 'Another TestProjectApp' + New-Item -ItemType Directory -Path (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder) -Force | Out-Null + New-Item -ItemType File -Path (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder 'app.json') -Force | Out-Null + $anotherTestProjectAppJsonContent = @{ + "version" = "0.2" + "name" = $anotherTestProjectAppFolder + } + $anotherTestProjectAppJsonContent | ConvertTo-Json | Set-Content (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder 'app.json') -Encoding UTF8 + + Pop-Location + } + + It 'Set-VersionInAppManifests updates all app.json files once and increments the version' { + $updatedAppFolders = @() + $testProjectSettings = @{ + versioningStrategy = 0 + appFolders = @('App1', 'App2') + testFolders = @('Test1') + bcptTestFolders = @('BCPTTest1') + } + + Set-VersionInAppManifests -projectPath $testProjectPath -projectSettings $testProjectSettings -newValue '+0.1' -updatedAppFolders ([ref] $updatedAppFolders) + + $updatedAppFolders.Count | Should -Be 4 + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App1' -Resolve) + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App2' -Resolve) + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'Test1' -Resolve) + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'BCPTTest1' -Resolve) + + Set-VersionInAppManifests -projectPath $anotherTestProjectPath -projectSettings $anotherTestProjectSettings -newValue '+0.1' -updatedAppFolders ([ref] $updatedAppFolders) + + $updatedAppFolders.Count | Should -Be 4 + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App1' -Resolve) + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App2' -Resolve) + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'Test1' -Resolve) + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'BCPTTest1' -Resolve) + + # Add the new app folder to the settings for anotherTestProject + $anotherTestProjectSettings.appFolders += @($anotherTestProjectAppFolder) + + Set-VersionInAppManifests -projectPath $anotherTestProjectPath -projectSettings $anotherTestProjectSettings -newValue '+0.1' -updatedAppFolders ([ref] $updatedAppFolders) + $updatedAppFolders.Count | Should -Be 5 + $updatedAppFolders | Should -Contain (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder -Resolve) + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App1' -Resolve) + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'App2' -Resolve) + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'Test1' -Resolve) + $updatedAppFolders | Should -Contain (Join-Path $testProjectPath 'BCPTTest1' -Resolve) + + # Verify the app.json files have been updated only once and the version is incremented + $appJsonFiles = Get-ChildItem -Path $testProjectPath -Recurse -Filter 'app.json' + $appJsonFiles | ForEach-Object { + $appJsonContent = Get-Content $_.FullName -Encoding UTF8 | ConvertFrom-Json + $appJsonContent.version | Should -Be "0.2" # 0.1 + 0.1 + } + + $anotherAppJsonFiles = Get-ChildItem -Path $anotherTestProjectPath -Recurse -Filter 'app.json' + $anotherAppJsonFiles | ForEach-Object { + $appJsonContent = Get-Content $_.FullName -Encoding UTF8 | ConvertFrom-Json + $appJsonContent.version | Should -Be "0.3" # 0.2 + 0.1 + } + } + + AfterEach { + # Clean up the projects directory + Remove-Item -Path $testProjectPath -Recurse -Force -ErrorAction Ignore + Remove-Item -Path $anotherTestProjectPath -Recurse -Force -ErrorAction Ignore + } +}