Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit 17e69af

Browse files
authored
!Deploy - Merge to master to deploy 0.1.0
!Deploy - Merge to master to deploy 0.1.0
2 parents ec91ae8 + 047d96d commit 17e69af

File tree

91 files changed

+3525
-1347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3525
-1347
lines changed

.build.ps1

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Param (
2+
[string]
3+
$BuildOutput = (property BuildOutput 'BuildOutput'),
4+
5+
[string]
6+
$ProjectName = (property ProjectName (Split-Path -Leaf $BuildRoot) ),
7+
8+
[string]
9+
$PesterOutputFormat = (property PesterOutputFormat 'NUnitXml'),
10+
11+
[string]
12+
$APPVEYOR_JOB_ID = $(try {property APPVEYOR_JOB_ID} catch {})
13+
)
14+
15+
# Synopsis: Uploading Unit Test results to AppVeyor
16+
task Upload_Unit_Test_Results_To_AppVeyor -If {(property BuildSystem 'unknown') -eq 'AppVeyor'} {
17+
18+
if (![io.path]::IsPathRooted($BuildOutput)) {
19+
$BuildOutput = Join-Path -Path $BuildRoot -ChildPath $BuildOutput
20+
}
21+
22+
$TestOutputPath = [system.io.path]::Combine($BuildOutput,'testResults','unit',$PesterOutputFormat)
23+
$TestResultFiles = Get-ChildItem -Path $TestOutputPath -Filter *.xml
24+
Write-Build Green " Uploading test results [$($TestResultFiles.Name -join ', ')] to Appveyor"
25+
$TestResultFiles | Add-TestResultToAppveyor
26+
Write-Build Green " Upload Complete"
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Param (
2+
[string]
3+
$BuildOutput = (property BuildOutput 'BuildOutput')
4+
)
5+
6+
# Removes the BuildOutput\modules (errors if Pester is loaded)
7+
task CleanAll Clean,CleanModule
8+
9+
# Synopsis: Deleting the content of the Build Output folder, except ./modules
10+
task Clean {
11+
if (![io.path]::IsPathRooted($BuildOutput)) {
12+
$BuildOutput = Join-Path -Path $BuildRoot -ChildPath $BuildOutput
13+
}
14+
15+
if (Test-Path $BuildOutput) {
16+
Write-Build -Color Green "Removing $BuildOutput\* excluding modules"
17+
Get-ChildItem $BuildOutput -Exclude modules | Remove-Item -Force -Recurse
18+
}
19+
}
20+
21+
# Synopsis: Removes the Modules from BuildOutput\Modules folder, might fail if there's an handle on one file.
22+
task CleanModule {
23+
if (![io.path]::IsPathRooted($BuildOutput)) {
24+
$BuildOutput = Join-Path -Path $BuildRoot -ChildPath $BuildOutput
25+
}
26+
Write-Build -Color Green "Removing $BuildOutput\*"
27+
Get-ChildItem $BuildOutput | Remove-Item -Force -Recurse -Verbose -ErrorAction Stop
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Param (
2+
[string]
3+
$VariableNamePrefix = $(try {property VariableNamePrefix} catch {''}),
4+
5+
[switch]
6+
$ForceEnvironmentVariables = $(try {property ForceEnvironmentVariables} catch {$false})
7+
)
8+
9+
# Synopsis: Using Build Helpers to Set default environment variables
10+
task Set_Build_Environment_Variables {
11+
$BH_Params = @{
12+
variableNamePrefix = $VariableNamePrefix
13+
ErrorVariable = 'err'
14+
ErrorAction = 'SilentlyContinue'
15+
Force = $ForceEnvironmentVariables
16+
Verbose = $verbose
17+
}
18+
19+
Set-BuildEnvironment @BH_Params
20+
foreach ($e in $err) {
21+
Write-Build Red $e
22+
}
23+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function Update-DscResourceFromObjectMetadata {
2+
[CmdletBinding()]
3+
Param(
4+
[Parameter(ValueFromPipelineByPropertyName)]
5+
[io.DirectoryInfo]$SourceFolder,
6+
7+
[PSCustomObject]
8+
$DscResourceMetadata = (Get-Content -Raw "$((Resolve-Path $SourceFolder).Path)\DscResources\DSCResourcesDefinitions.json"| ConvertFrom-Json)
9+
)
10+
11+
if (![io.path]::IsPathRooted($SourceFolder)) {
12+
$SourceFolder = (Resolve-Path $SourceFolder).Path
13+
}
14+
foreach ($Resource in $DscResourceMetadata)
15+
{
16+
$DscProperties = @()
17+
$ResourceName = $Resource.psobject.Properties.Name
18+
Write-Verbose "Preparing $ResourceName"
19+
foreach ($DscProperty in $Resource.($ResourceName)) {
20+
$resourceParams = @{}
21+
$DscProperty.psobject.properties | % { $resourceParams[$_.Name] = $_.value }
22+
$DscProperties += New-xDscResourceProperty @resourceParams
23+
}
24+
25+
if (Test-Path "$SourceFolder\DscResources\$ResourceName") {
26+
$DscResourceParams = @{
27+
Property = $DscProperties
28+
Path = "$SourceFolder\DscResources\$ResourceName"
29+
FriendlyName = $ResourceName
30+
}
31+
Update-xDscResource @DscResourceParams -Force
32+
}
33+
else {
34+
$DscResourceParams = @{
35+
Name = $ResourceName
36+
Property = $DscProperties
37+
Path = "$SourceFolder\"
38+
FriendlyName = $ResourceName
39+
}
40+
New-xDscResource @DscResourceParams
41+
}
42+
}
43+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Param (
2+
3+
[io.DirectoryInfo]
4+
$ProjectPath = (property ProjectPath (Join-Path $PSScriptRoot '../..' -Resolve -ErrorAction SilentlyContinue)),
5+
6+
[string]
7+
$ProjectName = (property ProjectName (Split-Path -Leaf (Join-Path $PSScriptRoot '../..')) ),
8+
9+
[string]
10+
$LineSeparation = (property LineSeparation ('-' * 78))
11+
)
12+
13+
task UpdateDscResource {
14+
$LineSeparation
15+
"`t`t`t UPDATING DSC SCRIPT RESOURCE SCHEMAS"
16+
$LineSeparation
17+
. $PSScriptRoot\Update-DscResourceFromDefinition.ps1
18+
19+
$SourceFolder = Join-Path -Path $ProjectPath.FullName -ChildPath $ProjectName
20+
21+
if (Test-Path $SourceFolder) {
22+
Update-DscResourceFromObjectMetadata -SourceFolder $SourceFolder
23+
}
24+
}
25+
26+
task updateDscSchema UpdateDscResource
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Param (
2+
[string]
3+
$BuildOutput = (property BuildOutput 'BuildOutput'),
4+
5+
[string]
6+
$ProjectName = (property ProjectName (Split-Path -Leaf $BuildRoot) ),
7+
8+
[string]
9+
$PesterOutputFormat = (property PesterOutputFormat 'NUnitXml'),
10+
11+
[string]
12+
$APPVEYOR_JOB_ID = $(try {property APPVEYOR_JOB_ID} catch {}),
13+
14+
$DeploymentTags = $(try {property DeploymentTags} catch {}),
15+
16+
$DeployConfig = (property DeployConfig 'Deploy.PSDeploy.ps1')
17+
)
18+
19+
# Synopsis: Deploy everything configured in PSDeploy
20+
task Deploy_with_PSDeploy {
21+
22+
if (![io.path]::IsPathRooted($BuildOutput)) {
23+
$BuildOutput = Join-Path -Path $BuildRoot -ChildPath $BuildOutput
24+
}
25+
26+
$DeployFile = [io.path]::Combine($BuildRoot, $DeployConfig)
27+
28+
"Deploying Module based on $DeployConfig config"
29+
30+
$InvokePSDeployArgs = @{
31+
Path = $DeployFile
32+
Force = $true
33+
}
34+
35+
if($DeploymentTags) {
36+
$null = $InvokePSDeployArgs.Add('Tags',$DeploymentTags)
37+
}
38+
39+
Import-Module PSDeploy
40+
Invoke-PSDeploy @InvokePSDeployArgs
41+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Param (
2+
[string]
3+
$ProjectName = (property ProjectName (Split-Path -Leaf $BuildRoot) ),
4+
5+
[string]
6+
$RelativePathToIntegrationTests = (property RelativePathToIntegrationTests 'tests/Integration')
7+
)
8+
9+
# Synopsis: Running the Integration tests if present
10+
task IntegrationTests {
11+
"`tProject Path = $BuildRoot"
12+
"`tProject Name = $ProjectName"
13+
"`tIntegration Tests = $RelativePathToIntegrationTests"
14+
$IntegrationTestPath = [io.DirectoryInfo][system.io.path]::Combine($BuildRoot,$ProjectName,$RelativePathToIntegrationTests)
15+
"`tIntegration Tests = $IntegrationTestPath"
16+
17+
if (!$IntegrationTestPath.Exists -and
18+
( #Try a module structure where the
19+
($IntegrationTestPath = [io.DirectoryInfo][system.io.path]::Combine($BuildRoot,$RelativePathToIntegrationTests)) -and
20+
!$IntegrationTestPath.Exists
21+
)
22+
)
23+
{
24+
Write-Warning ("`t>> Integration tests Path Not found {0}" -f $IntegrationTestPath)
25+
}
26+
else {
27+
"`tIntegrationTest Path: $IntegrationTestPath"
28+
''
29+
Push-Location $IntegrationTestPath
30+
31+
Import-module Pester -ErrorAction Stop
32+
Invoke-Pester -ErrorAction Stop
33+
34+
Pop-Location
35+
}
36+
37+
}

0 commit comments

Comments
 (0)