diff --git a/Extensions/Versioning/VersionPowerShellModule/src/Update-PowerShellModuleVersion.ps1 b/Extensions/Versioning/VersionPowerShellModule/src/Update-PowerShellModuleVersion.ps1 index c40a266c6..7ca54a045 100644 --- a/Extensions/Versioning/VersionPowerShellModule/src/Update-PowerShellModuleVersion.ps1 +++ b/Extensions/Versioning/VersionPowerShellModule/src/Update-PowerShellModuleVersion.ps1 @@ -27,6 +27,7 @@ $VersionNumber = Get-VstsInput -Name "VersionNumber" $InjectVersion = Get-VstsInput -Name "InjectVersion" $VersionRegex = Get-VstsInput -Name "VersionRegex" $outputversion = Get-VstsInput -Name "outputversion" +$recurse = Get-VstsInput -Name "recurse" $VersionNumber,$Prerelease = $VersionNumber -split '-' -replace '"' -replace "'" # Get and validate the version data @@ -71,10 +72,17 @@ Write-Verbose -Message "Loading Configuration module shipped with tasks" Import-Module "$PSScriptRoot\Configuration\1.5.0\Configuration.psd1" -force $Null = Get-Command -Module Configuration -Write-Verbose -Message "Finding all the module psd1 files in the specified path" -$ModuleFiles = Get-ChildItem -Path $Path -Filter *.psd1 -Recurse | - Select-String -Pattern 'RootModule' | - Select-Object -ExpandProperty Path -Unique +if ([System.Convert]::ToBoolean($recurse)) { + Write-Verbose -Message "Finding all the module psd1 files in the specified path recursively" + $ModuleFiles = Get-ChildItem -Path $Path -Filter *.psd1 -Recurse | + Select-String -Pattern 'RootModule' | + Select-Object -ExpandProperty Path -Unique +} else { + Write-Verbose -Message "Finding all the module psd1 files in the specified path only" + $ModuleFiles = Get-ChildItem -Path $Path -Filter *.psd1 | + Select-String -Pattern 'RootModule' | + Select-Object -ExpandProperty Path -Unique +} Write-Verbose "Found $($ModuleFiles.Count) modules. Beginning to apply updated version number $VersionNumber." diff --git a/Extensions/Versioning/VersionPowerShellModule/src/task.json b/Extensions/Versioning/VersionPowerShellModule/src/task.json index 7e5303cf4..065d9a3d3 100644 --- a/Extensions/Versioning/VersionPowerShellModule/src/task.json +++ b/Extensions/Versioning/VersionPowerShellModule/src/task.json @@ -51,6 +51,15 @@ "helpMarkDown": "If True no regex processing will be done to the build number.", "groupName":"advanced" }, + { + "name": "recurse", + "type": "boolean", + "label": "Recursive Search", + "defaultValue": "True", + "required": false, + "helpMarkDown": "Recurse when searching for PSD1 files", + "groupName":"advanced" + }, { "name": "VersionRegex", "type": "string", diff --git a/Extensions/Versioning/VersionPowerShellModule/test/Update-PowerShellModuleVersion.Tests.ps1 b/Extensions/Versioning/VersionPowerShellModule/test/Update-PowerShellModuleVersion.Tests.ps1 index d27b74abb..8c6195a36 100644 --- a/Extensions/Versioning/VersionPowerShellModule/test/Update-PowerShellModuleVersion.Tests.ps1 +++ b/Extensions/Versioning/VersionPowerShellModule/test/Update-PowerShellModuleVersion.Tests.ps1 @@ -6,83 +6,116 @@ Describe "Testing Update-PowerShellModuleVersion.ps1" { BeforeEach { $sut = Join-Path -Path $PSScriptRoot -ChildPath '..\src\Update-PowerShellModuleVersion.ps1' -Resolve - function Get-VstsInput {param ($Name)} + function Get-VstsInput { param ($Name) } Function Update-MetaData {} Function Get-MetaData {} -# Mock -CommandName Write-Verbose -MockWith {} + # Mock -CommandName Write-Verbose -MockWith {} Mock -CommandName Write-Warning -MockWith {} Mock -CommandName Write-Error -MockWith {} Mock -CommandName Get-PackageProvider -MockWith {} Mock -CommandName Install-PackageProvider -MockWith {} Mock Find-Module { - [PsCustomObject]@{Version=[version]::new(4,3,0);Repository='OtherRepository'} + [PsCustomObject]@{Version = [version]::new(4, 3, 0); Repository = 'OtherRepository' } } Mock -CommandName Install-Module -MockWith {} Mock -CommandName Import-Module -MockWith {} Mock -CommandName Update-MetaData -MockWith {} Mock -CommandName Write-Host -MockWith {} - Mock -CommandName Get-ChildItem -MockWith {@( - [PSCustomObject]@{ - Fullname = 'TestDrive:\First.psd1' - }, - [PSCustomObject]@{ - Fullname = 'TestDrive:\Second.psd1' - } - )} + Mock -CommandName Get-ChildItem -MockWith { @( + [PSCustomObject]@{ + Fullname = 'TestDrive:\First.psd1' + }, + [PSCustomObject]@{ + Fullname = 'TestDrive:\Second.psd1' + }, + [PSCustomObject]@{ + Fullname = 'TestDrive:\SubFolder\Third.psd1' + } + ) } Mock -CommandName Select-String -MockWith { [PSCustomObject]@{ Path = 'TestDrive:\First.psd1' } } - Mock -CommandName Get-MetaData -MockWith {$true} + Mock -CommandName Get-MetaData -MockWith { $true } #Mock -CommandName Select-Object -MockWith {} } It "Should write an error when the version number isn't a valid format" { - Mock Get-VstsInput -ParameterFilter {$Name -eq "Path"} {return 'TestDrive:\First.psd1'} - Mock Get-VstsInput -ParameterFilter {$Name -eq "VersionNumber"} {return "FakeNumber"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "InjectVersion"} {return "true"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "VersionRegex"} {return "\d+\.\d+\.\d+\.\d+"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "outputversion"} {return ""} + Mock Get-VstsInput -ParameterFilter { $Name -eq "Path" } { return 'TestDrive:\First.psd1' } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionNumber" } { return "FakeNumber" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "InjectVersion" } { return "true" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionRegex" } { return "\d+\.\d+\.\d+\.\d+" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "outputversion" } { return "" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "recurse" } { return "true" } + &$Sut Assert-MockCalled -CommandName Write-Error -Scope It -Times 1 } It "Should attempt to update 1 module in the target path" { - Mock Get-VstsInput -ParameterFilter {$Name -eq "Path"} {return 'TestDrive:\'} - Mock Get-VstsInput -ParameterFilter {$Name -eq "VersionNumber"} {return "1.2.3.4"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "InjectVersion"} {return "true"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "VersionRegex"} {return "\d+\.\d+\.\d+\.\d+"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "outputversion"} {return ""} + Mock Get-VstsInput -ParameterFilter { $Name -eq "Path" } { return 'TestDrive:\' } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionNumber" } { return "1.2.3.4" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "InjectVersion" } { return "true" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionRegex" } { return "\d+\.\d+\.\d+\.\d+" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "outputversion" } { return "" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "recurse" } { return "true" } + - Mock -CommandName Select-Object -MockWith {'TestDrive:\First.psd1'} -ParameterFilter {$InputObject.Path -eq 'TestDrive:\First.psd1'} + Mock -CommandName Select-Object -MockWith { 'TestDrive:\First.psd1' } -ParameterFilter { $InputObject.Path -eq 'TestDrive:\First.psd1' } &$Sut Assert-MockCalled -CommandName Update-Metadata -Scope It -Times 1 } - It "Should attempt to update 2 modules in the target path" { + It "Should attempt to update 3 modules in the target path (recursive)" { + + Mock Get-VstsInput -ParameterFilter { $Name -eq "Path" } { return 'TestDrive:\' } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionNumber" } { return "1.2.3.4" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "InjectVersion" } { return "true" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionRegex" } { return "\d+\.\d+\.\d+\.\d+" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "outputversion" } { return "" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "recurse" } { return "true" } - Mock Get-VstsInput -ParameterFilter {$Name -eq "Path"} {return 'TestDrive:\'} - Mock Get-VstsInput -ParameterFilter {$Name -eq "VersionNumber"} {return "1.2.3.4"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "InjectVersion"} {return "true"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "VersionRegex"} {return "\d+\.\d+\.\d+\.\d+"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "outputversion"} {return ""} &$Sut - Assert-MockCalled -CommandName Update-Metadata -Scope It -Times 2 + Assert-MockCalled -CommandName Update-Metadata -Scope It -Exactly 6 # for each file runs twice + } + It "Should attempt to update 2 modules in the target path (non-recursive)" { + + Mock Get-VstsInput -ParameterFilter { $Name -eq "Path" } { return 'TestDrive:\' } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionNumber" } { return "1.2.3.4" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "InjectVersion" } { return "true" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionRegex" } { return "\d+\.\d+\.\d+\.\d+" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "outputversion" } { return "" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "recurse" } { return "false" } + + Mock -CommandName Get-ChildItem -MockWith { @( + [PSCustomObject]@{ + Fullname = 'TestDrive:\First.psd1' + }, + [PSCustomObject]@{ + Fullname = 'TestDrive:\Second.psd1' + } + ) } + + &$Sut + + Assert-MockCalled -CommandName Update-Metadata -Scope It -Exactly 4 # for each file runs twice } It "Should attempt to update the version number and private data in 1 module in the target path when a prerelease version is passed" { - Mock Get-VstsInput -ParameterFilter {$Name -eq "Path"} {return 'TestDrive:\'} - Mock Get-VstsInput -ParameterFilter {$Name -eq "VersionNumber"} {return "1.2.3.4-alpha"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "InjectVersion"} {return "true"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "VersionRegex"} {return "\d+\.\d+\.\d+\.\d+"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "outputversion"} {return ""} - Mock -CommandName Select-Object -MockWith {'TestDrive:\First.psd1'} -ParameterFilter {$InputObject.Path -eq 'TestDrive:\First.psd1'} + Mock Get-VstsInput -ParameterFilter { $Name -eq "Path" } { return 'TestDrive:\' } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionNumber" } { return "1.2.3.4-alpha" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "InjectVersion" } { return "true" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionRegex" } { return "\d+\.\d+\.\d+\.\d+" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "outputversion" } { return "" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "recurse" } { return "true" } + + Mock -CommandName Select-Object -MockWith { 'TestDrive:\First.psd1' } -ParameterFilter { $InputObject.Path -eq 'TestDrive:\First.psd1' } &$Sut @@ -90,19 +123,21 @@ Describe "Testing Update-PowerShellModuleVersion.ps1" { } It "Should write a warning when the PSData Prerelease section isn't in the manifest when a prerelease version is passed" { - Mock Get-VstsInput -ParameterFilter {$Name -eq "Path"} {return 'TestDrive:\'} - Mock Get-VstsInput -ParameterFilter {$Name -eq "VersionNumber"} {return "1.2.3.4-alpha"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "InjectVersion"} {return "true"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "VersionRegex"} {return "\d+\.\d+\.\d+\.\d+"} - Mock Get-VstsInput -ParameterFilter {$Name -eq "outputversion"} {return ""} - Mock -CommandName Select-Object -MockWith {'TestDrive:\First.psd1'} -ParameterFilter {$InputObject.Path -eq 'TestDrive:\First.psd1'} - Mock -CommandName Get-MetaData -MockWith {$null} + Mock Get-VstsInput -ParameterFilter { $Name -eq "Path" } { return 'TestDrive:\' } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionNumber" } { return "1.2.3.4-alpha" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "InjectVersion" } { return "true" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "VersionRegex" } { return "\d+\.\d+\.\d+\.\d+" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "outputversion" } { return "" } + Mock Get-VstsInput -ParameterFilter { $Name -eq "recurse" } { return "true" } + + Mock -CommandName Select-Object -MockWith { 'TestDrive:\First.psd1' } -ParameterFilter { $InputObject.Path -eq 'TestDrive:\First.psd1' } + Mock -CommandName Get-MetaData -MockWith { $null } &$Sut Assert-MockCalled -CommandName Update-Metadata -Scope It -Times 1 Assert-MockCalled -CommandName Write-Warning -Scope It -Times 1 -ParameterFilter { $Message -eq ("Cannot set Prerelease in module manifest. Add an empty Prerelease to your module manifest, like:`n" + - ' PrivateData = @{ PSData = @{ Prerelease = "" } }') + ' PrivateData = @{ PSData = @{ Prerelease = "" } }') } } } diff --git a/Extensions/Versioning/azure-pipelines-build.yml b/Extensions/Versioning/azure-pipelines-build.yml index 1c53bd8d1..4e701cbc1 100644 --- a/Extensions/Versioning/azure-pipelines-build.yml +++ b/Extensions/Versioning/azure-pipelines-build.yml @@ -42,12 +42,14 @@ stages: rootDirectory: '$(Build.SourcesDirectory)/$(ExtensionRoot)' targetFiles: '**\\task.json' - - task: Pester.PesterRunner.Pester-Task.Pester@10 + - task: Pester.PesterRunner.Pester-Task.Pester@9 displayName: 'DACPac Versioning Pester Test Runner' inputs: scriptFolder: '$(Build.SourcesDirectory)\$(ExtensionRoot)\VersionDacpacTask\test' resultsFile: '$(Build.SourcesDirectory)\Test-VersionDacpacTaskPester.XML' run32Bit: false + PesterVersion: 'OtherVersion' + preferredPesterVersion: '4.10.1' continueOnError: true - task: PublishTestResults@2 @@ -57,12 +59,14 @@ stages: testResultsFiles: '$(Build.SourcesDirectory)\Test-VersionDacpacTaskPester.XML' testRunTitle: 'DACPac Pester Tests' - - task: Pester.PesterRunner.Pester-Task.Pester@10 + - task: Pester.PesterRunner.Pester-Task.Pester@9 displayName: 'PowerShellModule Versioning Tests' inputs: scriptFolder: '$(Build.SourcesDirectory)\$(ExtensionRoot)\VersionPowerShellModule\test' resultsFile: '$(Build.SourcesDirectory)\Test-VersionPowerShellTaskPester.XML' run32Bit: false + PesterVersion: 'OtherVersion' + preferredPesterVersion: '4.10.1' - task: PublishTestResults@2 displayName: 'Publish Test Results $(Build.SourcesDirectory)\Test-VersionPowerShellTaskPester.XML'