Skip to content

Commit 5b7bd25

Browse files
committedMar 10, 2018
added new build mechanism
Appyeyor Build test Appyeyor Build test Appyeyor Build test edit Appyeyor Build test edit Appyeyor Build test edit Appyeyor revamp Appyeyor revamp Appyeyor edit Appyeyor edit Appyeyor edit Appyeyor edit Appyeyor edit
1 parent ddaa1cb commit 5b7bd25

19 files changed

+730
-109
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin
2+
/TMP

‎Norm-ModuleTests.ps1

-98
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎PesterHelpers.psd1

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Author = 'Ryan Yates'
2727
CompanyName = 'PowerShellModules'
2828

2929
# Copyright statement for this module
30-
Copyright = '? 2016 PowerShellModules'
30+
Copyright = '2016 PowerShellModules'
3131

3232
# Description of the functionality provided by this module
3333
Description = 'PesterHelpers contains helper functions to help users move all their existing PowerShell Code in to seperate PowerShell ps1 files (for each function exported) whilst auto creating a Pester test for the exported function'
@@ -94,10 +94,10 @@ AliasesToExport = @()
9494
PrivateData = @{
9595

9696
#BlogUrl of this module
97-
BlogUrl = 'blog.kilasuit.org'
97+
BlogUrl = 'https://blog.kilasuit.org'
9898

9999
#UkPowerShellUserGroup of this module
100-
UkPowerShellUserGroup = 'www.get-psuguk.org'
100+
UkPowerShellUserGroup = 'http://www.get-psuguk.org'
101101

102102
#Twitter of this module
103103
Twitter = '@ryanyates1990'
@@ -108,7 +108,7 @@ PrivateData = @{
108108
PSData = @{
109109

110110
# Tags applied to this module. These help with module discovery in online galleries.
111-
# Tags = @()
111+
Tags = @('Desktop','Core')
112112

113113
# A URL to the license for this module.
114114
LicenseUri = 'https://github.com/PowerShellModules/PesterHelpers/License'

‎Private/Get-CommonParameter.ps1

-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
function Get-CommonParameter {
2-
3-
42
<#
53
.SYNOPSIS
64
Helper Function to get all Common Parameters
@@ -14,8 +12,5 @@
1412
[cmdletbinding(SupportsShouldProcess=$true)]
1513
param()
1614
if ($PSCmdlet.ShouldProcess($null,$null)) { }
17-
18-
19-
2015
}
2116

‎Public/Export/Tests/Export-Function.Functional.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474

7575

76-
It "Mocked everything correctly" { Assert-VerifiableMocks }
76+
It "Mocked everything correctly" { Assert-VerifiableMock }
7777

7878

7979
}

‎Public/New/Tests/New-FunctionPesterTest.Functional.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ It 'Has a parameter called OutPath' {
9292

9393

9494

95-
It "Mocked everything correctly" { Assert-VerifiableMocks }
95+
It "Mocked everything correctly" { Assert-VerifiableMock }
9696

9797

9898

‎Scripts/init.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#PesterHelpers

‎appveyor.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Custom Appveyor settings
2+
environment:
3+
matrix:
4+
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
5+
PowerShellEdition: Desktop
6+
Test: Full
7+
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
8+
PowerShellEdition: Core
9+
Test: Full
10+
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
11+
PowerShellEdition: Desktop
12+
Test: Norm
13+
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
14+
PowerShellEdition: Core
15+
Test: Norm
16+
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
17+
PowerShellEdition: Desktop
18+
Test: Min
19+
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
20+
PowerShellEdition: Core
21+
Test: Min
22+
23+
matrix:
24+
# immediately finish build on failure
25+
fast_finish: true
26+
27+
# Scripts that run after cloning
28+
install:
29+
- ps: Install-Module -Name InvokeBuild, PowerShellGet, Pester, PSScriptAnalyzer -SkipPublisherCheck -Force
30+
build_script:
31+
- ps: |
32+
$ErrorActionPreference = 'Stop'
33+
$buildScript = ".\build.ps1"
34+
Invoke-Build -File $buildScript
35+
#Compress-Archive -Path ".\bin\PesterHelpers\" -DestinationPath ".\PesterHelpers.zip"
36+
#Push-AppveyorArtifact ".\PesterHelpers.zip"

‎build.full.ps1

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#Requires -Modules @{ModuleName='InvokeBuild';ModuleVersion='3.2.1'}
2+
#Requires -Modules @{ModuleName='PowerShellGet';ModuleVersion='1.6.0'}
3+
#Requires -Modules @{ModuleName='Pester';ModuleVersion='4.1.1'}
4+
5+
$Script:IsAppveyor = $env:APPVEYOR -ne $null
6+
$Script:ModuleName = Get-Item -Path $BuildRoot | Select-Object -ExpandProperty Name
7+
Get-Module -Name $ModuleName,'helpers' | Remove-Module -Force
8+
Import-Module "$BuildRoot\buildhelpers\helpers.psm1"
9+
#$tests = Get-ChildItem .\Pr*\*,.\Pu*\* -Recurse | Where-Object Name -Match Tests.ps1
10+
11+
12+
#region Setup
13+
14+
$Private = Get-ChildItem .\Private\* -Recurse |
15+
Where-Object {$_.PSIsContainer -ne $true -and $_.Name -notmatch 'Tests.ps1'}
16+
17+
18+
$Public = Get-ChildItem .\Public\* -Recurse |
19+
Where-Object {$_.PSIsContainer -ne $true -and $_.Name -notmatch 'Tests.ps1'}
20+
21+
22+
#endregion
23+
24+
25+
task Clean {
26+
Remove-Item -Path ".\Bin" -Recurse -Force -ErrorAction SilentlyContinue
27+
}
28+
29+
task TestCode {
30+
Write-Build Yellow "`n`n`nTesting dev code before build"
31+
$TestResult = Invoke-Pester -Script $BuildRoot\$($env:standardname).full.tests.ps1 -PassThru
32+
if($TestResult.FailedCount -gt 0) {throw 'Tests failed'}
33+
}
34+
35+
task CopyFiles {
36+
$null = New-Item -Path "$BuildRoot\bin\$ModuleName" -ItemType Directory
37+
Copy-Item -Path "$BuildRoot\*.psd1" -Destination "$BuildRoot\bin\$ModuleName"
38+
Get-ChildItem -Path "$BuildRoot\license*" | Copy-Item -Destination "$BuildRoot\bin\$ModuleName"
39+
}
40+
41+
task CompilePSM {
42+
$PrivatePath = '{0}\Private\*.ps1' -f $BuildRoot
43+
$PublicPath = '{0}\Public\*.ps1'-f $BuildRoot
44+
$ScriptPath = '{0}\Script\*.ps1'-f $BuildRoot
45+
Merge-ModuleFiles -Path $ScriptPath,$PrivatePath,$PublicPath -OutputPath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1"
46+
47+
$PublicScriptBlock = Get-ScriptBlockFromFile -Path $PublicPath
48+
$PublicFunctions = Get-FunctionFromScriptblock -ScriptBlock $PublicScriptBlock
49+
$PublicAlias = Get-AliasFromScriptblock -ScriptBlock $PublicScriptBlock
50+
$PublicFunctionParam, $PublicAliasParam = ''
51+
$UpdateManifestParam = @{}
52+
if(-Not [String]::IsNullOrEmpty($PublicFunctions)) {
53+
$PublicFunctionParam = "-Function '{0}'" -f ($PublicFunctions -join "','")
54+
$UpdateManifestParam['FunctionsToExport'] = $PublicFunctions
55+
}
56+
if($PublicAlias) {
57+
$PublicAliasParam = "-Alias '{0}'" -f ($PublicAlias -join "','")
58+
$UpdateManifestParam['AliasesToExport'] = $PublicAlias
59+
}
60+
$ExportStrings = 'Export-ModuleMember',$PublicFunctionParam,$PublicAliasParam | Where-Object {-Not [string]::IsNullOrWhiteSpace($_)}
61+
$ExportStrings -join ' ' | Out-File -FilePath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1" -Append -Encoding UTF8
62+
63+
# If we have git and gitversion installed, let's use it to get new module version and Release Notes
64+
if ($(try{Get-Command -Name gitversion -ErrorAction Stop}catch{})) {
65+
$gitversion = gitversion | ConvertFrom-Json
66+
if ($gitversion.CommitsSinceVersionSource -gt 0) {
67+
# Prerelease, raise minor-version by 1 and add prerelease string.
68+
$UpdateManifestParam['ModuleVersion'] = '{0}.{1}.{2}' -f $gitversion.Major, ($gitversion.Minor), $gitversion.Patch
69+
$UpdateManifestParam['Prerelease'] = '-beta{0}' -f $gitversion.CommitsSinceVersionSourcePadded
70+
}
71+
else {
72+
# This is a release version
73+
# If there is a tag pointing at HEAD, use that as release notes
74+
$UpdateManifestParam['ModuleVersion'] = $gitversion.MajorMinorPatch
75+
if ($(try{Get-Command -Name git -ErrorAction Stop}catch{})) {
76+
if($CurrentTag = git tag --points-at HEAD) {
77+
$ReleaseNotes = git tag -l -n20 $CurrentTag | Select-Object -Skip 1
78+
$UpdateManifestParam['ReleaseNotes'] = $ReleaseNotes
79+
}
80+
}
81+
}
82+
}
83+
if ($UpdateManifestParam.Count -gt 0) {
84+
Update-ModuleManifest -Path "$BuildRoot\bin\$ModuleName\$ModuleName.psd1" @UpdateManifestParam
85+
}
86+
}
87+
88+
task MakeHelp -if (Test-Path -Path "$PSScriptRoot\Docs") {
89+
90+
}
91+
92+
task TestBuild {
93+
Write-Build Yellow "`n`n`nTesting compiled module"
94+
$Script = @{Path="$PSScriptRoot\test\Unit"; Parameters=@{ModulePath="$BuildRoot\bin\$ModuleName"}}
95+
$CodeCoverage = Get-Module "$BuildRoot\bin\$ModuleName" -ListAvailable |
96+
Select-Object -ExpandProperty ExportedCommands |
97+
Select-Object -ExpandProperty Keys | Foreach-Object -Process {
98+
@{Path="$BuildRoot\bin\$ModuleName\$ModuleName.psm1";Function=$_}
99+
}
100+
$TestResult = Invoke-Pester -Script $Script -Tag Unit -CodeCoverage $CodeCoverage -PassThru
101+
if($TestResult.FailedCount -gt 0) {throw 'Tests failed'}
102+
}
103+
104+
105+
task MakePSM1 {
106+
107+
Get-ChildItem .\Scripts\init.ps1 | Out-File .\bin\$($ModuleName)\$($ModuleName).psm1 -Encoding utf8
108+
109+
$Private,$Public | ForEach-Object { Get-Content $_.FullName | Out-File .\bin\$($ModuleName)\$($ModuleName).psm1 -Encoding utf8 -Append }
110+
111+
}
112+
task UpdateManifest {
113+
114+
$PublicScriptBlock = Get-ScriptBlockFromFile -Path $public
115+
$PublicFunctions = Get-FunctionFromScriptblock -ScriptBlock $PublicScriptBlock
116+
$PublicAlias = Get-AliasFromScriptblock -ScriptBlock $PublicScriptBlock
117+
118+
$UpdateManifestParam = @{}
119+
if(-Not [String]::IsNullOrEmpty($PublicFunctions)) {
120+
$PublicFunctionParam = "-Function '{0}'" -f ($PublicFunctions -join "','")
121+
$UpdateManifestParam['FunctionsToExport'] = $PublicFunctions
122+
}
123+
if($PublicAlias) {
124+
$PublicAliasParam = "-Alias '{0}'" -f ($PublicAlias -join "','")
125+
$UpdateManifestParam['AliasesToExport'] = $PublicAlias
126+
}
127+
$ExportStrings = 'Export-ModuleMember',$PublicFunctionParam,$PublicAliasParam | Where-Object {-Not [string]::IsNullOrWhiteSpace($_)}
128+
$ExportStrings -join ' ' | Out-File -FilePath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1" -Append -Encoding UTF8
129+
130+
# If we have git and gitversion installed, let's use it to get new module version and Release Notes
131+
if ($(try{Get-Command -Name gitversion -ErrorAction Stop}catch{})) {
132+
$gitversion = gitversion | ConvertFrom-Json
133+
if ($gitversion.CommitsSinceVersionSource -gt 0) {
134+
# Prerelease, raise minor-version by 1 and add prerelease string.
135+
$UpdateManifestParam['ModuleVersion'] = '{0}.{1}.{2}' -f $gitversion.Major, ($gitversion.Minor+1), $gitversion.Patch
136+
$UpdateManifestParam['Prerelease'] = '-beta{0}' -f $gitversion.CommitsSinceVersionSourcePadded
137+
}
138+
else {
139+
# This is a release version
140+
# If there is a tag pointing at HEAD, use that as release notes
141+
$UpdateManifestParam['ModuleVersion'] = $gitversion.MajorMinorPatch
142+
if ($(try{Get-Command -Name git -ErrorAction Stop}catch{})) {
143+
if($CurrentTag = git tag --points-at HEAD) {
144+
$ReleaseNotes = git tag -l -n20 $CurrentTag | Select-Object -Skip 1
145+
$UpdateManifestParam['ReleaseNotes'] = $ReleaseNotes
146+
}
147+
}
148+
}
149+
}
150+
if ($UpdateManifestParam.Count -gt 0) {
151+
Update-ModuleManifest -Path "$BuildRoot\bin\$ModuleName\$ModuleName.psd1" @UpdateManifestParam
152+
}
153+
}
154+
155+
task . Clean, TestCode, Build
156+
157+
task Build CopyFiles, MakePSM1, MakeHelp, UpdateManifest
158+

‎build.min.ps1

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#Requires -Modules @{ModuleName='InvokeBuild';ModuleVersion='3.2.1'}
2+
#Requires -Modules @{ModuleName='PowerShellGet';ModuleVersion='1.6.0'}
3+
#Requires -Modules @{ModuleName='Pester';ModuleVersion='4.1.1'}
4+
5+
$Script:IsAppveyor = $env:APPVEYOR -ne $null
6+
$Script:ModuleName = Get-Item -Path $BuildRoot | Select-Object -ExpandProperty Name
7+
Get-Module -Name $ModuleName,'helpers' | Remove-Module -Force
8+
Import-Module "$BuildRoot\buildhelpers\helpers.psm1"
9+
#$tests = Get-ChildItem .\Pr*\*,.\Pu*\* -Recurse | Where-Object Name -Match Tests.ps1
10+
11+
$Script:ModuleName = 'PesterHelpers'
12+
#region Setup
13+
14+
$Private = Get-ChildItem .\Private\* -Recurse |
15+
Where-Object {$_.PSIsContainer -ne $true -and $_.Name -notmatch 'Tests.ps1'}
16+
17+
18+
$Public = Get-ChildItem .\Public\* -Recurse |
19+
Where-Object {$_.PSIsContainer -ne $true -and $_.Name -notmatch 'Tests.ps1'}
20+
21+
22+
#endregion
23+
24+
25+
task Clean {
26+
Remove-Item -Path ".\Bin" -Recurse -Force -ErrorAction SilentlyContinue
27+
}
28+
29+
task TestCode {
30+
Write-Build Yellow "`n`n`nTesting dev code before build"
31+
$TestResult = Invoke-Pester -Script $BuildRoot\$($ModuleName).min.tests.ps1 -PassThru
32+
if($TestResult.FailedCount -gt 0) {throw 'Tests failed'}
33+
}
34+
35+
task CopyFiles {
36+
$null = New-Item -Path "$BuildRoot\bin\$ModuleName" -ItemType Directory
37+
Copy-Item -Path "$BuildRoot\*.psd1" -Destination "$BuildRoot\bin\$ModuleName"
38+
Get-ChildItem -Path "$BuildRoot\license*" | Copy-Item -Destination "$BuildRoot\bin\$ModuleName"
39+
Copy-Item $BuildRoot\Other -Destination $BuildRoot\bin\$ModuleName\Other -Recurse
40+
}
41+
42+
task CompilePSM {
43+
$PrivatePath = '{0}\Private\*.ps1' -f $BuildRoot
44+
$PublicPath = '{0}\Public\*.ps1'-f $BuildRoot
45+
$ScriptPath = '{0}\Script\*.ps1'-f $BuildRoot
46+
Merge-ModuleFiles -Path $ScriptPath,$PrivatePath,$PublicPath -OutputPath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1"
47+
48+
$PublicScriptBlock = Get-ScriptBlockFromFile -Path $PublicPath
49+
$PublicFunctions = Get-FunctionFromScriptblock -ScriptBlock $PublicScriptBlock
50+
$PublicAlias = Get-AliasFromScriptblock -ScriptBlock $PublicScriptBlock
51+
$PublicFunctionParam, $PublicAliasParam = ''
52+
$UpdateManifestParam = @{}
53+
if(-Not [String]::IsNullOrEmpty($PublicFunctions)) {
54+
$PublicFunctionParam = "-Function '{0}'" -f ($PublicFunctions -join "','")
55+
$UpdateManifestParam['FunctionsToExport'] = $PublicFunctions
56+
}
57+
if($PublicAlias) {
58+
$PublicAliasParam = "-Alias '{0}'" -f ($PublicAlias -join "','")
59+
$UpdateManifestParam['AliasesToExport'] = $PublicAlias
60+
}
61+
$ExportStrings = 'Export-ModuleMember',$PublicFunctionParam,$PublicAliasParam | Where-Object {-Not [string]::IsNullOrWhiteSpace($_)}
62+
$ExportStrings -join ' ' | Out-File -FilePath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1" -Append -Encoding UTF8
63+
64+
# If we have git and gitversion installed, let's use it to get new module version and Release Notes
65+
if ($(try{Get-Command -Name gitversion -ErrorAction Stop}catch{})) {
66+
$gitversion = gitversion | ConvertFrom-Json
67+
if ($gitversion.CommitsSinceVersionSource -gt 0) {
68+
# Prerelease, raise minor-version by 1 and add prerelease string.
69+
$UpdateManifestParam['ModuleVersion'] = '{0}.{1}.{2}' -f $gitversion.Major, ($gitversion.Minor), $gitversion.Patch
70+
$UpdateManifestParam['Prerelease'] = '-beta{0}' -f $gitversion.CommitsSinceVersionSourcePadded
71+
}
72+
else {
73+
# This is a release version
74+
# If there is a tag pointing at HEAD, use that as release notes
75+
$UpdateManifestParam['ModuleVersion'] = $gitversion.MajorMinorPatch
76+
if ($(try{Get-Command -Name git -ErrorAction Stop}catch{})) {
77+
if($CurrentTag = git tag --points-at HEAD) {
78+
$ReleaseNotes = git tag -l -n20 $CurrentTag | Select-Object -Skip 1
79+
$UpdateManifestParam['ReleaseNotes'] = $ReleaseNotes
80+
}
81+
}
82+
}
83+
}
84+
if ($UpdateManifestParam.Count -gt 0) {
85+
Update-ModuleManifest -Path "$BuildRoot\bin\$ModuleName\$ModuleName.psd1" @UpdateManifestParam
86+
}
87+
}
88+
89+
task MakeHelp -if (Test-Path -Path "$PSScriptRoot\Docs") {
90+
91+
}
92+
93+
task TestBuild {
94+
Write-Build Yellow "`n`n`nTesting compiled module"
95+
$Script = @{Path="$PSScriptRoot\test\Unit"; Parameters=@{ModulePath="$BuildRoot\bin\$ModuleName"}}
96+
$CodeCoverage = Get-Module "$BuildRoot\bin\$ModuleName" -ListAvailable |
97+
Select-Object -ExpandProperty ExportedCommands |
98+
Select-Object -ExpandProperty Keys | Foreach-Object -Process {
99+
@{Path="$BuildRoot\bin\$ModuleName\$ModuleName.psm1";Function=$_}
100+
}
101+
$TestResult = Invoke-Pester -Script $Script -Tag Unit -CodeCoverage $CodeCoverage -PassThru
102+
if($TestResult.FailedCount -gt 0) {throw 'Tests failed'}
103+
}
104+
105+
106+
task MakePSM1 {
107+
108+
Get-Content .\Scripts\init.ps1 | Out-File .\bin\$($ModuleName)\$($ModuleName).psm1 -Encoding utf8
109+
110+
$Private,$Public | ForEach-Object { Get-Content $_.FullName | Out-File .\bin\$($ModuleName)\$($ModuleName).psm1 -Encoding utf8 -Append }
111+
112+
}
113+
task UpdateManifest {
114+
115+
$PublicScriptBlock = Get-ScriptBlockFromFile -Path $public
116+
$PublicFunctions = Get-FunctionFromScriptblock -ScriptBlock $PublicScriptBlock
117+
$PublicAlias = Get-AliasFromScriptblock -ScriptBlock $PublicScriptBlock
118+
119+
$UpdateManifestParam = @{}
120+
if(-Not [String]::IsNullOrEmpty($PublicFunctions)) {
121+
$PublicFunctionParam = "-Function '{0}'" -f ($PublicFunctions -join "','")
122+
$UpdateManifestParam['FunctionsToExport'] = $PublicFunctions
123+
}
124+
if($PublicAlias) {
125+
$PublicAliasParam = "-Alias '{0}'" -f ($PublicAlias -join "','")
126+
$UpdateManifestParam['AliasesToExport'] = $PublicAlias
127+
}
128+
$ExportStrings = 'Export-ModuleMember',$PublicFunctionParam,$PublicAliasParam | Where-Object {-Not [string]::IsNullOrWhiteSpace($_)}
129+
$ExportStrings -join ' ' | Out-File -FilePath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1" -Append -Encoding UTF8
130+
131+
# If we have git and gitversion installed, let's use it to get new module version and Release Notes
132+
if ($(try{Get-Command -Name gitversion -ErrorAction Stop}catch{})) {
133+
$gitversion = gitversion | ConvertFrom-Json
134+
if ($gitversion.CommitsSinceVersionSource -gt 0) {
135+
# Prerelease, raise minor-version by 1 and add prerelease string.
136+
$UpdateManifestParam['ModuleVersion'] = '{0}.{1}.{2}' -f $gitversion.Major, ($gitversion.Minor+1), $gitversion.Patch
137+
$UpdateManifestParam['Prerelease'] = '-beta{0}' -f $gitversion.CommitsSinceVersionSourcePadded
138+
}
139+
else {
140+
# This is a release version
141+
# If there is a tag pointing at HEAD, use that as release notes
142+
$UpdateManifestParam['ModuleVersion'] = $gitversion.MajorMinorPatch
143+
if ($(try{Get-Command -Name git -ErrorAction Stop}catch{})) {
144+
if($CurrentTag = git tag --points-at HEAD) {
145+
$ReleaseNotes = git tag -l -n20 $CurrentTag | Select-Object -Skip 1
146+
$UpdateManifestParam['ReleaseNotes'] = $ReleaseNotes
147+
}
148+
}
149+
}
150+
}
151+
if ($UpdateManifestParam.Count -gt 0) {
152+
Update-ModuleManifest -Path "$BuildRoot\bin\$ModuleName\$ModuleName.psd1" @UpdateManifestParam
153+
}
154+
}
155+
156+
task . Clean, TestCode, Build
157+
158+
task Build CopyFiles, MakePSM1, MakeHelp, UpdateManifest
159+

‎build.norm.ps1

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#Requires -Modules @{ModuleName='InvokeBuild';ModuleVersion='3.2.1'}
2+
#Requires -Modules @{ModuleName='PowerShellGet';ModuleVersion='1.6.0'}
3+
#Requires -Modules @{ModuleName='Pester';ModuleVersion='4.1.1'}
4+
5+
$Script:IsAppveyor = $env:APPVEYOR -ne $null
6+
$Script:ModuleName = Get-Item -Path $BuildRoot | Select-Object -ExpandProperty Name
7+
Get-Module -Name $ModuleName,'helpers' | Remove-Module -Force
8+
Import-Module "$BuildRoot\buildhelpers\helpers.psm1"
9+
#$tests = Get-ChildItem .\Pr*\*,.\Pu*\* -Recurse | Where-Object Name -Match Tests.ps1
10+
11+
12+
#region Setup
13+
14+
$Private = Get-ChildItem .\Private\* -Recurse |
15+
Where-Object {$_.PSIsContainer -ne $true -and $_.Name -notmatch 'Tests.ps1'}
16+
17+
18+
$Public = Get-ChildItem .\Public\* -Recurse |
19+
Where-Object {$_.PSIsContainer -ne $true -and $_.Name -notmatch 'Tests.ps1'}
20+
21+
22+
#endregion
23+
24+
25+
task Clean {
26+
Remove-Item -Path ".\Bin" -Recurse -Force -ErrorAction SilentlyContinue
27+
}
28+
29+
task TestCode {
30+
Write-Build Yellow "`n`n`nTesting dev code before build"
31+
$TestResult = Invoke-Pester -Script $BuildRoot\$($env:standardname).norm.tests.ps1 -PassThru
32+
if($TestResult.FailedCount -gt 0) {throw 'Tests failed'}
33+
}
34+
35+
task CopyFiles {
36+
$null = New-Item -Path "$BuildRoot\bin\$ModuleName" -ItemType Directory
37+
Copy-Item -Path "$BuildRoot\*.psd1" -Destination "$BuildRoot\bin\$ModuleName"
38+
Get-ChildItem -Path "$BuildRoot\license*" | Copy-Item -Destination "$BuildRoot\bin\$ModuleName"
39+
Copy-Item $BuildRoot\Other -Recurse -Destination $BuildRoot\Bin\$($ModuleName)\
40+
}
41+
42+
task CompilePSM {
43+
$PrivatePath = '{0}\Private\*.ps1' -f $BuildRoot
44+
$PublicPath = '{0}\Public\*.ps1'-f $BuildRoot
45+
$ScriptPath = '{0}\Script\*.ps1'-f $BuildRoot
46+
Merge-ModuleFiles -Path $ScriptPath,$PrivatePath,$PublicPath -OutputPath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1"
47+
48+
$PublicScriptBlock = Get-ScriptBlockFromFile -Path $PublicPath
49+
$PublicFunctions = Get-FunctionFromScriptblock -ScriptBlock $PublicScriptBlock
50+
$PublicAlias = Get-AliasFromScriptblock -ScriptBlock $PublicScriptBlock
51+
$PublicFunctionParam, $PublicAliasParam = ''
52+
$UpdateManifestParam = @{}
53+
if(-Not [String]::IsNullOrEmpty($PublicFunctions)) {
54+
$PublicFunctionParam = "-Function '{0}'" -f ($PublicFunctions -join "','")
55+
$UpdateManifestParam['FunctionsToExport'] = $PublicFunctions
56+
}
57+
if($PublicAlias) {
58+
$PublicAliasParam = "-Alias '{0}'" -f ($PublicAlias -join "','")
59+
$UpdateManifestParam['AliasesToExport'] = $PublicAlias
60+
}
61+
$ExportStrings = 'Export-ModuleMember',$PublicFunctionParam,$PublicAliasParam | Where-Object {-Not [string]::IsNullOrWhiteSpace($_)}
62+
$ExportStrings -join ' ' | Out-File -FilePath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1" -Append -Encoding UTF8
63+
64+
# If we have git and gitversion installed, let's use it to get new module version and Release Notes
65+
if ($(try{Get-Command -Name gitversion -ErrorAction Stop}catch{})) {
66+
$gitversion = gitversion | ConvertFrom-Json
67+
if ($gitversion.CommitsSinceVersionSource -gt 0) {
68+
# Prerelease, raise minor-version by 1 and add prerelease string.
69+
$UpdateManifestParam['ModuleVersion'] = '{0}.{1}.{2}' -f $gitversion.Major, ($gitversion.Minor), $gitversion.Patch
70+
$UpdateManifestParam['Prerelease'] = '-beta{0}' -f $gitversion.CommitsSinceVersionSourcePadded
71+
}
72+
else {
73+
# This is a release version
74+
# If there is a tag pointing at HEAD, use that as release notes
75+
$UpdateManifestParam['ModuleVersion'] = $gitversion.MajorMinorPatch
76+
if ($(try{Get-Command -Name git -ErrorAction Stop}catch{})) {
77+
if($CurrentTag = git tag --points-at HEAD) {
78+
$ReleaseNotes = git tag -l -n20 $CurrentTag | Select-Object -Skip 1
79+
$UpdateManifestParam['ReleaseNotes'] = $ReleaseNotes
80+
}
81+
}
82+
}
83+
}
84+
if ($UpdateManifestParam.Count -gt 0) {
85+
Update-ModuleManifest -Path "$BuildRoot\bin\$ModuleName\$ModuleName.psd1" @UpdateManifestParam
86+
}
87+
}
88+
89+
task MakeHelp -if (Test-Path -Path "$PSScriptRoot\Docs") {
90+
91+
}
92+
93+
task TestBuild {
94+
Write-Build Yellow "`n`n`nTesting compiled module"
95+
$Script = @{Path="$PSScriptRoot\test\Unit"; Parameters=@{ModulePath="$BuildRoot\bin\$ModuleName"}}
96+
$CodeCoverage = Get-Module "$BuildRoot\bin\$ModuleName" -ListAvailable |
97+
Select-Object -ExpandProperty ExportedCommands |
98+
Select-Object -ExpandProperty Keys | Foreach-Object -Process {
99+
@{Path="$BuildRoot\bin\$ModuleName\$ModuleName.psm1";Function=$_}
100+
}
101+
$TestResult = Invoke-Pester -Script $Script -Tag Unit -CodeCoverage $CodeCoverage -PassThru
102+
if($TestResult.FailedCount -gt 0) {throw 'Tests failed'}
103+
}
104+
105+
106+
task MakePSM1 {
107+
108+
Get-ChildItem .\Scripts\init.ps1 | Out-File .\bin\$($ModuleName)\$($ModuleName).psm1 -Encoding utf8
109+
110+
$Private,$Public | ForEach-Object { Get-Content $_.FullName | Out-File .\bin\$($ModuleName)\$($ModuleName).psm1 -Encoding utf8 -Append }
111+
112+
}
113+
task UpdateManifest {
114+
115+
$PublicScriptBlock = Get-ScriptBlockFromFile -Path $public
116+
$PublicFunctions = Get-FunctionFromScriptblock -ScriptBlock $PublicScriptBlock
117+
$PublicAlias = Get-AliasFromScriptblock -ScriptBlock $PublicScriptBlock
118+
119+
$UpdateManifestParam = @{}
120+
if(-Not [String]::IsNullOrEmpty($PublicFunctions)) {
121+
$PublicFunctionParam = "-Function '{0}'" -f ($PublicFunctions -join "','")
122+
$UpdateManifestParam['FunctionsToExport'] = $PublicFunctions
123+
}
124+
if($PublicAlias) {
125+
$PublicAliasParam = "-Alias '{0}'" -f ($PublicAlias -join "','")
126+
$UpdateManifestParam['AliasesToExport'] = $PublicAlias
127+
}
128+
$ExportStrings = 'Export-ModuleMember',$PublicFunctionParam,$PublicAliasParam | Where-Object {-Not [string]::IsNullOrWhiteSpace($_)}
129+
$ExportStrings -join ' ' | Out-File -FilePath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1" -Append -Encoding UTF8
130+
131+
# If we have git and gitversion installed, let's use it to get new module version and Release Notes
132+
if ($(try{Get-Command -Name gitversion -ErrorAction Stop}catch{})) {
133+
$gitversion = gitversion | ConvertFrom-Json
134+
if ($gitversion.CommitsSinceVersionSource -gt 0) {
135+
# Prerelease, raise minor-version by 1 and add prerelease string.
136+
$UpdateManifestParam['ModuleVersion'] = '{0}.{1}.{2}' -f $gitversion.Major, ($gitversion.Minor+1), $gitversion.Patch
137+
$UpdateManifestParam['Prerelease'] = '-beta{0}' -f $gitversion.CommitsSinceVersionSourcePadded
138+
}
139+
else {
140+
# This is a release version
141+
# If there is a tag pointing at HEAD, use that as release notes
142+
$UpdateManifestParam['ModuleVersion'] = $gitversion.MajorMinorPatch
143+
if ($(try{Get-Command -Name git -ErrorAction Stop}catch{})) {
144+
if($CurrentTag = git tag --points-at HEAD) {
145+
$ReleaseNotes = git tag -l -n20 $CurrentTag | Select-Object -Skip 1
146+
$UpdateManifestParam['ReleaseNotes'] = $ReleaseNotes
147+
}
148+
}
149+
}
150+
}
151+
if ($UpdateManifestParam.Count -gt 0) {
152+
Update-ModuleManifest -Path "$BuildRoot\bin\$ModuleName\$ModuleName.psd1" @UpdateManifestParam
153+
}
154+
}
155+
156+
task . Clean, TestCode, Build
157+
158+
task Build CopyFiles, MakePSM1, MakeHelp, UpdateManifest
159+

‎build.ps1

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#Requires -Modules @{ModuleName='InvokeBuild';ModuleVersion='3.2.1'}
2+
#Requires -Modules @{ModuleName='PowerShellGet';ModuleVersion='1.6.0'}
3+
#Requires -Modules @{ModuleName='Pester';ModuleVersion='4.1.1'}
4+
5+
$Script:IsAppveyor = $env:APPVEYOR -ne $null
6+
$Script:ModuleName = 'PesterHelpers'
7+
Get-Module -Name $ModuleName,'helpers' | Remove-Module -Force
8+
Import-Module "$BuildRoot\buildhelpers\helpers.psm1"
9+
#$tests = Get-ChildItem .\Pr*\*,.\Pu*\* -Recurse | Where-Object Name -Match Tests.ps1
10+
11+
12+
#region Setup
13+
14+
$Private = Get-ChildItem .\Private\* -Recurse |
15+
Where-Object {$_.PSIsContainer -ne $true -and $_.Name -notmatch 'Tests.ps1'}
16+
17+
18+
$Public = Get-ChildItem .\Public\* -Recurse |
19+
Where-Object {$_.PSIsContainer -ne $true -and $_.Name -notmatch 'Tests.ps1'}
20+
21+
22+
#endregion
23+
24+
25+
task Clean {
26+
Remove-Item -Path ".\Bin" -Recurse -Force -ErrorAction SilentlyContinue
27+
}
28+
29+
task TestCode {
30+
Write-Build Yellow "`n`n`nTesting dev code before build"
31+
$TestResult = Invoke-Pester -Script $BuildRoot\$($ModuleName).$($env:Test).tests.ps1 -PassThru
32+
if($TestResult.FailedCount -gt 0) {throw 'Tests failed'}
33+
}
34+
35+
task CopyFiles {
36+
$null = New-Item -Path "$BuildRoot\bin\$ModuleName" -ItemType Directory
37+
Copy-Item -Path "$BuildRoot\*.psd1" -Destination "$BuildRoot\bin\$ModuleName"
38+
Get-ChildItem -Path "$BuildRoot\license*" | Copy-Item -Destination "$BuildRoot\bin\$ModuleName"
39+
Copy-Item $BuildRoot\Other -Destination $BuildRoot\$ModuleName\Other -Recurse
40+
}
41+
42+
task CompilePSM {
43+
$PrivatePath = '{0}\Private\*.ps1' -f $BuildRoot
44+
$PublicPath = '{0}\Public\*.ps1'-f $BuildRoot
45+
$ScriptPath = '{0}\Script\*.ps1'-f $BuildRoot
46+
Merge-ModuleFiles -Path $ScriptPath,$PrivatePath,$PublicPath -OutputPath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1"
47+
48+
$PublicScriptBlock = Get-ScriptBlockFromFile -Path $PublicPath
49+
$PublicFunctions = Get-FunctionFromScriptblock -ScriptBlock $PublicScriptBlock
50+
$PublicAlias = Get-AliasFromScriptblock -ScriptBlock $PublicScriptBlock
51+
$PublicFunctionParam, $PublicAliasParam = ''
52+
$UpdateManifestParam = @{}
53+
if(-Not [String]::IsNullOrEmpty($PublicFunctions)) {
54+
$PublicFunctionParam = "-Function '{0}'" -f ($PublicFunctions -join "','")
55+
$UpdateManifestParam['FunctionsToExport'] = $PublicFunctions
56+
}
57+
if($PublicAlias) {
58+
$PublicAliasParam = "-Alias '{0}'" -f ($PublicAlias -join "','")
59+
$UpdateManifestParam['AliasesToExport'] = $PublicAlias
60+
}
61+
$ExportStrings = 'Export-ModuleMember',$PublicFunctionParam,$PublicAliasParam | Where-Object {-Not [string]::IsNullOrWhiteSpace($_)}
62+
$ExportStrings -join ' ' | Out-File -FilePath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1" -Append -Encoding UTF8
63+
64+
# If we have git and gitversion installed, let's use it to get new module version and Release Notes
65+
if ($(try{Get-Command -Name gitversion -ErrorAction Stop}catch{})) {
66+
$gitversion = gitversion | ConvertFrom-Json
67+
if ($gitversion.CommitsSinceVersionSource -gt 0) {
68+
# Prerelease, raise minor-version by 1 and add prerelease string.
69+
$UpdateManifestParam['ModuleVersion'] = '{0}.{1}.{2}' -f $gitversion.Major, ($gitversion.Minor), $gitversion.Patch
70+
$UpdateManifestParam['Prerelease'] = '-beta{0}' -f $gitversion.CommitsSinceVersionSourcePadded
71+
}
72+
else {
73+
# This is a release version
74+
# If there is a tag pointing at HEAD, use that as release notes
75+
$UpdateManifestParam['ModuleVersion'] = $gitversion.MajorMinorPatch
76+
if ($(try{Get-Command -Name git -ErrorAction Stop}catch{})) {
77+
if($CurrentTag = git tag --points-at HEAD) {
78+
$ReleaseNotes = git tag -l -n20 $CurrentTag | Select-Object -Skip 1
79+
$UpdateManifestParam['ReleaseNotes'] = $ReleaseNotes
80+
}
81+
}
82+
}
83+
}
84+
if ($UpdateManifestParam.Count -gt 0) {
85+
Update-ModuleManifest -Path "$BuildRoot\bin\$ModuleName\$ModuleName.psd1" @UpdateManifestParam
86+
}
87+
}
88+
89+
task MakeHelp -if (Test-Path -Path "$PSScriptRoot\Docs") {
90+
91+
}
92+
93+
task TestBuild {
94+
Write-Build Yellow "`n`n`nTesting compiled module"
95+
$Script = @{Path="$PSScriptRoot\test\Unit"; Parameters=@{ModulePath="$BuildRoot\bin\$ModuleName"}}
96+
$CodeCoverage = Get-Module "$BuildRoot\bin\$ModuleName" -ListAvailable |
97+
Select-Object -ExpandProperty ExportedCommands |
98+
Select-Object -ExpandProperty Keys | Foreach-Object -Process {
99+
@{Path="$BuildRoot\bin\$ModuleName\$ModuleName.psm1";Function=$_}
100+
}
101+
$TestResult = Invoke-Pester -Script $Script -Tag Unit -CodeCoverage $CodeCoverage -PassThru
102+
if($TestResult.FailedCount -gt 0) {throw 'Tests failed'}
103+
}
104+
105+
106+
task MakePSM1 {
107+
108+
Get-ChildItem .\Scripts\init.ps1 | Out-File .\bin\$($ModuleName)\$($ModuleName).psm1 -Encoding utf8
109+
110+
$Private,$Public | ForEach-Object { Get-Content $_.FullName | Out-File .\bin\$($ModuleName)\$($ModuleName).psm1 -Encoding utf8 -Append }
111+
112+
}
113+
task UpdateManifest {
114+
115+
$PublicScriptBlock = Get-ScriptBlockFromFile -Path $public
116+
$PublicFunctions = Get-FunctionFromScriptblock -ScriptBlock $PublicScriptBlock
117+
$PublicAlias = Get-AliasFromScriptblock -ScriptBlock $PublicScriptBlock
118+
119+
$UpdateManifestParam = @{}
120+
if(-Not [String]::IsNullOrEmpty($PublicFunctions)) {
121+
$PublicFunctionParam = "-Function '{0}'" -f ($PublicFunctions -join "','")
122+
$UpdateManifestParam['FunctionsToExport'] = $PublicFunctions
123+
}
124+
if($PublicAlias) {
125+
$PublicAliasParam = "-Alias '{0}'" -f ($PublicAlias -join "','")
126+
$UpdateManifestParam['AliasesToExport'] = $PublicAlias
127+
}
128+
$ExportStrings = 'Export-ModuleMember',$PublicFunctionParam,$PublicAliasParam | Where-Object {-Not [string]::IsNullOrWhiteSpace($_)}
129+
$ExportStrings -join ' ' | Out-File -FilePath "$BuildRoot\bin\$ModuleName\$ModuleName.psm1" -Append -Encoding UTF8
130+
131+
# If we have git and gitversion installed, let's use it to get new module version and Release Notes
132+
if ($(try{Get-Command -Name gitversion -ErrorAction Stop}catch{})) {
133+
$gitversion = gitversion | ConvertFrom-Json
134+
if ($gitversion.CommitsSinceVersionSource -gt 0) {
135+
# Prerelease, raise minor-version by 1 and add prerelease string.
136+
$UpdateManifestParam['ModuleVersion'] = '{0}.{1}.{2}' -f $gitversion.Major, ($gitversion.Minor+1), $gitversion.Patch
137+
$UpdateManifestParam['Prerelease'] = '-beta{0}' -f $gitversion.CommitsSinceVersionSourcePadded
138+
}
139+
else {
140+
# This is a release version
141+
# If there is a tag pointing at HEAD, use that as release notes
142+
$UpdateManifestParam['ModuleVersion'] = $gitversion.MajorMinorPatch
143+
if ($(try{Get-Command -Name git -ErrorAction Stop}catch{})) {
144+
if($CurrentTag = git tag --points-at HEAD) {
145+
$ReleaseNotes = git tag -l -n20 $CurrentTag | Select-Object -Skip 1
146+
$UpdateManifestParam['ReleaseNotes'] = $ReleaseNotes
147+
}
148+
}
149+
}
150+
}
151+
if ($UpdateManifestParam.Count -gt 0) {
152+
Update-ModuleManifest -Path "$BuildRoot\bin\$ModuleName\$ModuleName.psd1" @UpdateManifestParam
153+
}
154+
}
155+
156+
task . Clean, TestCode, Build
157+
158+
task Build CopyFiles, MakePSM1, MakeHelp, UpdateManifest
159+

‎buildhelpers/helpers.psm1

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function Get-ScriptblockFromFile {
2+
[CmdletBinding()]
3+
param (
4+
# Specifies a path to one or more locations. Wildcards are permitted.
5+
[Parameter(Mandatory=$true,
6+
ValueFromPipeline=$true,
7+
ValueFromPipelineByPropertyName=$true,
8+
HelpMessage="Path to one or more locations.")]
9+
[ValidateNotNullOrEmpty()]
10+
[SupportsWildcards()]
11+
[string[]]
12+
$Path
13+
)
14+
process {
15+
$Content = $Path | Foreach-Object -Process {
16+
Get-Content -Path $_ -Encoding UTF8 } | Out-String
17+
[ScriptBlock]::Create($Content)
18+
}
19+
}
20+
21+
function Get-FunctionFromScriptblock {
22+
[CmdletBinding()]
23+
param (
24+
# Scriptblock
25+
[Parameter(Mandatory)]
26+
[scriptblock]
27+
$ScriptBlock
28+
)
29+
process {
30+
$ScriptBlock.Ast.FindAll({ $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst]},$false).Name
31+
}
32+
}
33+
34+
function Get-AliasFromScriptblock {
35+
[CmdletBinding()]
36+
param (
37+
# Scriptblock
38+
[Parameter(Mandatory)]
39+
[scriptblock]
40+
$ScriptBlock
41+
)
42+
process {
43+
(
44+
$ScriptBlock.Ast.FindAll({ $args[0] -is [System.Management.Automation.Language.AttributeAst] },$true) |
45+
Where-Object -FilterScript {
46+
$_.TypeName.FullName -eq 'Alias' -and $_.Parent -is [System.Management.Automation.Language.ParamBlockAst]
47+
}
48+
).PositionalArguments.Value
49+
}
50+
}

0 commit comments

Comments
 (0)
Please sign in to comment.