From 9baa8bde51e97418a796da3e3df6058d9435ea46 Mon Sep 17 00:00:00 2001 From: Akos Murati Date: Sat, 6 Jan 2018 02:49:59 +1300 Subject: [PATCH] Update build and test by manifest --- Tests/BambooModule/Module.tests.ps1 | 41 --------------------- Tests/BambooModule/ScriptAnalyzer.tests.ps1 | 34 ----------------- Tests/BambooModule/expected_commands.csv | 31 ---------------- psakefile.ps1 | 33 ++++++++++------- 4 files changed, 20 insertions(+), 119 deletions(-) delete mode 100644 Tests/BambooModule/Module.tests.ps1 delete mode 100644 Tests/BambooModule/ScriptAnalyzer.tests.ps1 delete mode 100644 Tests/BambooModule/expected_commands.csv diff --git a/Tests/BambooModule/Module.tests.ps1 b/Tests/BambooModule/Module.tests.ps1 deleted file mode 100644 index c331f38..0000000 --- a/Tests/BambooModule/Module.tests.ps1 +++ /dev/null @@ -1,41 +0,0 @@ -. (Join-Path $PSScriptRoot '../TestCommon.ps1') - -$exportedCommands = (Get-Command -Module $Script:ModuleName) -$expectedCommands = Import-Csv -Path (Join-Path $PSScriptRoot 'expected_commands.csv') - -Describe "$($Script:ModuleName) Module" { - It "Should be loaded" { - Get-Module $Script:ModuleName | Should Not BeNullOrEmpty - } -} - -Describe 'Exported commands' { - # Test if the exported command is expected - Foreach ($command in $exportedCommands) - { - Context $command { - It 'Should be an expected command' { - $expectedCommands.Name -contains $command.Name | Should Be $true - } - - It 'Should have proper help' { - $help = Get-Help $command.Name - $help.description | Should Not BeNullOrEmpty - $help.Synopsis | Should Not BeNullOrEmpty - $help.examples | Should Not BeNullOrEmpty - } - } - } -} - -Describe 'Expected commands' { - # Test if the expected command is exported - Foreach ($command in $expectedCommands) - { - Context $command.Name { - It 'Should be an exported command' { - $exportedCommands.Name -contains $command.Name | Should Be $true - } - } - } -} diff --git a/Tests/BambooModule/ScriptAnalyzer.tests.ps1 b/Tests/BambooModule/ScriptAnalyzer.tests.ps1 deleted file mode 100644 index 264d307..0000000 --- a/Tests/BambooModule/ScriptAnalyzer.tests.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -. (Join-Path $PSScriptRoot '../TestCommon.ps1') - -$scriptSources = Get-ChildItem -Path $script:FunctionPath -Filter '*.ps1' -Recurse -$scriptAnalyzer = Get-Module PSScriptAnalyzer -ListAvailable - -$excludeRuleList = @( - 'PSUseShouldProcessForStateChangingFunctions' -) - -if (-Not $scriptAnalyzer) { - Write-Warning "PSScriptAnalyzer module is not available." - return -} - -Describe "Script Source analysis" { - Import-Module PSScriptAnalyzer - - $scriptSources | ForEach-Object { - Context "Source $($_.FullName)" { - $results = Invoke-ScriptAnalyzer -Path $_.FullName -ErrorVariable $errors -ExcludeRule $excludeRuleList - - it "should have no errors" { - $errors | Should BeNullOrEmpty - } - - it "should not have warnings" { - $results | - Where-Object Severity -eq "Warning" | - Should BeNullOrEmpty - } - - } - } -} diff --git a/Tests/BambooModule/expected_commands.csv b/Tests/BambooModule/expected_commands.csv deleted file mode 100644 index af96f92..0000000 --- a/Tests/BambooModule/expected_commands.csv +++ /dev/null @@ -1,31 +0,0 @@ -Name -Add-BambooPlanBranch -Copy-BambooPlan -Disable-BambooPlan -Disable-BambooPlanBranch -Enable-BambooPlan -Enable-BambooPlanBranch -Expand-BambooResource -Get-BambooArtifact -Get-BambooBuild -Get-BambooBuildLog -Get-BambooCurrentUser -Get-BambooDeployEnvironmentResult -Get-BambooDeployProject -Get-BambooDeployProjectEnvironment -Get-BambooInfo -Get-BambooPlan -Get-BambooPlanBranch -Get-BambooProject -Get-BambooQueuedBuild -Get-BambooResult -Get-BambooResultLog -Get-BambooServer -Invoke-BambooRestMethod -Resume-BambooBuild -Resume-BambooQueuedBuild -Set-BambooAuthentication -Set-BambooServer -Start-BambooBuild -Stop-BambooQueuedBuild -Add_ObjectType diff --git a/psakefile.ps1 b/psakefile.ps1 index d236b48..1e9e148 100644 --- a/psakefile.ps1 +++ b/psakefile.ps1 @@ -1,7 +1,7 @@ -# PSake makes variables declared here available in other scriptblocks -# Init some things +# Visuals and shared properties +FormatTaskName ("`n$("-"*70)`n{0}`n$("-"*70)`n") + Properties { - # Find the build folder based on build system $ProjectRoot = $ENV:BHProjectPath if(-not $ProjectRoot) { $ProjectRoot = $PSScriptRoot @@ -17,30 +17,37 @@ Properties { } } -FormatTaskName ("`n$("-"*70)`n{0}$("-"*70)`n") - Task Default -Depends Deploy Task Init { Set-Location $ProjectRoot - "Build System Details:" + Write-Host "Build System" Get-Item ENV:BH* - "Module details:" + Write-Host "Modules" Get-Module | Format-Table Name,Version + + Write-Host "Working directory" + Get-ChildItem } Task Build -Depends Init { - Set-ModuleFunctions + $ModuleManifest = Get-ChildItem *.psd1 | Select-Object -Expand FullName + $ModuleName = (Split-Path $ModuleManifest -Leaf) -replace '.psd1','' + Write-Host "Building $ModuleName manifest..." try { - "Updating Module manifest '$env:BHPSModuleManifest'.." - $Version = Get-NextNugetPackageVersion -Name $env:BHProjectName -ErrorAction Stop - "Setting Version '$Version'.." - Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $Version -ErrorAction stop + $CurrentVersion = Get-Metadata -Path .\$ModuleManifest -PropertyName ModuleVersion + $NextNugetVersion = Get-NextNugetPackageVersion -Name $ModuleName -ErrorAction Stop + + if ($CurrentVersion -ne $NextNugetVersion) { + "Current '$CurrentVersion' of $ModuleName is already published to PsGallery.`n" + + "Please Bump the version in source too to '$NextNugetVersion'." | Write-Warning + Update-Metadata -Path $ModuleManifest -PropertyName ModuleVersion -Value $Version -ErrorAction stop + } } catch { - "Failed to update version for '$env:BHProjectName': $_.`nContinuing with existing version" + "Failed to update metadata for '$ModuleName': $_.`nContinuing with existing version" } }