forked from Azure/azure-functions-powershell-worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
97 lines (75 loc) · 3.07 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
#!/usr/bin/env pwsh
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
[CmdletBinding()]
param(
[switch]
$Clean,
[switch]
$Bootstrap,
[switch]
$Test,
[switch]
$NoBuild,
[string]
$Configuration = "Debug",
[string]
$BuildNumber = '0'
)
#Requires -Version 6.0
Import-Module "$PSScriptRoot/tools/helper.psm1" -Force
# Bootstrap step
if ($Bootstrap.IsPresent) {
Write-Log "Validate and install missing prerequisits for building ..."
Install-Dotnet
if (-not (Get-Module -Name PSDepend -ListAvailable)) {
Write-Log -Warning "Module 'PSDepend' is missing. Installing 'PSDepend' ..."
Install-Module -Name PSDepend -Scope CurrentUser -Force
}
if (-not (Get-Module -Name platyPS -ListAvailable)) {
Write-Log -Warning "Module 'platyPS' is missing. Installing 'platyPS' ..."
Install-Module -Name platyPS -Scope CurrentUser -Force
}
}
# Clean step
if($Clean.IsPresent) {
Push-Location $PSScriptRoot
git clean -fdX
Pop-Location
}
# Common step required by both build and test
Find-Dotnet
# Build step
if(!$NoBuild.IsPresent) {
if (-not (Get-Module -Name PSDepend -ListAvailable)) {
throw "Cannot find the 'PSDepend' module. Please specify '-Bootstrap' to install build dependencies."
}
# Generate C# files for resources
Start-ResGen
# Generate csharp code from protobuf if needed
New-gRPCAutoGenCode
$requirements = "$PSScriptRoot/src/requirements.psd1"
$modules = Import-PowerShellDataFile $requirements
Write-Log "Install modules that are bundled with PowerShell Language worker, including"
foreach ($entry in $modules.GetEnumerator()) {
Write-Log -Indent "$($entry.Name) $($entry.Value.Version)"
}
Invoke-PSDepend -Path $requirements -Force
Write-Log "Deleting fullclr folder from PackageManagement module if the folder exists ..."
Get-Item "$PSScriptRoot/src/Modules/PackageManagement/1.1.7.0/fullclr" -ErrorAction SilentlyContinue |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
# TODO: Remove this once the SDK properly bundles modules
Get-WebFile -Url 'https://raw.githubusercontent.com/PowerShell/PowerShell/master/src/Modules/Windows/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1' `
-OutFile "$PSScriptRoot/src/Modules/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1"
Get-WebFile -Url 'https://raw.githubusercontent.com/PowerShell/PowerShell/master/src/Modules/Windows/Microsoft.PowerShell.Management/Microsoft.PowerShell.Management.psd1' `
-OutFile "$PSScriptRoot/src/Modules/Microsoft.PowerShell.Management/Microsoft.PowerShell.Management.psd1"
dotnet publish -c $Configuration "/p:BuildNumber=$BuildNumber" $PSScriptRoot
dotnet pack -c $Configuration "/p:BuildNumber=$BuildNumber" "$PSScriptRoot/package"
}
# Test step
if($Test.IsPresent) {
dotnet test "$PSScriptRoot/test/Unit"
if ($LASTEXITCODE -ne 0) { throw "xunit tests failed." }
}