From 59cbeb4557b90c1d34593fb1ae5ec3bae700ac55 Mon Sep 17 00:00:00 2001 From: Peter Hsu Date: Tue, 5 Jun 2018 13:08:13 -0700 Subject: [PATCH] Cleanup script to be run before CI workflow (#317) * Cleanup script to be run before CI workflow --- tools/ci_ensure_cleanup.ps1 | 34 ++++++++++++++++++++++++++++++++++ tools/install_sharedfx.ps1 | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tools/ci_ensure_cleanup.ps1 diff --git a/tools/ci_ensure_cleanup.ps1 b/tools/ci_ensure_cleanup.ps1 new file mode 100644 index 0000000..9fd4f20 --- /dev/null +++ b/tools/ci_ensure_cleanup.ps1 @@ -0,0 +1,34 @@ +# +# Copyright (c) .NET Foundation and contributors. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +<# +.SYNOPSIS + This script is run before each CI run to ensure things are properly cleaned up +.DESCRIPTION + This script is run before each CI run to ensure things are properly cleaned up +.PARAMETER dropLocation + +#> +$ErrorActionPreference = 'Stop' + +# If two tests are run too closely, VBCSCompiler process might still be alive for previous test preventing dotnet and packages to be cleand up +function KillVBCSCompilers() { + $procs = Get-WmiObject Win32_Process | Where-Object { $_.Name.ToLower().StartsWith("dotnet") -and $_.CommandLine.ToLower().Contains("vbcscompiler") } + foreach ($proc in $procs) { + Stop-Process -Id $proc.ProcessId -Force + } +} + +# Some failed test would actually cause appHost config file to become corrupted and w3svc would not be able to start +function EnsureAppHostConfig() { + $appConfigLocation = [System.IO.Path]::Combine($env:WinDir, "System32", "inetsrv", "config", "applicationHost.config") + if (!(Test-Path $appConfigLocation) -or ((Get-Item $appConfigLocation).Length -eq 0)) { + $appConfigBackupLocation = "${appConfigLocation}.ancmtest.masterbackup" + Copy-Item -Path $appConfigBackupLocation -Destination $appConfigLocation -Force + } +} + +KillVBCSCompilers +EnsureAppHostConfig diff --git a/tools/install_sharedfx.ps1 b/tools/install_sharedfx.ps1 index 72bb43d..a636f0a 100644 --- a/tools/install_sharedfx.ps1 +++ b/tools/install_sharedfx.ps1 @@ -22,7 +22,7 @@ param( [string] $dotnetHome = (Join-Path $env:USERPROFILE ".dotnet") ) - +$ErrorActionPreference = 'Stop' Import-Module -Name (Join-Path $PSScriptRoot versions.psm1) -Force function InstallDotnet([string] $arch) {