forked from PowerShell/PSDesiredStateConfiguration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
122 lines (100 loc) · 3.34 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# Do NOT edit this file. Edit dobuild.ps1
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
param (
[Parameter(ParameterSetName="build")]
[switch]
$Clean,
[Parameter(ParameterSetName="build")]
[switch]
$Build,
[Parameter(ParameterSetName="publish")]
[switch]
$Publish,
[Parameter(ParameterSetName="publish")]
[switch]
$Signed,
[Parameter(ParameterSetName="build")]
[switch]
$Test,
[Parameter(ParameterSetName="build")]
[string[]]
[ValidateSet("Functional","StaticAnalysis")]
$TestType = @("Functional"),
[Parameter(ParameterSetName="help")]
[switch]
$UpdateHelp,
[Parameter(ParameterSetName="build")]
[switch]
$TestInvokeDscResource
)
$config = Get-PSPackageProjectConfiguration -ConfigPath $PSScriptRoot
$script:ModuleName = $config.ModuleName
$script:SrcPath = $config.SourcePath
$script:OutDirectory = $config.BuildOutputPath
$script:SignedDirectory = $config.SignedOutputPath
$script:TestPath = $config.TestPath
$script:ModuleRoot = $PSScriptRoot
$script:Culture = $config.Culture
$script:HelpPath = $config.HelpPath
if ($env:TF_BUILD) {
$vstsCommandString = "vso[task.setvariable variable=BUILD_OUTPUT_PATH]$OutDirectory"
Write-Host ("sending " + $vstsCommandString)
Write-Host "##$vstsCommandString"
$vstsCommandString = "vso[task.setvariable variable=SIGNED_OUTPUT_PATH]$SignedDirectory"
Write-Host ("sending " + $vstsCommandString)
Write-Host "##$vstsCommandString"
}
. $PSScriptRoot\dobuild.ps1
if ( ! ( Get-Module -ErrorAction SilentlyContinue PSPackageProject) ) {
Install-Module PSPackageProject
}
if ($Clean -and (Test-Path $OutDirectory))
{
Remove-Item -Force -Recurse $OutDirectory -ErrorAction Stop -Verbose
}
if (-not (Test-Path $OutDirectory))
{
$script:OutModule = New-Item -ItemType Directory -Path (Join-Path $OutDirectory $ModuleName)
}
else
{
$script:OutModule = Join-Path $OutDirectory $ModuleName
}
if ($Build.IsPresent)
{
$sb = (Get-Item Function:DoBuild).ScriptBlock
Invoke-PSPackageProjectBuild -BuildScript $sb -SkipPublish
}
if ($Publish.IsPresent)
{
Invoke-PSPackageProjectPublish -Signed:$Signed.IsPresent
}
if ( $TestInvokeDscResource.IsPresent ) {
$backupName = $null
try {
$configFolder = split-path $PROFILE
$configPath = Join-Path $configFolder -ChildPath powershell.config.json
if(Test-Path ~/.config/powershell/powershell.config.json)
{
$backupName = Join-Path $configFolder -ChildPath "powershell.config-((Get-Date).ToString('yyyyMMddHHmm')).json"
Copy-Item $configPath $backupName -force
}
copy-Item $PSScriptRoot/assets/powershell.config.json $configPath
Invoke-PSPackageProjectTest -Type $TestType
}
finally {
remove-item $configPath
if($backupName)
{
Copy-Item $backupName $configPath -force
}
}
}
if ( $Test.IsPresent ) {
Invoke-PSPackageProjectTest -Type $TestType
}
if ($UpdateHelp.IsPresent) {
Add-PSPackageProjectCmdletHelp -ProjectRoot $ModuleRoot -ModuleName $ModuleName -Culture $Culture
}