Skip to content

Commit

Permalink
move all npm-related stuff to build scripts (dotnet#1757)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo authored Nov 22, 2021
1 parent 096de43 commit 3def90b
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 176 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-keymap",
"ms-toolsai.jupyter-renderers",
"ms-vscode.powershell",
"ionide.ionide-fsharp"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand All @@ -49,7 +50,7 @@
// dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
// * macOS/Linux terminal:
// dotnet dev-certs https --trust; dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
//
//
// 2. Uncomment these 'remoteEnv' lines:
// "remoteEnv": {
// "ASPNETCORE_Kestrel__Certificates__Default__Password": "SecurePwdGoesHere",
Expand Down
19 changes: 13 additions & 6 deletions .devcontainer/workspace.code-workspace
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
{
"folders": [
{
"name": "Repo Root",
"path": ".."
},
{
"name": "NPM Package",
"path": "..\\src\\dotnet-interactive-npm"
"path": "../src/dotnet-interactive-npm"
},
{
"name": "VS Code - Stable",
"path": "..\\src\\dotnet-interactive-vscode\\stable"
"path": "../src/dotnet-interactive-vscode/stable"
},
{
"name": "VS Code - Insiders",
"path": "..\\src\\dotnet-interactive-vscode\\insiders"
"path": "../src/dotnet-interactive-vscode/insiders"
},
{
"path": "..\\src\\Microsoft.DotNet.Interactive.Js"
"path": "../src/Microsoft.DotNet.Interactive.Js"
},
{
"path": "../src/Microsoft.DotNet.Interactive.Mermaid.js"
},
{
"path": "../src/Microsoft.DotNet.Interactive.nteract.js"
},
{
"path": "../src/Microsoft.DotNet.Interactive.SandDance.js"
}
],
"settings": {}
Expand Down
68 changes: 19 additions & 49 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ variables:
value: $(Build.SourcesDirectory)/artifacts/.trydotnet/packages
- name: NodeJSVersion
value: '16.13.0'
- name: _TestArgs
value: ''

stages:
- stage: build
Expand Down Expand Up @@ -78,10 +76,6 @@ stages:
value: Test
- name: _BuildArgs
value: /p:SignType=$(_SignType)
# SkipTests
# - ${{ if ne(variables['SkipTests'], 'true') }}:
# - name: _TestArgs
# value: -test
steps:
- script: git config --global core.longpaths true
displayName: Enable `git clean` to handle long paths
Expand Down Expand Up @@ -114,12 +108,17 @@ stages:
exit /b 1
displayName: Prevent test directory crawling
- pwsh: |
$testArg = if ($env:SKIPTESTS -ne "true") { "-test" } else { "" }
Write-Host "##vso[task.setvariable variable=_TestArgs]$testArg"
displayName: Promote variables
- script: eng\CIBuild.cmd
-configuration $(_BuildConfig)
-prepareMachine
-sign
$(_TestArgs)
$(_BuildArgs)
$(_TestArgs)
displayName: Build
env:
POCKETLOGGER_LOG_PATH: $(PocketLoggerLogPath)
Expand All @@ -143,40 +142,6 @@ stages:
artifactType: container
condition: failed()

- script: npm run ciTest
displayName: NPM tests
workingDirectory: "$(Build.SourcesDirectory)/src/Microsoft.DotNet.Interactive.Js"
condition: ne(variables['SkipTests'], 'true')

# build and test VS Code extension
- script: npm install
displayName: npm install (VS Code stable)
workingDirectory: "$(Build.SourcesDirectory)/src/dotnet-interactive-vscode/stable"

- script: npm run ciTest
displayName: npm test (VS Code stable)
workingDirectory: "$(Build.SourcesDirectory)/src/dotnet-interactive-vscode/stable"
condition: ne(variables['SkipTests'], 'true')

- script: npm install
displayName: npm install (VS Code insiders)
workingDirectory: "$(Build.SourcesDirectory)/src/dotnet-interactive-vscode/insiders"

- script: npm run ciTest
displayName: npm test (VS Code insiders)
workingDirectory: "$(Build.SourcesDirectory)/src/dotnet-interactive-vscode/insiders"
condition: ne(variables['SkipTests'], 'true')

# build and test npm package
- script: npm install
displayName: npm install (npm package)
workingDirectory: "$(Build.SourcesDirectory)/src/dotnet-interactive-npm"

- script: npm run ciTest
displayName: npm test (npm package)
workingDirectory: "$(Build.SourcesDirectory)/src/dotnet-interactive-npm"
condition: ne(variables['SkipTests'], 'true')

# publish VS Code and npm test results
- task: PublishTestResults@2
displayName: Publish VS Code extension and npm test results
Expand Down Expand Up @@ -262,10 +227,6 @@ stages:
value: Test
- name: _BuildArgs
value: /p:SignType=$(_SignType)
# SkipTests
# - ${{ if ne(variables['SkipTests'], 'true') }}:
# - name: _TestArgs
# value: --test
steps:
- script: git config --global core.longpaths true
displayName: Enable `git clean` to handle long paths
Expand All @@ -292,6 +253,11 @@ stages:
cp eng/resources/* "$(Build.SourcesDirectory)/artifacts"
displayName: Prevent test directory crawling
- pwsh: |
$testArg = if ($env:SKIPTESTS -ne "true") { "--test" } else { "" }
Write-Host "##vso[task.setvariable variable=_TestArgs]$testArg"
displayName: Promote variables
- script: ./eng/cibuild.sh
--configuration $(_BuildConfig)
--prepareMachine
Expand Down Expand Up @@ -319,10 +285,14 @@ stages:
artifactType: container
condition: failed()

- script: npm run ciTest
displayName: NPM tests
workingDirectory: "$(Build.SourcesDirectory)/src/Microsoft.DotNet.Interactive.Js"
condition: ne(variables['SkipTests'], 'true')
# publish VS Code and npm test results
- task: PublishTestResults@2
displayName: Publish VS Code extension and npm test results
inputs:
testResultsFormat: VSTest
testResultsFiles: '**/*.trx'
searchFolder: '$(Build.SourcesDirectory)/artifacts/TestResults'
condition: always()

- template: /eng/common/templates/jobs/jobs.yml
parameters:
Expand Down
2 changes: 2 additions & 0 deletions build-js.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0eng\build.ps1" -noDotnet %*
16 changes: 16 additions & 0 deletions build-js.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

source="${BASH_SOURCE[0]}"

# resolve $SOURCE until the file is no longer a symlink
while [[ -h $source ]]; do
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
source="$(readlink "$source")"

# if $source was a relative symlink, we need to resolve it relative to the path where
# the symlink file was located
[[ $source != /* ]] && source="$scriptroot/$source"
done
scriptroot="$( cd -P "$( dirname "$source" )" && pwd)"

. "$scriptroot/eng/build.sh" --no-dotnet "$@"
2 changes: 1 addition & 1 deletion build.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@echo off
@echo off
powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0eng\build.ps1" -build -restore -binaryLog %*
91 changes: 52 additions & 39 deletions eng/build.ps1
Original file line number Diff line number Diff line change
@@ -1,41 +1,15 @@
[CmdletBinding(PositionalBinding = $false)]
param (
[switch]$ci,
[switch]$noDotnet,
[switch]$test,
[Parameter(ValueFromRemainingArguments = $true)][String[]]$arguments
)

Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"

function TestUsingNPM([string] $testPath) {
Write-Host "Installing packages"
Start-Process -PassThru -WindowStyle Hidden -WorkingDirectory $testPath -Wait npm "i"
Write-Host "Testing"
$test = Start-Process -PassThru -WindowStyle Hidden -WorkingDirectory $testPath -Wait npm "run ciTest"
Write-Host "Done with code $($test.ExitCode)"
return $test.ExitCode
}

$arguments = $args
function isCi {
$isCi = $arguments | Select-String -Pattern '-ci' -CaseSensitive -SimpleMatch
return ($isCi -ne "")
}
$isCi = isCi

function buildConfiguration {
$release = $arguments | Select-String -Pattern ('release', 'debug') -SimpleMatch -CaseSensitive
if ([System.String]::IsNullOrWhitespace($release) -eq $true) {
return "Debug"
}
else {
return "$release"
}
}
$buildConfiguration = buildConfiguration

try {
# if (isCi -eq $true) {
# . (Join-Path $PSScriptRoot "..\buildSqlTools.cmd") $buildConfiguration
# if ($LASTEXITCODE -ne 0) {
# exit $LASTEXITCODE
# }
# }

$repoRoot = Resolve-Path "$PSScriptRoot\.."
$symlinkDirectories = @(
"$repoRoot\src\dotnet-interactive-vscode\stable\src\common",
Expand All @@ -55,15 +29,54 @@ try {
}
}

# invoke regular build/test script
. (Join-Path $PSScriptRoot "common\build.ps1") -projects "$PSScriptRoot\..\dotnet-interactive.sln" @args
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
# build and test NPM
$npmDirs = @(
"src\dotnet-interactive-npm",
"src\dotnet-interactive-vscode\stable",
"src\dotnet-interactive-vscode\insiders",
"src\Microsoft.DotNet.Interactive.Js",
"src\Microsoft.DotNet.Interactive.Mermaid.js",
"src\Microsoft.DotNet.Interactive.nteract.js",
"src\Microsoft.DotNet.Interactive.SandDance.js"
)
foreach ($npmDir in $npmDirs) {
Push-Location "$repoRoot\$npmDir"
Write-Host "Building NPM in directory $npmDir"
npm ci
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
npm run compile
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

if ($test) {
Write-Host "Testing NPM in directory $npmDir"
npm run ciTest
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}

Pop-Location
}

if (-Not $noDotnet) {
# promote switches to arguments
if ($ci) {
$arguments += "-ci"
}
if ($test -And -Not($ci)) {
# CI runs unit tests elsewhere, so only promote the `-test` switch if we're not running CI
$arguments += '-test'
}

# invoke regular build/test script
$buildScript = (Join-Path $PSScriptRoot "common\build.ps1")
Invoke-Expression "$buildScript -projects ""$PSScriptRoot\..\dotnet-interactive.sln"" $arguments"
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
}
}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
exit 1
}
}
55 changes: 45 additions & 10 deletions eng/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e

source="${BASH_SOURCE[0]}"

# resolve $source until the file is no longer a symlink
Expand All @@ -12,28 +14,61 @@ while [[ -h "$source" ]]; do
done
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"

# parse args
args=""
is_ci=false
no_dotnet=false
run_tests=false

# scan for `--test` or `-t`
# scan for `--test` or `--ci` switches
while [[ $# > 0 ]]; do
opt="$(echo "$1" | awk '{print tolower($0)}')"
case "$opt" in
--ci)
is_ci=true
args="$args --ci"
;;
--no-dotnet)
no_dotnet=true
;;
--test|-t)
run_tests=true
;;
*)
args="$args $1"
;;
esac
args="$args $1"
shift
done

function TestUsingNPM() {
test_path=$1
pushd "$test_path"
npm i
# build and test NPM
npmDirs='src/dotnet-interactive-npm
src/dotnet-interactive-vscode/stable
src/dotnet-interactive-vscode/insiders
src/Microsoft.DotNet.Interactive.Js
src/Microsoft.DotNet.Interactive.Mermaid.js
src/Microsoft.DotNet.Interactive.nteract.js
src/Microsoft.DotNet.Interactive.SandDance.js'
for npmDir in $npmDirs;
do
echo "Building NPM in directory $npmDir"
pushd $npmDir
npm ci
npm run compile
if [[ "$run_tests" == true ]]; then
echo "Testing NPM in directory $npmDir"
npm run ciTest
popd
}
fi
popd
done

if [[ "$no_dotnet" != true ]]; then
# promote switches to arguments
if [[ "$run_tests" == true ]] && [[ "$is_ci" != true ]]; then
# CI runs unit tests elsewhere, so only promote the `--test` switch if we're not running CI
args="$args --test"
fi

# invoke regular build/test script
. "$scriptroot/common/build.sh" "/p:Projects=$scriptroot/../dotnet-interactive.sln" $args
# invoke regular build/test script
. "$scriptroot/common/build.sh" "/p:Projects=$scriptroot/../dotnet-interactive.sln" $args
fi
2 changes: 2 additions & 0 deletions eng/cibuild.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e

source="${BASH_SOURCE[0]}"

# resolve $SOURCE until the file is no longer a symlink
Expand Down
Empty file modified eng/common/build.sh
100644 → 100755
Empty file.
Loading

0 comments on commit 3def90b

Please sign in to comment.