Skip to content

Update each app.json once when running Increment Version Number #1820

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

Merged
merged 7 commits into from
Jul 15, 2025
Merged
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
24 changes: 6 additions & 18 deletions Actions/IncrementVersionNumber/IncrementVersionNumber.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions Actions/IncrementVersionNumber/IncrementVersionNumber.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,33 @@ 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))
if ($useRepoVersion) {
$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)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
110 changes: 110 additions & 0 deletions Tests/IncrementVersionNumber.Action.Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,113 @@
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
}
}
Loading