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

Update logic for Increment Version Number #1108

Merged
merged 17 commits into from
Jun 24, 2024
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
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
aholstrup1 marked this conversation as resolved.
Show resolved Hide resolved
# 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
Loading