From 6e17a5061d37b63bdb4e67857044637a9491a574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0t=C4=9Bp=C3=A1nek?= Date: Fri, 11 Jun 2021 12:33:12 +0200 Subject: [PATCH] Configure CI (no. 154) --- ci/linux/run.sh | 4 +- ci/windows/run.ps1 | 227 +++++++++++++++++++++++++++----------------- ci/windows/test.ps1 | 1 + 3 files changed, 142 insertions(+), 90 deletions(-) create mode 100644 ci/windows/test.ps1 diff --git a/ci/linux/run.sh b/ci/linux/run.sh index 26669691ae..eaab49f476 100755 --- a/ci/linux/run.sh +++ b/ci/linux/run.sh @@ -146,8 +146,8 @@ echo "ROOT=$ROOT" echo "SLN=$SLN" echo "CONFIGURATION=$CONFIGURATION" echo "DISPLAY=$DISPLAY" -echo "SAMPLES_DIR=$SAMPLES_DIR" echo "TEST_RESULTS_DIR=$TEST_RESULTS_DIR" +echo "SAMPLES_DIR=$SAMPLES_DIR" echo "SAMPLES_PROFILE=$SAMPLES_PROFILE" echo "SAMPLES_PORT=$SAMPLES_PORT" echo "SAMPLES_PORT_API=$SAMPLES_PORT_API" @@ -205,11 +205,13 @@ if [ $SLN_RESTORE -eq 1 ]; then -v:m" fi +# seleniumconfig.json needs to be copied before the build of the sln if [ $UI_TESTS -eq 1 ]; then PROFILE_PATH="$SAMPLES_DIR/Profiles/$SAMPLES_PROFILE" if [ ! -f "$PROFILE_PATH" ]; then echo >&2 "Profile '$PROFILE_PATH' doesn't exist." + exit 1 fi cp -f "$PROFILE_PATH" "$SAMPLES_DIR/seleniumconfig.json" fi diff --git a/ci/windows/run.ps1 b/ci/windows/run.ps1 index 4756f844d5..bb71cc96c8 100644 --- a/ci/windows/run.ps1 +++ b/ci/windows/run.ps1 @@ -1,121 +1,170 @@ param( - [switch] $noNpmBuild = $false, - [switch] $noSlnRestore = $false, - [switch] $noSlnBuild = $false, - [switch] $noUnitTests = $false, - [switch] $noUITests = $false) - -$root = $env:DOTVVM_ROOT -if ($null -eq $root) { - $root = "$PWD" + [string] $Root, + [string] $Config, + [string] $SamplesProfile = "seleniumconfig.owin.chrome.json", + [string] $SamplesPort = "5407", + [string] $SamplesPortApi = "61453", + [switch] $Clean = $false, + [switch] $NoNpmBuild = $false, + [switch] $NoSlnRestore = $false, + [switch] $NoSlnBuild = $false, + [switch] $NoUnitTests = $false, + [switch] $NoJSTests = $false, + [switch] $NoUITests = $false) + +# ================== +# config var setting +# ================== + +$Root = $env:DOTVVM_ROOT +if ($null -eq $Root) { + $Root = "$PWD" } -$env:DOTVVM_ROOT = $root +$env:DOTVVM_ROOT = $Root -$configuration = $env:CONFIGURATION -if ($null -eq $configuration) { - $configuration = "Release" +$Config = $env:CONFIGURATION +if ($null -eq $Config) { + $Config = "Release" } -$sln = "$root\ci\windows\Windows.sln" -$packagesDir = "$root\src\packages\" -$testResultsDir = "$root\artifacts\test\" +$sln = "$Root\ci\windows\Windows.sln" +$packagesDir = "$Root\src\packages\" +$testResultsDir = "$Root\artifacts\test\" +$samplesDir = "$root\src\DotVVM.Samples.Tests" + +Write-Host "ROOT=$Root" +Write-Host "SLN=$sln" +Write-Host "CONFIGURATION=$Config" +Write-Host "TEST_RESULTS_DIR=$testResultsDir" +Write-Host "SAMPLES_DIR=$samplesDir" +Write-Host "SAMPLES_PROFILE=$SamplesProfile" +Write-Host "SAMPLES_PORT=$SamplesPort" +Write-Host "SAMPLES_PORT_API=$SamplesPortApi" + +# ================ +# helper functions +# ================ + +function Write-Header { + param ( + [string][parameter(Position=0)]$Text + ) + Write-Host -ForegroundColor Yellow "--------------------------------" + Write-Host -BackgroundColor Yellow $Text + Write-Host -ForegroundColor Yellow "--------------------------------" +} -Write-Host "ROOT=$ROOT" -Write-Host "CONFIGURATION=$CONFIGURATION" +function Run-Command { + param ( + [string][parameter(Position=0)]$Name, + [scriptblock][parameter(Position=1)]$Command + ) + Write-Header $Name + Write-Host -ForegroundColor Blue "$Command" + $Command.Invoke() +} -if ($noNpmBuild -ne $true) { - Write-Host "--------------------------------" - Write-Host "npm build" - Write-Host "--------------------------------" - Set-Location $root\src\DotVVM.Framework - npm ci --cache $root\.npm --prefer-offline - npm run build +function Ensure-Command { + param ( + [string][parameter(Position=0)]$Name, + [scriptblock][parameter(Position=1)]$Command + ) + Run-Command $Name $Command if ($LASTEXITCODE -ne 0) { - Write-Host "npm build failed" + Write-Host -ForegroundColor Red "$Name failed" exit 1 } } +function Clean-UITest { + Stop-Process -Force -Name chrome -ErrorAction SilentlyContinue + Stop-Process -Force -Name chromedriver -ErrorAction SilentlyContinue + Remove-IISSite -Confirm:$false -Name dotvvm.owin + Remove-IISSite -Confirm:$false -Name dotvvm.owin.api +} -if ($noSlnRestore -ne $true) { - Write-Host "--------------------------------" - Write-Host "sln restore" - Write-Host "--------------------------------" - Set-Location $root - & "$root\src\Tools\NuGet.exe" restore $sln -PackagesDirectory $packagesDir - dotnet restore $sln --packages $packagesDir - if ($LASTEXITCODE -ne 0) { - Write-Host "nuget restore failed" - exit 1 +# ============================= +# actual continuous integration +# ============================= + +if ($Clean -eq $true) { + Ensure-Command "clean" { + git clean -dfx } } -if ($noSlnBuild -ne $true) { - Write-Host "--------------------------------" - Write-Host "sln build" - Write-Host "--------------------------------" - msbuild $sln -v:m ` - -p:PublishProfile=$root\ci\windows\GenericPublish.pubxml ` - -p:DeployOnBuild=true ` - -p:Configuration=$configuration ` - -p:SourceLinkCreate=true - if ($LASTEXITCODE -ne 0) { - Write-Host "dotnet build failed" - exit 1 +if ($NoNpmBuild -ne $true) { + Ensure-Command "npm build" { + Set-Location $Root\src\DotVVM.Framework + npm ci --cache $Root\.npm --prefer-offline + npm run build } } -if ($noUnitTests -ne $true) { - Write-Host "--------------------------------" - Write-Host "unit tests" - Write-Host "--------------------------------" - dotnet test src/DotVVM.Framework.Tests ` - --no-build ` - --configuration $configuration ` - --logger trx ` - --results-directory $testResultsDir ` - --collect "Code Coverage" +if ($NoSlnRestore -ne $true) { + Ensure-Command "sln restore" { + Set-Location $Root + & "$Root\src\Tools\NuGet.exe" restore $sln -PackagesDirectory $packagesDir + dotnet restore $sln --packages $packagesDir + } } -function Clean-UITest { - Stop-Process -Force -Name chrome -ErrorAction SilentlyContinue - Stop-Process -Force -Name chromedriver -ErrorAction SilentlyContinue - Remove-IISSite -Confirm:$false -Name dotvvm.owin - Remove-IISSite -Confirm:$false -Name dotvvm.owin.api -} +# seleniumconfig.json needs to be copied before the build of the sln +if ($UI_TESTS -eq $true) { + $profilePath="$samplesDir\Profiles\$SamplesProfile" -if ($noUITests -ne $true) { - Write-Host "--------------------------------" - Write-Host "UI tests" - Write-Host "--------------------------------" + if (Test-Path -PathType Leaf -Path $profilePath) { + Write-Host -ForegroundColor Red "Profile '$PROFILE_PATH' doesn't exist." + exit 1 + } + Copy-Item -Force "$profilePath" "$samplesDir\seleniumconfig.json" +} - Import-Module IISAdministration - Clean-UITest +if ($NoSlnBuild -ne $true) { + Ensure-Command "sln build" { + msbuild $sln -v:m ` + -p:PublishProfile=$Root\ci\windows\GenericPublish.pubxml ` + -p:DeployOnBuild=true ` + -p:Configuration=$Config ` + -p:SourceLinkCreate=true + } +} - icacls $root\artifacts\ /grant "IIS_IUSRS:(OI)(CI)F" +if ($NoUnitTests -ne $true) { + Run-Command "unit tests" { + dotnet test src/DotVVM.Framework.Tests ` + --no-build ` + --configuration $Config ` + --logger trx ` + --results-directory $testResultsDir ` + --collect "Code Coverage" + } +} - New-IISSite -Name dotvvm.owin ` - -PhysicalPath $root\artifacts\DotVVM.Samples.BasicSamples.Owin ` - -BindingInformation "*:5407:" +if ($noUITests -ne $true) { + Run-Command "UI tests" { + Import-Module IISAdministration + Clean-UITest - New-IISSite -Name dotvvm.owin.api ` - -PhysicalPath $root\artifacts\DotVVM.Samples.BasicSamples.Api.Owin ` - -BindingInformation "*:61453:" + icacls $Root\artifacts\ /grant "IIS_IUSRS:(OI)(CI)F" - Copy-Item -Force -Recurse ` - $root\src\DotVVM.Samples.Common ` - $root\artifacts + New-IISSite -Name dotvvm.owin ` + -PhysicalPath $Root\artifacts\DotVVM.Samples.BasicSamples.Owin ` + -BindingInformation "*:5407:" - Copy-Item -Force ` - $root\src\DotVVM.Samples.Tests\Profiles\seleniumconfig.owin.chrome.json ` - $root\src\DotVVM.Samples.Tests\seleniumconfig.json + New-IISSite -Name dotvvm.owin.api ` + -PhysicalPath $Root\artifacts\DotVVM.Samples.BasicSamples.Api.Owin ` + -BindingInformation "*:61453:" - dotnet test $root\src\DotVVM.Samples.Tests ` - --configuration $configuration ` - --logger trx ` - --results-directory $testResultsDir + Copy-Item -Force -Recurse ` + $Root\src\DotVVM.Samples.Common ` + $Root\artifacts - Clean-UITest + dotnet test $Root\src\DotVVM.Samples.Tests ` + --configuration $Config ` + --logger trx ` + --results-directory $testResultsDir - Get-Process + Clean-UITest + } } diff --git a/ci/windows/test.ps1 b/ci/windows/test.ps1 new file mode 100644 index 0000000000..9475bfc7d3 --- /dev/null +++ b/ci/windows/test.ps1 @@ -0,0 +1 @@ +docker run --rm -it --mount "type=bind,src=${PWD},dst=C:\s" docker-reg.riganti.cz/docker-agent:latest-windows powershell