From 0b54783877cca229e2fc3f772ce7257cf0b3814f Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 29 May 2019 21:15:29 -0700 Subject: [PATCH] [Helix] Try running node services tests on helix again (#9046) --- eng/helix/content/InstallNode.ps1 | 71 +++++++++++++++++++ eng/helix/content/installnode.sh | 29 ++++++++ eng/helix/content/runtests.cmd | 2 +- eng/helix/content/runtests.sh | 2 +- eng/targets/Helix.props | 9 +++ ...osoft.AspNetCore.NodeServices.Tests.csproj | 9 +-- .../NodeServices/test/NodeServicesTest.cs | 3 +- 7 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 eng/helix/content/InstallNode.ps1 create mode 100644 eng/helix/content/installnode.sh diff --git a/eng/helix/content/InstallNode.ps1 b/eng/helix/content/InstallNode.ps1 new file mode 100644 index 0000000000..862e612582 --- /dev/null +++ b/eng/helix/content/InstallNode.ps1 @@ -0,0 +1,71 @@ + <# + .SYNOPSIS + Installs NodeJs from http://nodejs.org/dist on a machine + .DESCRIPTION + This script installs NodeJs from http://nodejs.org/dist on a machine. + .PARAMETER Version + The version of NodeJS to install. + .PARAMETER InstallDir + The directory to install NodeJS to. + .LINK + https://nodejs.org/en/ + #> +param( + [Parameter(Mandatory = $true)] + $Version, + + [Parameter(Mandatory = $true)] + $InstallDir +) + +$ErrorActionPreference = 'Stop' +$ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138 + +Set-StrictMode -Version 1 + +if (Get-Command "node.exe" -ErrorAction SilentlyContinue) +{ + Write-Host "Found node.exe in PATH" + exit +} + +if (Test-Path "$output_dir\node.exe") +{ + Write-Host "Node.exe found at $output_dir" + exit +} + +$nodeFile="node-v$Version-win-x64" +$url="http://nodejs.org/dist/v$Version/$nodeFile.zip" +Write-Host "Starting download of NodeJs ${Version} from $url" +Invoke-WebRequest -UseBasicParsing -Uri "$url" -OutFile "nodejs.zip" +Write-Host "Done downloading NodeJS ${Version}" + +$tempPath = [System.IO.Path]::GetTempPath() +$tempDir = Join-Path $tempPath nodejs +New-Item -Path "$tempDir" -ItemType "directory" -Force +Write-Host "Extracting to $tempDir" + +if (Get-Command -Name 'Microsoft.PowerShell.Archive\Expand-Archive' -ErrorAction Ignore) { + # Use built-in commands where possible as they are cross-plat compatible + Microsoft.PowerShell.Archive\Expand-Archive -Path "nodejs.zip" -DestinationPath $tempDir +} +else { + # Fallback to old approach for old installations of PowerShell + Add-Type -AssemblyName System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::ExtractToDirectory("nodejs.zip", $tempDir) +} + +Write-Host "Expanded NodeJs" +New-Item -Path "$InstallDir" -ItemType "directory" -Force +Write-Host "Copying $tempDir\$nodeFile\node.exe to $InstallDir" +Copy-Item "$tempDir\$nodeFile\node.exe" "$InstallDir\node.exe" + +if (Test-Path "$InstallDir\node.exe") +{ + Write-Host "Node.exe copied to $InstallDir" +} +else +{ + Write-Host "Node.exe not copied to $InstallDir" +} diff --git a/eng/helix/content/installnode.sh b/eng/helix/content/installnode.sh new file mode 100644 index 0000000000..5a72cca423 --- /dev/null +++ b/eng/helix/content/installnode.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Cause the script to fail if any subcommand fails +set -e + +if type -P "node" &>/dev/null; then + echo "node is in \$PATH" + exit +fi + +node_version=$1 +osname=`uname -s` +echo $osname +if [ "$osname" = "Darwin" ]; then + platformarch='darwin-x64' +else + platformarch='linux-x64' +fi +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +output_dir="$DIR/node" +url="http://nodejs.org/dist/v$node_version/node-v$node_version-$platformarch.tar.gz" +tmp="$(mktemp -d -t install-node.XXXXXX)" +trap "rm -rf $tmp" EXIT +cd "$tmp" +curl -Lsfo $(basename $url) "$url" +echo "Installing node from $(basename $url) $url" +mkdir $output_dir +echo "Unpacking to $output_dir" +tar --strip-components 1 -xzf "node-v$node_version-$platformarch.tar.gz" --no-same-owner --directory "$output_dir" diff --git a/eng/helix/content/runtests.cmd b/eng/helix/content/runtests.cmd index 8657c61ec1..8344fe5a66 100644 --- a/eng/helix/content/runtests.cmd +++ b/eng/helix/content/runtests.cmd @@ -14,7 +14,7 @@ set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 set DOTNET_MULTILEVEL_LOOKUP=0 set DOTNET_CLI_HOME=%HELIX_CORRELATION_PAYLOAD%\home -set PATH=%DOTNET_ROOT%;%PATH% +set PATH=%DOTNET_ROOT%;%PATH%;%HELIX_CORRELATION_PAYLOAD%\node\bin powershell.exe -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -useb 'https://dot.net/v1/dotnet-install.ps1'))) -Architecture x64 -Version %sdkVersion% -InstallDir %DOTNET_ROOT%" powershell.exe -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -useb 'https://dot.net/v1/dotnet-install.ps1'))) -Architecture x64 -Runtime dotnet -Version %runtimeVersion% -InstallDir %DOTNET_ROOT%" diff --git a/eng/helix/content/runtests.sh b/eng/helix/content/runtests.sh index b3a786ee05..e864f097de 100644 --- a/eng/helix/content/runtests.sh +++ b/eng/helix/content/runtests.sh @@ -16,7 +16,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" export DOTNET_ROOT="$DIR/.dotnet$RANDOM" # Ensure dotnet comes first on PATH -export PATH="$DOTNET_ROOT:$PATH" +export PATH="$DOTNET_ROOT:$PATH:$DIR/node/bin" # Prevent fallback to global .NET locations. This ensures our tests use the shared frameworks we specify and don't rollforward to something else that might be installed on the machine export DOTNET_MULTILEVEL_LOOKUP=0 diff --git a/eng/targets/Helix.props b/eng/targets/Helix.props index b2f297fe63..c6b1b68cd2 100644 --- a/eng/targets/Helix.props +++ b/eng/targets/Helix.props @@ -17,6 +17,7 @@ $(MSBuildProjectName)/$(TargetFramework) false true + 10.15.3 @@ -35,4 +36,12 @@ + + + + + + + + diff --git a/src/Middleware/NodeServices/test/Microsoft.AspNetCore.NodeServices.Tests.csproj b/src/Middleware/NodeServices/test/Microsoft.AspNetCore.NodeServices.Tests.csproj index 0b8c614e31..7d0bed922f 100644 --- a/src/Middleware/NodeServices/test/Microsoft.AspNetCore.NodeServices.Tests.csproj +++ b/src/Middleware/NodeServices/test/Microsoft.AspNetCore.NodeServices.Tests.csproj @@ -2,19 +2,14 @@ netcoreapp3.0 - - - - false - - - + true + diff --git a/src/Middleware/NodeServices/test/NodeServicesTest.cs b/src/Middleware/NodeServices/test/NodeServicesTest.cs index a5012ea8aa..f851e08d0c 100644 --- a/src/Middleware/NodeServices/test/NodeServicesTest.cs +++ b/src/Middleware/NodeServices/test/NodeServicesTest.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.NodeServices.HostingModels; using Microsoft.Extensions.DependencyInjection; using System; +using System.IO; using System.Threading.Tasks; using Xunit; @@ -115,7 +116,7 @@ namespace Microsoft.AspNetCore.NodeServices } private static string ModulePath(string testModuleName) - => $"../../../js/{testModuleName}"; + => Path.Combine(AppContext.BaseDirectory, "js", testModuleName); public void Dispose() {