-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvokeBuild.ps1
97 lines (79 loc) · 2.42 KB
/
InvokeBuild.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ProjectBuilder.ProjectInfo] $ProjectInfo
)
task Clean {
$ProjectInfo.CleanRelease()
}
task BuildDocs {
$helpParams = $ProjectInfo.Documentation.GetParams()
$null = New-ExternalHelp @helpParams
}
task BuildManaged {
$arguments = $ProjectInfo.GetBuildArgs()
Push-Location -LiteralPath $ProjectInfo.Project.Source.FullName
try {
foreach ($framework in $ProjectInfo.Project.TargetFrameworks) {
Write-Host "Compiling for $framework"
dotnet @arguments --framework $framework
if ($LASTEXITCODE) {
throw "Failed to compiled code for $framework"
}
}
}
finally {
Pop-Location
}
}
task CopyToRelease {
$ProjectInfo.Module.CopyToRelease()
$ProjectInfo.Project.CopyToRelease()
}
task Package {
$ProjectInfo.Project.ClearNugetPackage()
$repoParams = $ProjectInfo.Project.GetPSRepoParams()
if (Get-PSRepository -Name $repoParams.Name -ErrorAction SilentlyContinue) {
Unregister-PSRepository -Name $repoParams.Name
}
Register-PSRepository @repoParams
try {
$publishModuleSplat = @{
Path = $ProjectInfo.Project.Release
Repository = $repoParams.Name
}
Publish-Module @publishModuleSplat
}
finally {
Unregister-PSRepository -Name $repoParams.Name
}
}
task Analyze {
if (-not $ProjectInfo.AnalyzerPath) {
Write-Host 'No Analyzer Settings found, skipping'
return
}
$pssaSplat = $ProjectInfo.GetAnalyzerParams()
$results = Invoke-ScriptAnalyzer @pssaSplat
if ($results) {
$results | Out-String
throw 'Failed PsScriptAnalyzer tests, build failed'
}
}
task PesterTests {
if (-not $ProjectInfo.Pester.PesterScript) {
Write-Host 'No Pester tests found, skipping'
return
}
$ProjectInfo.Pester.ClearResultFile()
if (-not (dotnet tool list --global | Select-String coverlet.console -SimpleMatch)) {
Write-Host 'Installing dotnet tool coverlet.console' -ForegroundColor Yellow
dotnet tool install --global coverlet.console
}
coverlet $ProjectInfo.Pester.GetTestArgs($PSVersionTable.PSVersion)
if ($LASTEXITCODE) {
throw 'Pester failed tests'
}
}
task Build -Jobs Clean, BuildManaged, CopyToRelease, BuildDocs, Package
task Test -Jobs BuildManaged, Analyze, PesterTests