-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
build.ps1
108 lines (90 loc) · 3.43 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
[CmdletBinding()]
param(
[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $ModuleOutPath = "./dist/ACME-PS",
[Parameter()]
[Switch] $SignModule
)
begin {
function Merge-ContentInto {
param(
[Parameter(Mandatory = $true, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[string] $File,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $OutFile
)
process {
Get-Content $_ | Add-Content $OutFile;
Add-Content $OutFile -Value "";
}
}
}
process {
$ErrorActionPreference = 'Stop';
$InformationPreference = 'Continue';
$ModuleSourcePath = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, "./ACME-PS"));
$ModuleOutPath = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $ModuleOutPath));
$ModuleOutFile = [System.IO.Path]::Combine($ModuleOutPath, "ACME-PS.psm1");
<# Clean Publish folder #>
if(Test-Path $ModuleOutPath) {
Write-Information "Delete old files from $ModuleOutPath";
Get-ChildItem "$ModuleOutPath/*" -Recurse | Remove-Item -Force -Recurse | Out-Null
} else {
Write-Information "Creating $ModuleOutPath";
New-Item $ModuleOutPath -ItemType Directory
}
<# Publish the module #>
$ContentFiles = @(
"$ModuleSourcePath/ACME-PS.psd1",
"$ModuleSourcePath/Prerequisites.ps1",
"$ModuleSourcePath/ACME-PS.png",
"$ModuleSourcePath/../LICENSE"
)
# Class files are sequence sensitive
$ClassPath = [System.IO.Path]::Combine($ModuleSourcePath, "./internal/classes");
$ClassFiles = @(
"crypto/AcmePSKey",
"crypto/Certificate",
"AcmeHttpResponse",
"AcmeHttpException",
"AcmeDirectory",
"AcmeAccount",
"AcmeIdentifier",
"AcmeChallenge",
"AcmeCsrOptions"
"AcmeOrder",
"AcmeAuthorization",
"AcmeState",
"AcmeState.InMemory",
"AcmeState.DiskPersisted"
);
$ScriptPaths = @(
"internal/functions",
"functions"
)
$ScriptFiles = $ScriptPaths | ForEach-Object { Get-ChildItem -Path ([System.IO.Path]::Combine($ModuleSourcePath, $_)) -Recurse -Include "*.ps1" }
Write-Information "Merge class files into $ModuleOutFile";
$ClassFiles | ForEach-Object { [System.IO.Path]::Combine($ClassPath, "$_.ps1") } | Merge-ContentInto -OutFile $ModuleOutFile;
Write-Information "Merge srcipt files into $ModuleOutFile";
$ScriptFiles | ForEach-Object { $_.FullName } | Merge-ContentInto -OutFile $ModuleOutFile;
Write-Information "Copy content files";
$ContentFiles | ForEach-Object { Copy-Item -Path $_ -Destination "$ModuleOutPath/" }
if($SignModule) {
Write-Information "Signing all *.ps* files"
$files = "$ModuleOutPath/*.ps*"
$cert = Get-Item Cert:\CurrentUser\My\39BCA611578AD62BA5126A406DBD4CC5DAFB859C
Set-AuthenticodeSignature -FilePath $files -Certificate $cert | Out-Null
}
Write-Information "Finished building - running tests";
<# Run tests #>
& Invoke-Command -ScriptBlock {
Import-Module "$ModuleOutPath\ACME-PS.psd1" -ErrorAction 'Stop'
if ($null -ne (Get-Module PSScriptAnalyzer -ListAvailable)) {
& Invoke-ScriptAnalyzer -Path $ModuleOutFile;
}
& Invoke-Pester -Path "$ModuleSourcePath\tests"
}
}