-
Notifications
You must be signed in to change notification settings - Fork 54
/
build.ps1
158 lines (119 loc) · 4.43 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/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,
[switch]
$Deploy,
[string]
$CoreToolsDir,
[string]
$Configuration = "Debug",
[string]
$BuildNumber = '0'
)
#Requires -Version 7.0
Import-Module "$PSScriptRoot/tools/helper.psm1" -Force
$TargetFramework = 'net8.0'
$PowerShellVersion = '7.4'
Write-Log "Build worker version: $PowerShellVersion"
Write-Log "Target framework: $TargetFramework"
function Get-FunctionsCoreToolsDir {
if ($CoreToolsDir) {
$CoreToolsDir
} else {
$funcPath = (Get-Command func).Source
if (-not $funcPath) {
throw 'Cannot find "func" command. Please install Azure Functions Core Tools: ' +
'see https://github.com/Azure/azure-functions-core-tools#installing for instructions'
}
# func may be just a symbolic link, so we need to follow it until we find the true location
while ((((Get-Item $funcPath).Attributes) -band 'ReparsePoint') -ne 0) {
$funcPath = (Get-Item $funcPath).Target
}
$funcParentDir = Split-Path -Path $funcPath -Parent
if (-not (Test-Path -Path $funcParentDir/workers/powershell -PathType Container)) {
throw 'Cannot find Azure Function Core Tools installation directory. ' +
'Please provide the path in the CoreToolsDir parameter.'
}
$funcParentDir
}
}
function Deploy-PowerShellWorker {
$ErrorActionPreference = 'Stop'
$powerShellWorkerDir = "$(Get-FunctionsCoreToolsDir)/workers/powershell/$PowerShellVersion"
if (-not (Test-Path $powerShellWorkerDir))
{
Write-Log "Creating directory: '$powerShellWorkerDir'"
New-Item -Path $powerShellWorkerDir -ItemType Directory -Force | Out-Null
}
Write-Log "Deploying worker to $powerShellWorkerDir..."
if (-not $IsWindows) {
sudo chmod -R a+w $powerShellWorkerDir
}
Remove-Item -Path $powerShellWorkerDir/* -Recurse -Force
Copy-Item -Path "./src/bin/$Configuration/$TargetFramework/publish/*" `
-Destination $powerShellWorkerDir -Recurse -Force
Write-Log "Deployed worker to $powerShellWorkerDir"
}
# 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
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." }
}
if ($Deploy.IsPresent) {
Deploy-PowerShellWorker
}