зеркало из https://github.com/aspnet/MusicStore.git
Scripts to run tests remotely
This commit is contained in:
Родитель
b7f4058c28
Коммит
7839b80f04
|
@ -12,6 +12,7 @@
|
|||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { }
|
||||
"dnx451": { },
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
@Echo off
|
||||
|
||||
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0RemoteTest.ps1' %*"
|
|
@ -0,0 +1,40 @@
|
|||
param(
|
||||
[string] $server = $env:TEST_SERVER,
|
||||
[string] $userName = $env:TEST_SERVER_USER,
|
||||
[string] $password = $env:TEST_SERVER_PASS,
|
||||
[string] $serverFolder = "dev"
|
||||
)
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$projectFile = "MusicStore.Test\project.json"
|
||||
|
||||
Write-Host "Test server: $server"
|
||||
Write-Host "Test folder: $serverFolder"
|
||||
|
||||
$projectName = (get-item $projectFile).Directory.Name
|
||||
Write-Host "Test project: $projectName"
|
||||
|
||||
Invoke-Expression "..\tools\BundleAndDeploy.ps1 -projectFile $projectFile -server $server -serverFolder $serverFolder -userName $userName -password $password"
|
||||
|
||||
$pass = ConvertTo-SecureString $password -AsPlainText -Force
|
||||
$cred = New-Object System.Management.Automation.PSCredential ($userName, $pass);
|
||||
|
||||
Set-Item WSMan:\localhost\Client\TrustedHosts "$server" -Force
|
||||
|
||||
#This block of code will be executed remotely
|
||||
$remoteScript = {
|
||||
$ErrorActionPreference = "Continue"
|
||||
cd C:\$using:serverFolder\$using:projectName
|
||||
dir
|
||||
$env:DNX_TRACE=1
|
||||
$testResult = & .\test.cmd 2>&1
|
||||
$testResult
|
||||
}
|
||||
|
||||
Write-Host ">>>> Remote code execution started <<<<"
|
||||
$result = Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock $remoteScript
|
||||
$result
|
||||
Write-Host "<<<< Remote execution code completed >>>>"
|
||||
|
||||
$testExitCode = $result[$result.length-1];
|
||||
exit $testExitCode
|
|
@ -0,0 +1,3 @@
|
|||
@Echo off
|
||||
|
||||
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0BundleAndDeploy.ps1' %*"
|
|
@ -0,0 +1,89 @@
|
|||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $projectFile,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $server,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $serverFolder,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $userName,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $password,
|
||||
[bool] $remoteInvoke = $false
|
||||
)
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function UpdateHostInProjectJson($projectFile, $newhost)
|
||||
{
|
||||
(Get-Content $projectFile) |
|
||||
Foreach-Object {
|
||||
$_ -replace "http://localhost", "http://$newhost"
|
||||
} |
|
||||
Set-Content $projectFile
|
||||
}
|
||||
|
||||
if (-not (Test-Path $projectFile)) {
|
||||
Write-Error "Couldn't find $projectFile"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$projectName = (get-item $projectFile).Directory.Name
|
||||
$workDir = (get-item $projectFile).Directory.FullName
|
||||
$remoteRoot = "\\" + $server
|
||||
$remoteDir = Join-Path $remoteRoot -ChildPath $serverFolder
|
||||
|
||||
try
|
||||
{
|
||||
if ($userName) {
|
||||
net use $remoteRoot $password /USER:$userName
|
||||
if ($lastexitcode -ne 0) {
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
if (-not (Test-Path $remoteDir)) {
|
||||
Write-Error "Remote directory $remoteDir does not exist or it is not accessible"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$packDir = Join-Path $workDir -ChildPath "bin\output"
|
||||
if (Test-Path $packDir) {
|
||||
Write-Host "$packDir already exists. Removing it..."
|
||||
rmdir -Recurse "$packDir"
|
||||
}
|
||||
|
||||
Write-Host "Bundling the application..."
|
||||
cd "$workDir"
|
||||
dnvm use default -r CoreCLR -arch x64
|
||||
dnu publish --runtime active
|
||||
if ($lastexitcode -ne 0) {
|
||||
Write-Error "Failed to bundle the application"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($remoteInvoke) {
|
||||
$packedProjectJsonFile = Join-Path $packDir -ChildPath "approot\src\$projectName\project.json"
|
||||
Write-Host "Setting host to $server in $packedProjectJsonFile"
|
||||
if (-not (Test-Path $packedProjectJsonFile)) {
|
||||
Write-Error "Couldn't find $packedProjectJsonFile"
|
||||
exit 1
|
||||
}
|
||||
|
||||
UpdateHostInProjectJson $packedProjectJsonFile $server
|
||||
}
|
||||
|
||||
$destDir = Join-Path $remoteDir -ChildPath $projectName
|
||||
if (Test-Path $destDir) {
|
||||
Write-Host "$destDir already exists. Removing it..."
|
||||
rmdir -Recurse "$destDir"
|
||||
}
|
||||
|
||||
Write-Host "Copying bundled application to $destDir ..."
|
||||
Copy-Item "$packDir" -Destination "$destDir" -Recurse
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ($userName -and $remoteRoot) {
|
||||
net use $remoteRoot /delete
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче