|
4 | 4 | #
|
5 | 5 | param
|
6 | 6 | (
|
7 |
| - [Switch] |
8 |
| - $UseCoreToolsBuildFromIntegrationTests |
| 7 | + [Switch]$UseCoreToolsBuildFromIntegrationTests |
9 | 8 | )
|
10 | 9 |
|
11 |
| -$FUNC_RUNTIME_VERSION = '4' |
12 |
| -$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant() |
13 |
| -$os = if ($IsWindows) { "win" } else { if ($IsMacOS) { "osx" } else { "linux" } } |
| 10 | +$FUNC_RUNTIME_VERSION = 'latest' |
14 | 11 |
|
15 |
| -$env:CORE_TOOLS_URL = $null |
16 |
| -$coreToolsUrl = $null |
17 |
| -if ($UseCoreToolsBuildFromIntegrationTests.IsPresent) |
18 |
| -{ |
19 |
| - Write-Host "Install the Core Tools for Integration Tests..." |
20 |
| - $env:CORE_TOOLS_URL = "https://functionsintegclibuilds.blob.core.windows.net/builds/$FUNC_RUNTIME_VERSION/latest/Azure.Functions.Cli.$os-$arch.zip" |
21 |
| - $coreToolsUrl = "https://functionsintegclibuilds.blob.core.windows.net/builds/$FUNC_RUNTIME_VERSION/latest" |
22 |
| -} |
23 |
| -else |
24 |
| -{ |
25 |
| - Write-Host "Install the Core Tools..." |
26 |
| - $env:CORE_TOOLS_URL = "https://functionsclibuilds.blob.core.windows.net/builds/$FUNC_RUNTIME_VERSION/latest/Azure.Functions.Cli.$os-$arch.zip" |
27 |
| - $coreToolsUrl = "https://functionsclibuilds.blob.core.windows.net/builds/$FUNC_RUNTIME_VERSION/latest" |
28 |
| -} |
| 12 | +Write-Host "Installing Core Tools globlally using npm, version: $FUNC_RUNTIME_VERSION ..." |
29 | 13 |
|
30 | 14 | $FUNC_CLI_DIRECTORY = Join-Path $PSScriptRoot 'Azure.Functions.Cli'
|
| 15 | +$InstallDir = $FUNC_CLI_DIRECTORY |
| 16 | + |
| 17 | +# 1. Clean previous install |
| 18 | +Remove-Item -Recurse -Force $InstallDir -ErrorAction Ignore |
| 19 | +New-Item -ItemType Directory -Path $InstallDir -ErrorAction Ignore |
31 | 20 |
|
32 |
| -Write-Host 'Deleting the Core Tools if exists...' |
33 |
| -Remove-Item -Force "$FUNC_CLI_DIRECTORY.zip" -ErrorAction Ignore |
34 |
| -Remove-Item -Recurse -Force $FUNC_CLI_DIRECTORY -ErrorAction Ignore |
| 21 | +# 2. Locate the global prefix and module root that npm just used |
| 22 | +$globalPrefix = (npm prefix -g | Out-String).Trim() # e.g. /usr/local or C:\Users\<user>\AppData\Roaming\npm |
| 23 | +$globalNode = (npm root -g | Out-String).Trim() # e.g. /usr/local/lib/node_modules |
| 24 | +$moduleRoot = Join-Path $globalNode 'azure-functions-core-tools' |
35 | 25 |
|
36 |
| -$version = Invoke-RestMethod -Uri "$coreToolsUrl/version.txt" |
37 |
| -Write-Host "Downloading the Core Tools (Version: $version)..." |
| 26 | +# 3. npm install → temp folder |
| 27 | +npm install -g azure-functions-core-tools@$FUNC_RUNTIME_VERSION --unsafe-perm true --foreground-scripts --loglevel verbose |
38 | 28 |
|
39 |
| -$output = "$FUNC_CLI_DIRECTORY.zip" |
40 |
| -Write-Host "Downloading the Core Tools from url: $env:CORE_TOOLS_URL" |
41 |
| -Invoke-RestMethod -Uri $env:CORE_TOOLS_URL -OutFile $output |
| 29 | +# 4. Copy CLI payload into the layout required by your tests |
| 30 | +Copy-Item "$moduleRoot\bin\*" $InstallDir -Recurse -Force |
42 | 31 |
|
43 |
| -Write-Host 'Extracting Core Tools...' |
44 |
| -Expand-Archive $output -DestinationPath $FUNC_CLI_DIRECTORY |
45 | 32 |
|
46 | 33 | if (-not $UseCoreToolsBuildFromIntegrationTests.IsPresent)
|
47 | 34 | {
|
|
0 commit comments