Skip to content

Commit 9d6f7bc

Browse files
Add support to update the PS worker binaries in the Core Tools (#780)
1 parent 0c494c0 commit 9d6f7bc

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

build.ps1

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ param(
1818
[switch]
1919
$NoBuild,
2020

21+
[switch]
22+
$Deploy,
23+
24+
[string]
25+
$CoreToolsDir,
26+
2127
[string]
2228
$Configuration = "Debug",
2329

@@ -33,6 +39,34 @@ param(
3339

3440
#Requires -Version 6.0
3541

42+
$PowerShellVersion = '6'
43+
$TargetFramework = 'netcoreapp2.1'
44+
function Get-FunctionsCoreToolsDir {
45+
if ($CoreToolsDir) {
46+
$CoreToolsDir
47+
} else {
48+
$funcPath = (Get-Command func).Source
49+
if (-not $funcPath) {
50+
throw 'Cannot find "func" command. Please install Azure Functions Core Tools: ' +
51+
'see https://github.com/Azure/azure-functions-core-tools#installing for instructions'
52+
}
53+
54+
# func may be just a symbolic link, so we need to follow it until we find the true location
55+
while ((((Get-Item $funcPath).Attributes) -band 'ReparsePoint') -ne 0) {
56+
$funcPath = (Get-Item $funcPath).Target
57+
}
58+
59+
$funcParentDir = Split-Path -Path $funcPath -Parent
60+
61+
if (-not (Test-Path -Path $funcParentDir/workers/powershell -PathType Container)) {
62+
throw 'Cannot find Azure Function Core Tools installation directory. ' +
63+
'Please provide the path in the CoreToolsDir parameter.'
64+
}
65+
66+
$funcParentDir
67+
}
68+
}
69+
3670
function Install-SBOMUtil
3771
{
3872
if ([string]::IsNullOrEmpty($SBOMUtilSASUrl))
@@ -62,6 +96,24 @@ function Install-SBOMUtil
6296
return $manifestToolPath
6397
}
6498

99+
function Deploy-PowerShellWorker {
100+
$ErrorActionPreference = 'Stop'
101+
102+
$powerShellWorkerDir = "$(Get-FunctionsCoreToolsDir)/workers/powershell/$PowerShellVersion"
103+
104+
Write-Log "Deploying worker to $powerShellWorkerDir..."
105+
106+
if (-not $IsWindows) {
107+
sudo chmod -R a+w $powerShellWorkerDir
108+
}
109+
110+
Remove-Item -Path $powerShellWorkerDir/* -Recurse -Force
111+
Copy-Item -Path "./src/bin/$Configuration/$TargetFramework/publish/*" `
112+
-Destination $powerShellWorkerDir -Recurse -Force
113+
114+
Write-Log "Deployed worker to $powerShellWorkerDir"
115+
}
116+
65117
Import-Module "$PSScriptRoot/tools/helper.psm1" -Force
66118

67119
# Bootstrap step
@@ -153,3 +205,7 @@ if($Test.IsPresent) {
153205
dotnet test "$PSScriptRoot/test/Unit"
154206
if ($LASTEXITCODE -ne 0) { throw "xunit tests failed." }
155207
}
208+
209+
if ($Deploy.IsPresent) {
210+
Deploy-PowerShellWorker
211+
}

0 commit comments

Comments
 (0)