This repository was archived by the owner on Aug 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.ps1
116 lines (94 loc) · 3.59 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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
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
)
$config = Get-Content -Path (Join-Path $PSScriptRoot 'pspackageproject.json') | ConvertFrom-Json
$script:ModuleName = $config.ModuleName
$script:SrcPath = $config.SourcePath
$script:OutDirectory = $config.BuildOutputPath
$script:SignedDirectory = $config.SignedOutputPath
$script:TestPath = $config.TestPath
$script:ModuleRoot = $PSScriptRoot
$script:OutDirectory = Join-Path -Path $ModuleRoot -ChildPath $OutDirectory
$script:SignedDirectory = Join-Path -Path $ModuleRoot -ChildPath $SignedDirectory
$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"
}
<#
.DESCRIPTION
Implement build and packaging of the package and place the output $OutDirectory/$ModuleName
#>
function DoBuild
{
Write-Verbose -Verbose -Message "Starting DoBuild"
Get-ChildItem -Path $script:SrcPath -Filter "*.ps?1" |
ForEach-Object { Copy-Item -Path $_.FullName -Destination $script:OutModule -Verbose }
Copy-Item -Path (Join-Path $script:SrcPath 'yml') -Recurse $script:OutModule -Force -Verbose
Copy-Item -Path (Join-Path $script:SrcPath 'build_for_init.ps1') -Destination $script:OutModule -Verbose
Copy-Item -Path (Join-Path $script:SrcPath 'gitignore_for_init') -Destination $script:OutModule -Verbose
# Workaround problem where two ps1 files in a nuget causes nuget packaging to hang.
# rename it to PSM1 so that static analysis still works
Copy-Item -Path (Join-Path $script:SrcPath 'dobuild.ps1') -Destination $script:OutModule/dobuild.psm1 -Verbose
Copy-Item -Path (Join-Path $script:SrcPath 'WHAT_TO_DO_NEXT.md') -Destination $script:OutModule -Verbose
Write-Verbose -Verbose -Message "Ending DoBuild"
}
#region Special casing for PSPackageProject CI system
$PSPackageProjectModule = [System.IO.Path]::Combine($PSScriptRoot, $SrcPath, "$ModuleName.psd1")
Import-Module $PSPackageProjectModule -Force
#endregion
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 ( $Test.IsPresent ) {
Invoke-PSPackageProjectTest -Type $TestType
}
if ($UpdateHelp.IsPresent) {
Add-PSPackageProjectCmdletHelp -ProjectRoot $ModuleRoot -ModuleName $ModuleName -Culture $Culture
}