forked from gaelcolas/Datum.ProtectedData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.build.ps1
144 lines (119 loc) · 4.86 KB
/
.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
[cmdletBinding()]
Param (
[Parameter(Position=0)]
$Tasks,
[switch]
$ResolveDependency,
[String]
$BuildOutput = "BuildOutput",
$ProjectName = 'Datum.ProtectedData',
[String[]]
$GalleryRepository,
[Uri]
$GalleryProxy,
[Switch]
$ForceEnvironmentVariables = [switch]$true,
$MergeList = @('enum*',[PSCustomObject]@{Name='class*';order={(Import-PowerShellDataFile -EA 0 .\*\Classes\classes.psd1).order.indexOf($_.BaseName)}},'priv*','pub*')
,$TaskHeader = {
param($Path)
''
'=' * 79
Write-Build Cyan "`t`t`t$($Task.Name.replace('_',' ').ToUpper())"
Write-Build DarkGray "$(Get-BuildSynopsis $Task)"
'-' * 79
Write-Build DarkGray " $Path"
Write-Build DarkGray " $($Task.InvocationInfo.ScriptName):$($Task.InvocationInfo.ScriptLineNumber)"
''
}
,$CodeCoverageThreshold = 23
)
Process {
if ($MyInvocation.ScriptName -notlike '*Invoke-Build.ps1') {
if ($PSboundParameters.ContainsKey('ResolveDependency')) {
Write-Verbose "Dependency already resolved. Handing over to InvokeBuild."
$null = $PSboundParameters.Remove('ResolveDependency')
}
Invoke-Build $Tasks $MyInvocation.MyCommand.Path @PSBoundParameters
return
}
# Loading Build Tasks defined in the .build/ folder
Get-ChildItem -Path "$PSScriptRoot/.build/" -Recurse -Include *.ps1 -Verbose |
Foreach-Object {
"Importing file $($_.BaseName)" | Write-Verbose
. $_.FullName
}
# Defining the task header for this Build Job
if($TaskHeader) { Set-BuildHeader $TaskHeader }
# Defining the Default task 'workflow' when invoked without -tasks parameter
task . Clean,
Set_Build_Environment_Variables,
Pester_Quality_Tests_Stop_On_Fail,
Copy_Source_To_Module_BuildOutput,
Merge_Source_Files_To_PSM1,
Clean_Empty_Folders_from_Build_Output,
Update_Module_Manifest,
Run_Unit_Tests,
Upload_Unit_Test_Results_To_AppVeyor,
Fail_Build_if_Unit_Test_Failed,
Fail_if_Last_Code_Converage_is_Under_Threshold,
IntegrationTests,
Deploy_with_PSDeploy
# Define a testAll tasks for interactive testing
task testAll UnitTests, IntegrationTests, QualityTestsStopOnFail
# Define a dummy task when you don't want any task executed (e.g. Only load PSModulePath)
task Noop {}
}
begin {
function Resolve-Dependency {
[CmdletBinding()]
param()
if (!(Get-PackageProvider -Name NuGet -ForceBootstrap)) {
$providerBootstrapParams = @{
Name = 'nuget'
force = $true
ForceBootstrap = $true
}
if($PSBoundParameters.ContainsKey('verbose')) { $providerBootstrapParams.add('verbose',$verbose)}
if ($GalleryProxy) { $providerBootstrapParams.Add('Proxy',$GalleryProxy) }
$null = Install-PackageProvider @providerBootstrapParams
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
}
if (!(Get-Module -Listavailable PSDepend)) {
Write-verbose "BootStrapping PSDepend"
"Parameter $BuildOutput"| Write-verbose
$InstallPSDependParams = @{
Name = 'PSDepend'
AllowClobber = $true
Confirm = $false
Force = $true
Scope = 'CurrentUser'
}
if($PSBoundParameters.ContainsKey('verbose')) { $InstallPSDependParams.add('verbose',$verbose)}
if ($GalleryRepository) { $InstallPSDependParams.Add('Repository',$GalleryRepository) }
if ($GalleryProxy) { $InstallPSDependParams.Add('Proxy',$GalleryProxy) }
if ($GalleryCredential) { $InstallPSDependParams.Add('ProxyCredential',$GalleryCredential) }
Install-Module @InstallPSDependParams
}
$PSDependParams = @{
Force = $true
Path = "$PSScriptRoot\PSDepend.build.psd1"
}
if($PSBoundParameters.ContainsKey('verbose')) { $PSDependParams.add('verbose',$verbose)}
Invoke-PSDepend @PSDependParams
Write-Verbose "Project Bootstrapped, returning to Invoke-Build"
}
if (![io.path]::IsPathRooted($BuildOutput)) {
$BuildOutput = Join-Path -Path $PSScriptRoot -ChildPath $BuildOutput
}
if(($Env:PSModulePath -split ';') -notcontains (Join-Path $BuildOutput 'modules') ) {
$Env:PSModulePath = (Join-Path $BuildOutput 'modules') + ';' + $Env:PSModulePath
}
if ($ResolveDependency) {
Write-Host "Resolving Dependencies... [this can take a moment]"
$Params = @{}
if ($PSboundParameters.ContainsKey('verbose')) {
$Params.Add('verbose',$verbose)
}
Resolve-Dependency @Params
}
}