forked from microsoft/ApplicationInsights-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeCov.ps1
73 lines (63 loc) · 2.97 KB
/
CodeCov.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#Run code coverage tests to generate report
.\nuget.exe install "OpenCover" -Version "4.6.519"
$assemblies = get-childitem "..\bin\Release" -Filter *Tests.dll -Exclude *netcoreapp11.Tests.dll -recurse | foreach-object { $_.FullName }
foreach ($assembly in $assemblies)
{
Write-Host "==========================================="
Write-Host "Running tests for $assembly"
Write-Host "==========================================="
..\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe `
-register:user `
"-target:${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" `
"-targetargs:$assembly /logger:trx" `
"-filter:+[Microsoft.ApplicationInsights*]* +[Microsoft.AI*]* -[*Tests]* -[*TestFramework*]*" `
-hideskipped:All `
-output:.\coverage.xml `
-mergeoutput
}
$netcoreassemblies = get-childitem "..\bin\Release" -Filter *netcoreapp11.Tests.dll -recurse | foreach-object { $_.FullName }
foreach ($assembly in $netcoreassemblies)
{
Write-Host "==========================================="
Write-Host "Running tests for $assembly"
Write-Host "==========================================="
# Net Core tests should be run by a different version of vstest.console.exe
..\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe `
-register:user `
"-target:${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" `
"-targetargs:$assembly /logger:trx /Framework:FrameworkCore10" `
"-filter:+[Microsoft.ApplicationInsights*]* +[Microsoft.AI*]* -[*Tests]* -[*TestFramework*]*" `
-hideskipped:All `
-output:.\coverage.xml `
-mergeoutput
}
#Download report uploader
(New-Object System.Net.WebClient).DownloadFile("https://codecov.io/bash", ".\CodecovUploader.sh")
#On the Agent box repo is in a detached state. So get branchName by commit hash
$lastCommit = $(git rev-parse HEAD)
Write-Host "Last commit:" $lastCommit
$branchNames = $(git branch --all --contains $lastCommit)
Write-Host "All branches that have this commit:" $branchNames
$i=0
Foreach ($branchName in $branchNames)
{
$i++
# First element in the array is trash because repo is detached
if ($i -gt 1)
{
$branchName = $branchName.Trim()
# Check for what branches current commit (for which we have coverage) is the last commit
$lastCommitOnBranch = $(git rev-parse $branchName)
if ($lastCommitOnBranch -eq $lastCommit)
{
#Cut the prefix that CodeCov does not handle well
if ($branchName.StartsWith("remotes/origin/"))
{
$branchName = $branchName.Substring("remotes/origin/".Length)
}
Write-Host "We will upload report to:" $branchName
#Upload report
.\CodecovUploader.sh -f coverage.xml -t $env:CODECOVACCESSKEY -X gcov -B $branchName
}
}
}