-
Notifications
You must be signed in to change notification settings - Fork 3
/
custom.build.ps1
84 lines (74 loc) · 2.72 KB
/
custom.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
<#
.SYNOPSIS
Build script which leverages the InvokeBuild module.
.DESCRIPTION
Build script which leverages the InvokeBuild module.
This build script is used in the build pipeline and local development for building this project.
Invoked by invoke.build.ps1 in this project where its intent is to implement project-specific custom pre/post build actions during the build pipeline andds local development.
#>
[CmdletBinding()]
param (
[Parameter()]
[ValidateNotNullOrEmpty()]
[String]$ModuleName,
[Parameter()]
[ValidateNotNullOrEmpty()]
[String]$Author,
[Parameter()]
[String]$Version,
[Parameter()]
[Bool]$NewRelease
)
task PreBuild {
if (-not (Get-Module 'ConfigurationManager' -ListAvailable)) {
Invoke-BuildClean -Path $BuildRoot\misc
New-Item -Path $BuildRoot\misc\ConfigurationManager\ConfigurationManager.psm1 -ItemType File -Force
$Params = @{
Path = '{0}\misc\ConfigurationManager\ConfigurationManager.psd1' -f $BuildRoot
Guid = (New-Guid).Guid
RootModule = '{0}\misc\ConfigurationManager\ConfigurationManager.psm1' -f $BuildRoot
}
New-ModuleManifest @Params
$SuccessfullyCopiedModule = $false
foreach ($ModulePath in $env:PSModulePath.Split([System.IO.Path]::PathSeparator)) {
try {
$Params = @{
Path = '{0}\misc\ConfigurationManager' -f $BuildRoot
Destination = $ModulePath
Recurse = $true
Force = $true
PassThru = $true
ErrorAction = 'Stop'
}
Copy-Item @Params
$SuccessfullyCopiedModule = $true
break
}
catch {
Write-Warning -Message ('Failed to copy dummy ConfigurationManager module to "{0}" ({1})' -f $ModuleName, $_.Exception.Message)
}
}
if (-not $SuccessfullyCopiedModule) {
Write-Error "Failed to copy dummy ConfigurationManager module to a PSModulePath folder" -ErrorAction "Stop"
}
}
}
task PostBuild {
Invoke-BuildClean -Path $BuildRoot\misc
if ($env:USER -ne 'runner') {
Get-Module 'ConfigurationManager' -ListAvailable | ForEach-Object {
if ($_ -notmatch 'AdminConsole\\bin') {
Remove-Item -Path $_.ModuleBase -Recurse -Force -ErrorAction 'Stop'
}
}
}
}
task PreRelease {
}
task PostRelease {
Get-Module 'ConfigurationManager' -ListAvailable | ForEach-Object {
if ($_ -notmatch 'AdminConsole\\bin') {
Remove-Item -Path $_.ModuleBase -Recurse -Force -ErrorAction 'Stop'
}
}
}