Skip to content

Commit

Permalink
Clean-up, add comments, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
mazhelez committed Jan 31, 2024
1 parent b6dee6d commit 34aa16b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Actions/IncrementVersionNumber/IncrementVersionNumber.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ try {
$newVersion = [System.Version]"$($versionNumber).0.0"

# Change repoVersion in repository settings
Set-SettingInFile -settingsFilePath (Join-Path $baseFolder $RepoSettingsFile) -settingName 'repoVersion' -newValue $newVersion -incremental:$addToVersionNumber
Set-SettingInFile -settingsFilePath (Join-Path $baseFolder $RepoSettingsFile) -settingName 'repoVersion' -newValue $newVersion -incremental:$addToVersionNumber # $RepoSettingsFile is defined in AL-Go-Helper.ps1

$settings = $env:Settings | ConvertFrom-Json
$projectList = @(GetProjectsFromRepository -baseFolder $baseFolder -projectsFromSettings $settings.projects -selectProjects $projects)
Expand Down
39 changes: 19 additions & 20 deletions Actions/IncrementVersionNumber/IncrementVersionNumber.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
.Parameter newValue
New value of the setting.
.Parameter incremental
If set, the new value will be added to the old value. The old value must be a version number.
If set, the new value will be added to the old value. The old value must be a version number. The new value must be a version number.
#>
function Set-SettingInFile($settingsFilePath, $settingName, $newValue, [switch] $incremental) {
if (-not (Test-Path $settingsFilePath)) {
throw "Settings file ($settingsFilePath) not found."
}

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

if (-not ($settingFileContent.PSObject.Properties.Name -eq $settingName)) {
Write-Host "Setting $settingName not found in $settingsFilePath"
Expand Down Expand Up @@ -49,33 +54,27 @@ function Set-SettingInFile($settingsFilePath, $settingName, $newValue, [switch]
.Parameter newVersion
New version number.
.Parameter incremental
If set, the new version number will be added to the old version number.
If set, the new version number will be added to the old version number. The old version number must be a version number.
#>
function Set-ProjectVersion($projectPath, $projectSettings, $newVersion, [switch] $incremental) {
$projectSettingsPath = Join-Path $projectPath $ALGoSettingsFile
# Set repoVersion in project settings (if it exists)
$projectSettingsPath = Join-Path $projectPath $ALGoSettingsFile # $ALGoSettingsFile is defined in AL-Go-Helper.ps1
Set-SettingInFile -settingsFilePath $projectSettingsPath -settingName 'repoVersion' -newValue $newVersion -incremental:$incremental | Out-Null

# Check if the project uses repoVersion versioning strategy
$useRepoVersion = (($projectSettings.PSObject.Properties.Name -eq "versioningStrategy") -and (($projectSettings.versioningStrategy -band 16) -eq 16))
if ($useRepoVersion) {
$newVersion = $projectSettings.repoVersion
$incremental = $false # Don't increment the version number if the project uses repoVersion versioning strategy
}

$folders = @($projectSettings.appFolders) + @($projectSettings.testFolders)
$folders | ForEach-Object {
$folder = $_
$folder = Join-Path $projectPath $folder
Write-Host "Modifying app.json in folder $folder"

# Set version in app.json files
$allAppFolders = @($projectSettings.appFolders) + @($projectSettings.testFolders) + @($projectSettings.bcptTestFolders)
$allAppFolders | ForEach-Object {
$folder = Join-Path $projectPath $_
$appJsonFile = Join-Path $folder "app.json"
try {
if ($useRepoVersion) {
$newVersion = $projectSettings.repoVersion
$incremental = $false # Don't increment the version number if the project uses repoVersion versioning strategy
}

Set-SettingInFile -settingsFilePath $appJsonFile -settingName 'version' -newValue $newVersion -incremental:$incremental | Out-Null
}
catch {
throw "Application manifest file($appJsonFile) is malformed: $_"
}
Set-SettingInFile -settingsFilePath $appJsonFile -settingName 'version' -newValue $newVersion -incremental:$incremental | Out-Null
}
}

Expand Down

0 comments on commit 34aa16b

Please sign in to comment.