Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ param(
[switch]
$NoBuild,

[switch]
$Deploy,

[string]
$CoreToolsDir,

[string]
$Configuration = "Debug",

Expand All @@ -33,6 +39,34 @@ param(

#Requires -Version 6.0

$PowerShellVersion = '6'
$TargetFramework = 'netcoreapp2.1'
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 Install-SBOMUtil
{
if ([string]::IsNullOrEmpty($SBOMUtilSASUrl))
Expand Down Expand Up @@ -62,6 +96,24 @@ function Install-SBOMUtil
return $manifestToolPath
}

function Deploy-PowerShellWorker {
$ErrorActionPreference = 'Stop'

$powerShellWorkerDir = "$(Get-FunctionsCoreToolsDir)/workers/powershell/$PowerShellVersion"

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"
}

Import-Module "$PSScriptRoot/tools/helper.psm1" -Force

# Bootstrap step
Expand Down Expand Up @@ -153,3 +205,7 @@ if($Test.IsPresent) {
dotnet test "$PSScriptRoot/test/Unit"
if ($LASTEXITCODE -ne 0) { throw "xunit tests failed." }
}

if ($Deploy.IsPresent) {
Deploy-PowerShellWorker
}