Skip to content

Commit 907a5c7

Browse files
authored
Always set repoVersion on project-level settings (microsoft#941)
- `repoVersion` should always be set on project-level settings as `InrecrementVersionNumber` can be called on a project. - Disallow lowering the `repoVersion` value.
1 parent eb5561a commit 907a5c7

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

Actions/IncrementVersionNumber/IncrementVersionNumber.ps1

+5-7
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,18 @@ try {
3030

3131
$settings = $env:Settings | ConvertFrom-Json
3232

33-
# Ensure the repoVersion setting exists in the repository settings. Defaults to 1.0 if it doesn't exist.
34-
Set-VersionInSettingsFile -settingsFilePath (Join-Path $baseFolder $RepoSettingsFile) -settingName 'repoVersion' -newValue $settings.repoVersion -Force # $RepoSettingsFile is defined in AL-Go-Helper.ps1
35-
36-
# Change repoVersion in repository settings
37-
Set-VersionInSettingsFile -settingsFilePath (Join-Path $baseFolder $RepoSettingsFile) -settingName 'repoVersion' -newValue $versionNumber
38-
3933
$projectList = @(GetProjectsFromRepository -baseFolder $baseFolder -projectsFromSettings $settings.projects -selectProjects $projects)
4034

4135
$allAppFolders = @()
4236
foreach($project in $projectList) {
4337
$projectPath = Join-Path $baseFolder $project
4438

45-
# Set repoVersion in project settings (if it exists)
4639
$projectSettingsPath = Join-Path $projectPath $ALGoSettingsFile # $ALGoSettingsFile is defined in AL-Go-Helper.ps1
40+
41+
# Ensure the repoVersion setting exists in the project settings. Defaults to 1.0 if it doesn't exist.
42+
Set-VersionInSettingsFile -settingsFilePath $projectSettingsPath -settingName 'repoVersion' -newValue $settings.repoVersion -Force
43+
44+
# Set repoVersion in project settings according to the versionNumber parameter
4745
Set-VersionInSettingsFile -settingsFilePath $projectSettingsPath -settingName 'repoVersion' -newValue $versionNumber
4846

4947
# Resolve project folders to get all app folders that contain an app.json file

Actions/IncrementVersionNumber/IncrementVersionNumber.psm1

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ function Set-VersionInSettingsFile {
104104
# Construct the new version number. Cast to System.Version to validate if the version number is valid.
105105
$newValue = [System.Version] "$($versionNumbers -join '.')"
106106

107+
if($newValue -lt $oldValue) {
108+
throw "The new version number ($newValue) is less than the old version number ($oldValue). The version number must be incremented."
109+
}
110+
107111
if($newValue -eq $oldValue) {
108112
Write-Host "The setting $settingName is already set to $newValue in $settingsFilePath"
109113
return

Tests/IncrementVersionNumber.Action.Test.ps1

+15-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@ Describe "Set-VersionInSettingsFile tests" {
210210
$newSettingsContent.otherSetting | Should -Be "otherSettingValue"
211211
}
212212

213+
It 'Set-VersionInSettingsFile -newValue 2.0 throws an error because it''s not incremented' {
214+
$settingsFile = New-TestSettingsFilePath -repoVersion '2.0'
215+
$settingName = 'repoVersion'
216+
$newValue = '1.0'
217+
218+
{ Set-VersionInSettingsFile -settingsFilePath $settingsFile -settingName $settingName -newValue $newValue } | Should -Throw "The new version number ($newValue) is less than the old version number (2.0). The version number must be incremented."
219+
220+
$newSettingsContent = Get-Content $settingsFile -Encoding UTF8 | ConvertFrom-Json
221+
$newSettingsContent.$settingName | Should -Be "2.0"
222+
223+
# Check that the other setting are not changed
224+
$newSettingsContent.otherSetting | Should -Be "otherSettingValue"
225+
}
226+
213227
It 'Set-VersionInSettingsFile -newValue +1 increments the major version number and sets the minor version number to 0' {
214228
$settingsFile = New-TestSettingsFilePath
215229
$settingName = 'repoVersion'
@@ -238,7 +252,7 @@ Describe "Set-VersionInSettingsFile tests" {
238252
$newSettingsContent.otherSetting | Should -Be "otherSettingValue"
239253
}
240254

241-
It 'Set-VersionInSettingsFile -newValue is set and bnFileuild and revision are kept from the old value'{
255+
It 'Set-VersionInSettingsFile -newValue is set and build and revision are kept from the old value'{
242256
$settingsFile = New-TestSettingsFilePath -repoVersion '1.2.0.0'
243257
$settingName = 'repoVersion'
244258
$newValue = '2.1'

0 commit comments

Comments
 (0)