Skip to content

Commit

Permalink
Appveyor updates (#43)
Browse files Browse the repository at this point in the history
* Properly handles errors during build/test, so that AppVeyor recognizes an error
* Dynamically creates a Relay namespace for each test run
* Uses PowerShell functions instead of inline AppVeyor scripts
  • Loading branch information
jtaubensee authored Jan 18, 2017
1 parent b4b6ad0 commit 1583957
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 38 deletions.
45 changes: 16 additions & 29 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
version: 1.0.{build}
environment:
RELAYCONNECTIONSTRING:
secure: 4yWgjKkxdBsqrE2LHex9vF5c4SW0W+ELgzuCpGzhFywKziZ/4VpzNu2kAWTPGKWMZxmfZqfipCIrXa+2PecqHQF79ihsdyu7etVDUhk4n72F8QhLBQ8k7/Ln7+rfMK8viNE6WHxubjFGTGxCLGY/67EFpM6N8qoqpSzDr5aV5zE0LaK14ACWdaOTMBKb61qkAIzX8RQiz+eRBpSi7VtBT1XIUOgfzS7Hr+mXrMtOaNs=
ClientSecret:
secure: /8H7C81iNS+gVi7LhJCEOPUlNaa30y4KcY4nw/g2C4HGxOv6SrcroyDvMnqD+5GN
TenantId:
secure: xohonz/X8PPLOVIdT3ch2C5XeSa30RwR6NuXFh4e85svXT1mJNGGO1HQEGxCk3wp
AppId:
secure: c+H140oRJfHtmFHZxSRLWocv5AU0q33X7kgMcTcXxhJvtVhk2WAk1dRQkSN+SyoA
before_build:
- ps: >-
. .\build\AppveyorBuildFunctions.ps1
build_script:
- cmd: >-
dotnet restore
dotnet build src/Microsoft.Azure.Relay/project.json
dotnet build test/Microsoft.Azure.Relay.UnitTests/project.json
- ps: >-
Build-Solution
before_test:
- cmd: >-
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\sn.exe" -Vr *,31bf3856ad364e35
- ps: >-
$xUnitConfig = "
{
`"parallelizeAssembly`": false,
`"parallelizeTestCollections`": false
}"
New-Item test/Microsoft.Azure.Relay.UnitTests/bin/debug/netcoreapp1.0/xunit.runner.json -type file -force -value $xUnitConfig
New-Item test/Microsoft.Azure.Relay.UnitTests/bin/Debug/net46/win7-x64/xunit.runner.json -type file -force -value $xUnitConfig
Deploy-AzureResources
test_script:
- ps: >-
if ([bool]$env:RELAYCONNECTIONSTRING)
{
Write-Host "Running unit tests."
dotnet test test/Microsoft.Azure.Relay.UnitTests/project.json
}
else
{
Write-Host "No environment variables present. Skipping unit tests."
}
Run-UnitTests
after_test:
- ps: >-
Delete-AzureResources
130 changes: 130 additions & 0 deletions build/AppveyorBuildFunctions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
function Build-Solution
{
Write-Host "Building Relay projects"

dotnet restore

# $? Returns True or False value indicating whether previous command ended with an error.
# This is used to throw an error that will cause the AppVeyor process to fail as expected.
if (-not $?)
{
throw "Package restore failed."
}

dotnet build src/Microsoft.Azure.Relay/project.json

if (-not $?)
{
throw "Microsoft.Azure.Relay build failed."
}

dotnet build test/Microsoft.Azure.Relay.UnitTests/project.json

if (-not $?)
{
throw "Microsoft.Azure.Relay.UnitTests build failed."
}
else
{
Write-Host "Building complete."
}
}

function Deploy-AzureResources
{
if ([bool]$env:ClientSecret `
-and [bool]$env:TenantId `
-and [bool]$env:AppId `
-and [bool]$env:APPVEYOR_BUILD_NUMBER)
{
Write-Host "Creating Azure resources"

$ErrorActionPreference = 'Stop'
Enable-AzureDataCollection -WarningAction SilentlyContinue | Out-Null
$BuildVersion = ($env:APPVEYOR_BUILD_NUMBER).Replace(".", "")

$env:ResourceGroupName = "relay-dotnet-av-$BuildVersion-rg"
$NamespaceName = "relay-dotnet-av-$BuildVersion-ns"
$Location = 'westus'

$Password = ConvertTo-SecureString -AsPlainText -Force $env:ClientSecret
$Credentials = New-Object `
-TypeName System.Management.Automation.PSCredential `
-ArgumentList $env:AppId, $Password

# https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authenticate-service-principal
Add-AzureRmAccount -Credential $Credentials -ServicePrincipal -TenantId $env:TenantId | Out-Null

$ResourceGroup = New-AzureRmResourceGroup -Name $env:ResourceGroupName -Location $Location -Force -WarningAction SilentlyContinue
Write-Host ("Resource group name: " + $ResourceGroup.ResourceGroupName)

$ArmParameters = @{
namespaceName = $NamespaceName;
}

$TemplatePath = "$((Get-Location).path)\templates\azuredeploy.json"

$settings = New-AzureRmResourceGroupDeployment `
-ResourceGroupName $env:ResourceGroupName `
-TemplateFile $TemplatePath `
-TemplateParameterObject $ArmParameters `
-Force `
-WarningAction SilentlyContinue

Write-Host "Relay namespace: $NamespaceName"

$ConnectionString = $settings.Outputs.Get_Item("namespaceConnectionString").Value
[Environment]::SetEnvironmentVariable('RELAYCONNECTIONSTRING', $ConnectionString)

Write-Host "Completed creating Azure resources"
}
else
{
Write-Host "No environment variables present. Skipping Azure deployment."
}

# Useful for debugging ARM deployments
# Get-AzureRmLog -CorrelationId "GUID" -DetailedOutput
}

function Run-UnitTests
{
if ([bool][Environment]::GetEnvironmentVariable('RELAYCONNECTIONSTRING'))
{
Write-Host "Running unit tests."

dotnet test test/Microsoft.Azure.Relay.UnitTests/project.json

if (-not $?)
{
throw "Unit tests failed."
}
}
else
{
Write-Host "Connection string environment variable not present. Skipping unit tests."
}
}

function Delete-AzureResources
{
if ([bool]$env:ClientSecret -and [bool]$env:AppId)
{
Write-Host "Deleting Azure resources"

$ErrorActionPreference = 'Stop'

$Password = ConvertTo-SecureString -AsPlainText -Force $env:ClientSecret
$Credentials = New-Object `
-TypeName System.Management.Automation.PSCredential `
-ArgumentList $env:AppId, $Password

Remove-AzureRmResourceGroup -Name $env:ResourceGroupName -WarningAction SilentlyContinue -Force | Out-Null

Write-Host "Completed deleting Azure resources"
}
else
{
Write-Host "No environment variables present. Skipping Azure resource deletion"
}
}
9 changes: 0 additions & 9 deletions templates/azuredeploy.parameters.json

This file was deleted.

0 comments on commit 1583957

Please sign in to comment.