-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.psake.ps1
55 lines (43 loc) · 1.79 KB
/
build.psake.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
Task default -depends Build
Properties {
$source = $psake.build_script_dir
$buildTarget = '~\Documents\WindowsPowerShell\Modules\GenericMethods'
$filesToExclude = @(
'README.md'
'GenericMethods.Tests.ps1'
'build.psake.ps1'
)
}
Task Test {
$result = Invoke-Pester -Path $source -PassThru
$failed = $result.FailedCount
if ($failed -gt 0)
{
throw "$failed unit tests failed; build aborting."
}
}
Task Build -depends Test {
if (Test-Path -Path $buildTarget -PathType Container)
{
Remove-Item -Path $buildTarget -Recurse -Force -ErrorAction Stop
}
$null = New-Item -Path $buildTarget -ItemType Directory -ErrorAction Stop
Copy-Item -Path $source\* -Exclude $filesToExclude -Destination $buildTarget -Recurse -ErrorAction Stop
}
Task Sign {
$CertThumbprint = '20164DCA86BDFBB5B345AF85F5DB54E9AFFA3F30'
$TimestampURL = 'http://timestamp.digicert.com'
$cert = $(Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object { $_.Thumbprint -eq $CertThumbprint -and $_.PrivateKey -is [System.Security.Cryptography.RSACryptoServiceProvider] } )
if ($cert -eq $null) {
throw 'My code signing certificate was not found!'
}
$properties = @(
@{ Label = 'Name'; Expression = { Split-Path -Path $_.Path -Leaf } }
'Status'
@{ Label = 'SignerCertificate'; Expression = { $_.SignerCertificate.Thumbprint } }
@{ Label = 'TimeStamperCertificate'; Expression = { $_.TimeStamperCertificate.Thumbprint } }
)
Get-ChildItem -Path $buildTarget\* -Include *.ps1, *.psm1, *.psd1, *.dll |
Set-AuthenticodeSignature -Certificate $cert -TimestampServer $TimestampURL -Force -IncludeChain All -ErrorAction Stop -HashAlgorithm SHA256 |
Format-Table -Property $properties -AutoSize
}