Added module building

This commit is contained in:
KevinMarquette
2017-05-02 22:45:59 -07:00
parent de3e06bee6
commit 498d408491

View File

@@ -3,7 +3,7 @@
Properties { Properties {
# Find the build folder based on build system # Find the build folder based on build system
$ProjectRoot = $ENV:BHProjectPath $ProjectRoot = $ENV:BHProjectPath
if(-not $ProjectRoot) if (-not $ProjectRoot)
{ {
$ProjectRoot = $PSScriptRoot $ProjectRoot = $PSScriptRoot
} }
@@ -14,7 +14,7 @@ Properties {
$lines = '----------------------------------------------------------------------' $lines = '----------------------------------------------------------------------'
$Verbose = @{} $Verbose = @{}
if($ENV:BHCommitMessage -match "!verbose") if ( $ENV:BHCommitMessage -match "!verbose" )
{ {
$Verbose = @{Verbose = $True} $Verbose = @{Verbose = $True}
} }
@@ -35,7 +35,7 @@ Task UnitTests -Depends Init {
'Running quick unit tests to fail early if there is an error' 'Running quick unit tests to fail early if there is an error'
$TestResults = Invoke-Pester -Path $ProjectRoot\Tests\*unit* -PassThru -Tag Build $TestResults = Invoke-Pester -Path $ProjectRoot\Tests\*unit* -PassThru -Tag Build
if($TestResults.FailedCount -gt 0) if ( $TestResults.FailedCount -gt 0 )
{ {
Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed" Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed"
} }
@@ -50,11 +50,11 @@ Task Test -Depends UnitTests {
$TestResults = Invoke-Pester -Path $ProjectRoot\Tests -PassThru -OutputFormat NUnitXml -OutputFile "$ProjectRoot\$TestFile" -Tag Build $TestResults = Invoke-Pester -Path $ProjectRoot\Tests -PassThru -OutputFormat NUnitXml -OutputFile "$ProjectRoot\$TestFile" -Tag Build
# In Appveyor? Upload our tests! #Abstract this into a function? # In Appveyor? Upload our tests! #Abstract this into a function?
If($ENV:BHBuildSystem -eq 'AppVeyor') If ( $ENV:BHBuildSystem -eq 'AppVeyor' )
{ {
[xml]$content = Get-Content "$ProjectRoot\$TestFile" [xml]$content = Get-Content "$ProjectRoot\$TestFile"
$content.'test-results'.'test-suite'.type = "Powershell" $content.'test-results'.'test-suite'.type = "Powershell"
$content.Save("$ProjectRoot\$TestFile") $content.Save( "$ProjectRoot\$TestFile" )
"Uploading $ProjectRoot\$TestFile to AppVeyor" "Uploading $ProjectRoot\$TestFile to AppVeyor"
"JobID: $env:APPVEYOR_JOB_ID" "JobID: $env:APPVEYOR_JOB_ID"
@@ -65,7 +65,7 @@ Task Test -Depends UnitTests {
# Failed tests? # Failed tests?
# Need to tell psake or it will proceed to the deployment. Danger! # Need to tell psake or it will proceed to the deployment. Danger!
if($TestResults.FailedCount -gt 0) if ( $TestResults.FailedCount -gt 0 )
{ {
Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed" Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed"
} }
@@ -76,7 +76,7 @@ Task Build -Depends Test {
$lines $lines
$functions = Get-ChildItem "$PSScriptRoot\$env:BHProjectName\Public\*.ps1" | $functions = Get-ChildItem "$PSScriptRoot\$env:BHProjectName\Public\*.ps1" |
Where-Object{ $_.name -notmatch 'Tests'} | Where-Object { $_.name -notmatch 'Tests'} |
Select-Object -ExpandProperty basename Select-Object -ExpandProperty basename
# Load the module, read the exported functions, update the psd1 FunctionsToExport # Load the module, read the exported functions, update the psd1 FunctionsToExport
@@ -85,21 +85,46 @@ Task Build -Depends Test {
# Bump the module version # Bump the module version
$version = [version] (Step-Version (Get-Metadata -Path $env:BHPSModuleManifest)) $version = [version] (Step-Version (Get-Metadata -Path $env:BHPSModuleManifest))
$galleryVersion = Get-NextPSGalleryVersion -Name $env:BHProjectName $galleryVersion = Get-NextPSGalleryVersion -Name $env:BHProjectName
if($version -lt $galleryVersion) if ( $version -lt $galleryVersion )
{ {
$version = $galleryVersion $version = $galleryVersion
} }
$version = [version]::New($version.Major,$version.Minor,$version.Build,$env:BHBuildNumber) $version = [version]::New($version.Major, $version.Minor, $version.Build, $env:BHBuildNumber)
Write-Host "Using version: $version" Write-Host "Using version: $version"
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $version Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $version
$psm1 = "$PSScriptRoot\$env:BHProjectName\$env:BHProjectName.psm1"
Remove-Item $psm1
# keep the first line in the psm1 file and clear the rest
Get-Content -Path $psm1 -TotalCount 1 | Set-Content -Path $psm1
foreach ( $folder in ('Classes', 'Public', 'Private') )
{
Add-Content -Path $psm1 -Value "Write-Verbose 'Importing from [$folder]'"
$imports = Get-ChildItem "$PSScriptRoot\$env:BHProjectName\$folder\*.ps1" -Exclude *.Tests.ps1
foreach ( $file in $imports )
{
Add-Content -Path $psm1 -Value ''
Add-Content -Path $psm1 -Value "Write-Verbose ' Source [\$folder\$($file.name)]'"
[System.IO.File]::ReadAllText($file.fullname) | Add-Content -Path $psm1
}
# Remove folders after import
Remove-Item "$PSScriptRoot\$env:BHProjectName\$folder" -Recurse
}
# Add exports
Add-Content -Path $psm1 -Value "Export-ModuleMember -Function $($functions -join ', ')"
Import-Module $psm1 -Force
} }
Task Deploy -Depends Build { Task Deploy -Depends Build {
$lines $lines
# Gate deployment # Gate deployment
if( if (
$ENV:BHBuildSystem -ne 'Unknown' -and $ENV:BHBuildSystem -ne 'Unknown' -and
$ENV:BHBranchName -eq "master" -and $ENV:BHBranchName -eq "master" -and
$ENV:BHCommitMessage -match '!deploy' $ENV:BHCommitMessage -match '!deploy'