Added module building
This commit is contained in:
67
psake.ps1
67
psake.ps1
@@ -2,11 +2,11 @@
|
|||||||
# Init some things
|
# Init some things
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
$Timestamp = Get-date -uformat "%Y%m%d-%H%M%S"
|
$Timestamp = Get-date -uformat "%Y%m%d-%H%M%S"
|
||||||
$PSVersion = $PSVersionTable.PSVersion.Major
|
$PSVersion = $PSVersionTable.PSVersion.Major
|
||||||
@@ -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,14 +35,14 @@ 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"
|
||||||
}
|
}
|
||||||
"`n"
|
"`n"
|
||||||
}
|
}
|
||||||
|
|
||||||
Task Test -Depends UnitTests {
|
Task Test -Depends UnitTests {
|
||||||
$lines
|
$lines
|
||||||
"`n`tSTATUS: Testing with PowerShell $PSVersion"
|
"`n`tSTATUS: Testing with PowerShell $PSVersion"
|
||||||
|
|
||||||
@@ -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,8 +76,8 @@ 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
|
||||||
Set-ModuleFunctions -Name $env:BHPSModuleManifest -FunctionsToExport $functions
|
Set-ModuleFunctions -Name $env:BHPSModuleManifest -FunctionsToExport $functions
|
||||||
@@ -85,23 +85,48 @@ 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'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -114,9 +139,9 @@ Task Deploy -Depends Build {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
"Skipping deployment: To deploy, ensure that...`n" +
|
"Skipping deployment: To deploy, ensure that...`n" +
|
||||||
"`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" +
|
"`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" +
|
||||||
"`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" +
|
"`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" +
|
||||||
"`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage)"
|
"`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user