-
Notifications
You must be signed in to change notification settings - Fork 2
/
AzureADLicensing.build.ps1
67 lines (55 loc) · 2.88 KB
/
AzureADLicensing.build.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
#Requires -Modules @{ModuleName='InvokeBuild';ModuleVersion='3.2.1'}
#Requires -Modules @{ModuleName='PowerShellGet';ModuleVersion='1.6.0'}
#Requires -Modules @{ModuleName='Pester';ModuleVersion='4.1.1'}
#Requires -Modules @{ModuleName='ModuleBuilder';ModuleVersion='1.0.0'}
$Script:IsAppveyor = $null -ne $env:APPVEYOR
$Script:ModuleName = Get-Item -Path $BuildRoot | Select-Object -ExpandProperty Name
Get-Module -Name $ModuleName | Remove-Module -Force
task Clean {
Remove-Item -Path ".\Bin" -Recurse -Force -ErrorAction SilentlyContinue
}
task TestCode {
Write-Build Yellow "`n`n`nTesting dev code before build"
$TestResult = Invoke-Pester -Script "$PSScriptRoot\Test\Unit" -Tag Unit -Show 'Header','Summary' -PassThru
if($TestResult.FailedCount -gt 0) {throw 'Tests failed'}
}
task CompilePSM {
Write-Build Yellow "`n`n`nCompiling all code into single psm1"
try {
$BuildParams = @{}
if((Get-Command -ErrorAction stop -Name gitversion)) {
$GitVersion = gitversion | ConvertFrom-Json | Select-Object -Expand FullSemVer
$GitVersion = gitversion | ConvertFrom-Json | Select-Object -Expand InformationalVersion
$BuildParams['SemVer'] = $GitVersion
}
}
catch{
Write-Warning -Message 'gitversion not found, keeping current version'
}
Push-Location -Path "$BuildRoot\Source" -StackName 'InvokeBuildTask'
$Script:CompileResult = Build-Module @BuildParams -Passthru
Get-ChildItem -Path "$BuildRoot\license*" | Copy-Item -Destination $Script:CompileResult.ModuleBase
Pop-Location -StackName 'InvokeBuildTask'
}
task MakeHelp -if (Test-Path -Path "$PSScriptRoot\Docs") {
}
task TestBuild {
Write-Build Yellow "`n`n`nTesting compiled module"
$Script = @{Path="$PSScriptRoot\test\Unit"; Parameters=@{ModulePath=$Script:CompileResult.ModuleBase}}
$CodeCoverage = (Get-ChildItem -Path $Script:CompileResult.ModuleBase -Filter *.psm1).FullName
$TestResult = Invoke-Pester -Script $Script -CodeCoverage $CodeCoverage -Show None -PassThru
if($TestResult.FailedCount -gt 0) {
Write-Warning -Message "Failing Tests:"
$TestResult.TestResult.Where{$_.Result -eq 'Failed'} | ForEach-Object -Process {
Write-Warning -Message $_.Name
Write-Verbose -Message $_.FailureMessage -Verbose
}
throw 'Tests failed'
}
# $CodeCoverageResult = $TestResult | Convert-CodeCoverage -SourceRoot "$PSScriptRoot\Source" -Relative
# $CodeCoveragePercent = $TestResult.CodeCoverage.NumberOfCommandsExecuted/$TestResult.CodeCoverage.NumberOfCommandsAnalyzed*100 -as [int]
# Write-Verbose -Message "CodeCoverage is $CodeCoveragePercent%" -Verbose
# $CodeCoverageResult | Group-Object -Property SourceFile | Sort-Object -Property Count | Select-Object -Property Count, Name -Last 10
}
task . Clean, TestCode, Build
task Build CompilePSM, MakeHelp, TestBuild