-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpsake.ps1
74 lines (58 loc) · 2.22 KB
/
psake.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Adopted from https://github.com/RamblingCookieMonster/PSDeploy
Properties {
# Find the build folder based on build system
$ProjectRoot = $ENV:BHProjectPath
if (-not $ProjectRoot) {
$ProjectRoot = $PSScriptRoot
}
$Timestamp = Get-date -uformat "%Y%m%d-%H%M%S"
$PSVersion = $PSVersionTable.PSVersion.Major
$TestFile = "TestResults_PS$PSVersion`_$TimeStamp.xml"
$lines = '----------------------------------------------------------------------'
$Verbose = @{}
if ($ENV:BHCommitMessage -match "!verbose") {
$Verbose = @{Verbose = $True}
}
}
Task Default -Depends Deploy
Task Init {
Remove-item $ProjectRoot\TestResults* -Force
$lines
Set-Location $ProjectRoot
"Build System Details:"
Get-Item ENV:BH*
"`n"
}
Task Test -Depends Init {
$lines
"`n`tSTATUS: Testing with PowerShell $PSVersion"
Invoke-ScriptAnalyzer -Path $ENV:BHPSModulePath -Settings PSGallery -Recurse
$lines
$sourcefiles = (Get-ChildItem -Path $ENV:BHPSModulePath\*.ps1 -Recurse).FullName
$TestResults = Invoke-Pester -Path $ProjectRoot\Tests -PassThru -OutputFormat NUnitXml -CodeCoverage $sourcefiles -OutputFile "$ProjectRoot\$TestFile"
If ($ENV:BHBuildSystem -eq 'Teamcity') {
Write-Output "##teamcity[importData type='nunit' path='$ProjectRoot\$TestFile']"
Write-Output "##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='$($testResults.CodeCoverage.NumberOfCommandsAnalyzed)']"
Write-Output "##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='$($testResults.CodeCoverage.NumberOfCommandsExecuted)']"
}
if ($TestResults.FailedCount -gt 0) {
Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed"
}
"`n"
}
Task Build -Depends Test {
$lines
# Load the module, read the exported functions, update the psd1 FunctionsToExport
Set-ModuleFunctions
# Bump the module version
Update-Metadata -Path $env:BHPSModuleManifest
}
Task Deploy -Depends Build {
$lines
$Params = @{
Path = $ProjectRoot
Force = $true
Recurse = $false
}
Invoke-PSDeploy @Verbose @Params
}