|
| 1 | +[cmdletBinding()] |
| 2 | +Param ( |
| 3 | + [Parameter(Position=0)] |
| 4 | + $Tasks, |
| 5 | + |
| 6 | + [switch] |
| 7 | + $ResolveDependency, |
| 8 | + |
| 9 | + [String] |
| 10 | + $BuildOutput = "BuildOutput", |
| 11 | + |
| 12 | + [String[]] |
| 13 | + $GalleryRepository, |
| 14 | + |
| 15 | + [Uri] |
| 16 | + $GalleryProxy, |
| 17 | + |
| 18 | + [Switch] |
| 19 | + $ForceEnvironmentVariables = [switch]$true, |
| 20 | + |
| 21 | + $MergeList = @('enum*',[PSCustomObject]@{Name='class*';order={(Import-PowerShellDataFile -EA 0 .\*\Classes\classes.psd1).order.indexOf($_.BaseName)}},'priv*','pub*') |
| 22 | + |
| 23 | + ,$TaskHeader = { |
| 24 | + param($Path) |
| 25 | + '' |
| 26 | + '=' * 79 |
| 27 | + Write-Build Cyan "`t`t`t$($Task.Name.replace('_',' ').ToUpper())" |
| 28 | + Write-Build DarkGray "$(Get-BuildSynopsis $Task)" |
| 29 | + '-' * 79 |
| 30 | + Write-Build DarkGray " $Path" |
| 31 | + Write-Build DarkGray " $($Task.InvocationInfo.ScriptName):$($Task.InvocationInfo.ScriptLineNumber)" |
| 32 | + '' |
| 33 | + } |
| 34 | + |
| 35 | + ,$CodeCoverageThreshold = 0 |
| 36 | +) |
| 37 | + |
| 38 | +Process { |
| 39 | + if ($MyInvocation.ScriptName -notlike '*Invoke-Build.ps1') { |
| 40 | + if ($PSboundParameters.ContainsKey('ResolveDependency')) { |
| 41 | + Write-Verbose "Dependency already resolved. Handing over to InvokeBuild." |
| 42 | + $null = $PSboundParameters.Remove('ResolveDependency') |
| 43 | + } |
| 44 | + Invoke-Build $Tasks $MyInvocation.MyCommand.Path @PSBoundParameters |
| 45 | + return |
| 46 | + } |
| 47 | + |
| 48 | + # Loading Build Tasks defined in the .build/ folder |
| 49 | + Get-ChildItem -Path "$PSScriptRoot/.build/" -Recurse -Include *.ps1 -Verbose | |
| 50 | + Foreach-Object { |
| 51 | + "Importing file $($_.BaseName)" | Write-Verbose |
| 52 | + . $_.FullName |
| 53 | + } |
| 54 | + |
| 55 | + # Defining the task header for this Build Job |
| 56 | + if($TaskHeader) { Set-BuildHeader $TaskHeader } |
| 57 | + |
| 58 | + # Defining the Default task 'workflow' when invoked without -tasks parameter |
| 59 | + task . Clean, |
| 60 | + Set_Build_Environment_Variables, |
| 61 | + #Pester_Quality_Tests_Stop_On_Fail, |
| 62 | + Copy_Source_To_Module_BuildOutput, |
| 63 | + Merge_Source_Files_To_PSM1, |
| 64 | + Clean_Empty_Folders_from_Build_Output, |
| 65 | + Update_Module_Manifest, |
| 66 | + Run_Unit_Tests, |
| 67 | + #Upload_Unit_Test_Results_To_AppVeyor, |
| 68 | + Fail_Build_if_Unit_Test_Failed, |
| 69 | + Fail_if_Last_Code_Converage_is_Under_Threshold, |
| 70 | + IntegrationTests, |
| 71 | + Deploy_with_PSDeploy |
| 72 | + |
| 73 | + # Define a testAll tasks for interactive testing |
| 74 | + task testAll UnitTests, IntegrationTests, QualityTestsStopOnFail |
| 75 | + |
| 76 | + # Define a dummy task when you don't want any task executed (e.g. Only load PSModulePath) |
| 77 | + task Noop {} |
| 78 | + |
| 79 | +} |
| 80 | + |
| 81 | + |
| 82 | +begin { |
| 83 | + function Resolve-Dependency { |
| 84 | + [CmdletBinding()] |
| 85 | + param() |
| 86 | + |
| 87 | + if (!(Get-PackageProvider -Name NuGet -ForceBootstrap)) { |
| 88 | + $providerBootstrapParams = @{ |
| 89 | + Name = 'nuget' |
| 90 | + force = $true |
| 91 | + ForceBootstrap = $true |
| 92 | + } |
| 93 | + if($PSBoundParameters.ContainsKey('verbose')) { $providerBootstrapParams.add('verbose',$verbose)} |
| 94 | + if ($GalleryProxy) { $providerBootstrapParams.Add('Proxy',$GalleryProxy) } |
| 95 | + $null = Install-PackageProvider @providerBootstrapParams |
| 96 | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted |
| 97 | + } |
| 98 | + |
| 99 | + if (!(Get-Module -Listavailable PSDepend)) { |
| 100 | + Write-verbose "BootStrapping PSDepend" |
| 101 | + "Parameter $BuildOutput"| Write-verbose |
| 102 | + $InstallPSDependParams = @{ |
| 103 | + Name = 'PSDepend' |
| 104 | + AllowClobber = $true |
| 105 | + Confirm = $false |
| 106 | + Force = $true |
| 107 | + Scope = 'CurrentUser' |
| 108 | + } |
| 109 | + if($PSBoundParameters.ContainsKey('verbose')) { $InstallPSDependParams.add('verbose',$verbose)} |
| 110 | + if ($GalleryRepository) { $InstallPSDependParams.Add('Repository',$GalleryRepository) } |
| 111 | + if ($GalleryProxy) { $InstallPSDependParams.Add('Proxy',$GalleryProxy) } |
| 112 | + if ($GalleryCredential) { $InstallPSDependParams.Add('ProxyCredential',$GalleryCredential) } |
| 113 | + Install-Module @InstallPSDependParams |
| 114 | + } |
| 115 | + |
| 116 | + $PSDependParams = @{ |
| 117 | + Force = $true |
| 118 | + Path = "$PSScriptRoot\PSDepend.build.psd1" |
| 119 | + } |
| 120 | + if($PSBoundParameters.ContainsKey('verbose')) { $PSDependParams.add('verbose',$verbose)} |
| 121 | + Invoke-PSDepend @PSDependParams |
| 122 | + Write-Verbose "Project Bootstrapped, returning to Invoke-Build" |
| 123 | + } |
| 124 | + |
| 125 | + if (![io.path]::IsPathRooted($BuildOutput)) { |
| 126 | + $BuildOutput = Join-Path -Path $PSScriptRoot -ChildPath $BuildOutput |
| 127 | + } |
| 128 | + |
| 129 | + if(($Env:PSModulePath -split ';') -notcontains (Join-Path $BuildOutput 'modules') ) { |
| 130 | + $Env:PSModulePath = (Join-Path $BuildOutput 'modules') + ';' + $Env:PSModulePath |
| 131 | + } |
| 132 | + |
| 133 | + |
| 134 | + if ($ResolveDependency) { |
| 135 | + Write-Host "Resolving Dependencies... [this can take a moment]" |
| 136 | + $Params = @{} |
| 137 | + if ($PSboundParameters.ContainsKey('verbose')) { |
| 138 | + $Params.Add('verbose',$verbose) |
| 139 | + } |
| 140 | + Resolve-Dependency @Params |
| 141 | + } |
| 142 | +} |
0 commit comments