Skip to content

Commit

Permalink
Update logic for Increment Version Number (#1108)
Browse files Browse the repository at this point in the history
**Problem**
If you define the repoVersion in .github/AL-Go-Settings.json it isn't
updated when running the Increment Version Number workflow. In our case,
the would like to keep the repoVersion the same across all Al-Go
projects so having repoVersion defined on repo level makes sense for us
(even if it is a project setting)

**Proposed Solution**
* If repoVersion exists on project level (recommended), we only update
it there.
* If repoVersion doesn't exist in project level but exists on repo
level, we update it on repo level (what we want in our case)
* if repoVersion is neither defined on project level or repo level,
force create it on project level


Fixes #1105

---------

Co-authored-by: Freddy Kristiansen <[email protected]>
  • Loading branch information
aholstrup1 and freddydk authored Jun 24, 2024
1 parent 6f8c7f3 commit c9e9cc3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
31 changes: 23 additions & 8 deletions Actions/IncrementVersionNumber/IncrementVersionNumber.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,38 @@ try {
# Collect all projects (AL and PowerPlatform Solution)
$projectList = @(GetProjectsFromRepository -baseFolder $baseFolder -projectsFromSettings $settings.projects -selectProjects $projects)
$PPprojects = @(GetMatchingProjects -projects @($settings.powerPlatformSolutionFolder) -selectProjects $projects)
if ($projectList.Count -eq 0 -and $PPproject.Count -eq 0) {
throw "No projects matches '$selectProjects'"
if ($projectList.Count -eq 0 -and $PPprojects.Count -eq 0) {
throw "No projects matches '$projects'"
}

$repositorySettingsPath = Join-Path $baseFolder $RepoSettingsFile # $RepoSettingsFile is defined in AL-Go-Helper.ps1

# Increment version number in AL Projects
if ($projectList.Count -gt 0) {
$allAppFolders = @()
$repoVersionExistsInRepoSettings = Test-SettingExists -settingsFilePath $repositorySettingsPath -settingName 'repoVersion'
$repoVersionInRepoSettingsWasUpdated = $false
foreach($project in $projectList) {
$projectPath = Join-Path $baseFolder $project
$projectSettingsPath = Join-Path $projectPath $ALGoSettingsFile # $ALGoSettingsFile is defined in AL-Go-Helper.ps1
$settings = ReadSettings -baseFolder $baseFolder -project $project

# Ensure the repoVersion setting exists in the project settings. Defaults to 1.0 if it doesn't exist.
Set-VersionInSettingsFile -settingsFilePath $projectSettingsPath -settingName 'repoVersion' -newValue $settings.repoVersion -Force

# Set repoVersion in project settings according to the versionNumber parameter
Set-VersionInSettingsFile -settingsFilePath $projectSettingsPath -settingName 'repoVersion' -newValue $versionNumber
if (Test-SettingExists -settingsFilePath $projectSettingsPath -settingName 'repoVersion') {
# If 'repoVersion' exists in the project settings, update it there
Set-VersionInSettingsFile -settingsFilePath $projectSettingsPath -settingName 'repoVersion' -newValue $versionNumber
} elseif ($repoVersionExistsInRepoSettings) {
# If 'repoVersion' is not found in project settings but it exists in repo settings, update it there instead
if (-not $repoVersionInRepoSettingsWasUpdated) {
Write-Host "Setting 'repoVersion' not found in $projectSettingsPath. Updating it on repo level instead"
Set-VersionInSettingsFile -settingsFilePath $repositorySettingsPath -settingName 'repoVersion' -newValue $versionNumber
$repoVersionInRepoSettingsWasUpdated = $true
}
} else {
# If 'repoVersion' is neither found in project settings nor in repo settings, force create it in project settings
# Ensure the repoVersion setting exists in the project settings. Defaults to 1.0 if it doesn't exist.
$settings = ReadSettings -baseFolder $baseFolder -project $project
Set-VersionInSettingsFile -settingsFilePath $projectSettingsPath -settingName 'repoVersion' -newValue $settings.repoVersion -Force
Set-VersionInSettingsFile -settingsFilePath $projectSettingsPath -settingName 'repoVersion' -newValue $versionNumber
}

# Resolve project folders to get all app folders that contain an app.json file
$projectSettings = ReadSettings -baseFolder $baseFolder -project $project
Expand Down
36 changes: 35 additions & 1 deletion Actions/IncrementVersionNumber/IncrementVersionNumber.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,40 @@ function Set-VersionInSettingsFile {
$settingsJson | Set-JsonContentLF -Path $settingsFilePath
}

<#
.Synopsis
Checks if a setting exists in a settings file.
.Description
Checks if a setting exists in a settings file.
.Parameter settingsFilePath
Path to a JSON file containing the settings.
.Parameter settingName
Name of the setting to check.
#>
function Test-SettingExists {
param(
[Parameter(Mandatory = $true)]
[string] $settingsFilePath,
[Parameter(Mandatory = $true)]
[string] $settingName
)

if (-not (Test-Path $settingsFilePath)) {
throw "Settings file ($settingsFilePath) not found."
}

Write-Host "Reading settings from $settingsFilePath"
try {
$settingsJson = Get-Content $settingsFilePath -Encoding UTF8 -Raw | ConvertFrom-Json
}
catch {
throw "Settings file ($settingsFilePath) is malformed: $_"
}

$settingExists = [bool] ($settingsJson.PSObject.Properties.Name -eq $settingName)
return $settingExists
}

<#
.Synopsis
Changes the version number of a project.
Expand Down Expand Up @@ -258,4 +292,4 @@ function Set-PowerPlatformSolutionVersion {
}
}

Export-ModuleMember -Function Set-VersionInSettingsFile, Set-VersionInAppManifests, Set-DependenciesVersionInAppManifests, Set-PowerPlatformSolutionVersion
Export-ModuleMember -Function Set-VersionInSettingsFile, Set-VersionInAppManifests, Set-DependenciesVersionInAppManifests, Set-PowerPlatformSolutionVersion, Test-SettingExists
4 changes: 4 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Issues

- Issue 1105 Increment Version Number - repoVersion in .github/AL-Go-Settings.json is not updated

### Business Central Performance Toolkit Test Result Viewer

In the summary after a Test Run, you now also have the result of performance tests.
Expand Down

0 comments on commit c9e9cc3

Please sign in to comment.