Skip to content
This repository was archived by the owner on Apr 8, 2019. It is now read-only.

Commit cdc0c8e

Browse files
committed
Updated code coverage scripting
1 parent 8595c2a commit cdc0c8e

File tree

6 files changed

+137
-28
lines changed

6 files changed

+137
-28
lines changed

.nuget/packages.config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Codecov" version="1.0.1" />
4-
<package id="OpenCover" version="4.6.247-rc" />
3+
<package id="Codecov" version="1.1.0" />
4+
<package id="Microsoft.DiaSymReader.Pdb2Pdb" version="1.1.0-beta1-62624-01" />
5+
<package id="OpenCover" version="4.6.519" />
56
<package id="ReportGenerator" version="2.3.5.0" targetFramework="net452" />
67
<package id="xunit.runner.console" version="2.1.0" targetFramework="net452" />
78
</packages>

NuGet.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<add key="symreader-converter" value="https://dotnet.myget.org/F/symreader-converter/api/v3/index.json" />
5+
</packageSources>
6+
</configuration>

PublicApiAnalyzer/Directory.Build.props

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,8 @@
2323
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
2424
</PropertyGroup>
2525

26-
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
27-
<DebugType>full</DebugType>
28-
<DebugSymbols>true</DebugSymbols>
29-
</PropertyGroup>
30-
31-
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
32-
<DebugType>pdbonly</DebugType>
26+
<PropertyGroup>
27+
<DebugType>portable</DebugType>
3328
<DebugSymbols>true</DebugSymbols>
3429
</PropertyGroup>
3530

appveyor.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,34 @@ version: 1.0.{build}
22
os: Visual Studio 2017
33
init:
44
- git config --global core.autocrlf true
5+
configuration:
6+
- Debug
7+
- Release
58
before_build:
69
- nuget restore
10+
skip_tags: true
711
build:
812
project: PublicApiAnalyzer.sln
913
verbosity: minimal
1014
test_script:
11-
- .\packages\OpenCover.4.6.247-rc\tools\OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:"C:\projects\publicapianalyzer\PublicApiAnalyzer\PublicApiAnalyzer.Test\bin\Debug\net452\PublicApiAnalyzer.Test.dll -noshadow -appveyor" -returntargetcode -filter:"+[PublicApi*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\PublicApiAnalyzer_coverage.xml
12-
- .\packages\Codecov.1.0.1\tools\codecov.exe -f "PublicApiAnalyzer_coverage.xml"
15+
- cd build
16+
- ps: |
17+
if ($env:Configuration -eq 'Debug') {
18+
.\opencover-report.ps1 -Debug -NoBuild -NoReport -AppVeyor
19+
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
20+
$packageConfig = [xml](Get-Content ..\.nuget\packages.config)
21+
$codecov_version = $packageConfig.SelectSingleNode('/packages/package[@id="Codecov"]').version
22+
$codecov = "..\packages\Codecov.$codecov_version\tools\codecov.exe"
23+
&$codecov -f '..\build\OpenCover.Reports\OpenCover.PublicApiAnalyzer.xml'
24+
} else {
25+
.\opencover-report.ps1 -NoBuild -NoReport -AppVeyor
26+
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
27+
}
1328
# preserve "packages" directory in the root of build folder but will reset it if packages.config is modified
1429
cache:
1530
- packages -> **\packages.config
31+
32+
# 'Release' is hard-coded to ensure VSIX and NuGet artifacts are only published for release configuration builds
1633
artifacts:
17-
- path: 'PublicApiAnalyzer\**\*.vsix'
18-
- path: 'PublicApiAnalyzer\**\*.nupkg'
34+
- path: 'PublicApiAnalyzer\PublicApiAnalyzer.Vsix\bin\Release\net452\*.vsix'
35+
- path: 'PublicApiAnalyzer\PublicApiAnalyzer.CodeFixes\bin\Release\*.nupkg'

build/opencover-report.ps1

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
param (
2-
[switch]$Debug
2+
[switch]$Debug,
3+
[switch]$NoBuild,
4+
[switch]$NoReport,
5+
[switch]$AppVeyor
36
)
47

5-
# Run a build to ensure everything is up-to-date
6-
If ($Debug) {
7-
.\build.ps1 -Debug -Incremental
8-
} Else {
9-
.\build.ps1 -Incremental
10-
}
8+
If (-not $NoBuild) {
9+
# Run a build to ensure everything is up-to-date
10+
If ($Debug) {
11+
.\build.ps1 -Debug -Incremental
12+
} Else {
13+
.\build.ps1 -Incremental
14+
}
1115

12-
If (-not $?) {
13-
$host.UI.WriteErrorLine('Build failed; coverage analysis aborted.')
14-
Exit $LASTEXITCODE
16+
If (-not $?) {
17+
$host.UI.WriteErrorLine('Build failed; coverage analysis aborted.')
18+
Exit $LASTEXITCODE
19+
}
1520
}
1621

1722
If ($Debug) {
@@ -24,31 +29,93 @@ $packageConfig = [xml](Get-Content ..\.nuget\packages.config)
2429
$opencover_version = $packageConfig.SelectSingleNode('/packages/package[@id="OpenCover"]').version
2530
$reportgenerator_version = $packageConfig.SelectSingleNode('/packages/package[@id="ReportGenerator"]').version
2631
$xunitrunner_version = $packageConfig.SelectSingleNode('/packages/package[@id="xunit.runner.console"]').version
32+
$pdb2pdb_version = $packageConfig.SelectSingleNode('/packages/package[@id="Microsoft.DiaSymReader.Pdb2Pdb"]').version
2733

2834
$packages_folder = '..\packages'
2935
$opencover_console = "$packages_folder\OpenCover.$opencover_version\tools\OpenCover.Console.exe"
3036
$xunit_runner_console = "$packages_folder\xunit.runner.console.$xunitrunner_version\tools\xunit.console.x86.exe"
3137
$report_generator = "$packages_folder\ReportGenerator.$reportgenerator_version\tools\ReportGenerator.exe"
38+
$pdb2pdb = "$packages_folder\Microsoft.DiaSymReader.Pdb2Pdb.$pdb2pdb_version\tools\Pdb2Pdb.exe"
3239
$report_folder = '.\OpenCover.Reports'
33-
$target_dll = "..\PublicApiAnalyzer\PublicApiAnalyzer.Test\bin\$Configuration\PublicApiAnalyzer.Test.dll"
40+
$symbols_folder = '.\OpenCover.Symbols'
41+
$target_dll = "..\PublicApiAnalyzer\PublicApiAnalyzer.Test\bin\$Configuration\net452\PublicApiAnalyzer.Test.dll"
42+
43+
If (Test-Path $symbols_folder) {
44+
Remove-Item -Recurse -Force $symbols_folder
45+
}
46+
47+
mkdir $symbols_folder | Out-Null
48+
49+
function Convert-Coverage-Pdb() {
50+
param (
51+
[string]$assembly,
52+
[string]$outputDir
53+
)
54+
$sourceDir = [IO.Path]::GetDirectoryName($assembly)
55+
$outputName = [IO.Path]::ChangeExtension([IO.Path]::GetFileName($assembly), 'pdb')
56+
$sourcePdb = Join-Path $sourceDir $outputName
57+
$output = Join-Path $outputDir $outputName
58+
if (Test-Path $sourcePdb) {
59+
&$pdb2pdb $assembly /out $output
60+
61+
# Workaround for https://github.com/OpenCover/opencover/issues/800
62+
Remove-Item $sourcePdb
63+
Copy-Item $assembly $outputDir
64+
}
65+
}
66+
67+
function Extract-Coverage-Pdb() {
68+
param (
69+
[string]$assembly,
70+
[string]$outputDir
71+
)
72+
$sourceDir = [IO.Path]::GetDirectoryName($assembly)
73+
$outputName = [IO.Path]::ChangeExtension([IO.Path]::GetFileName($assembly), 'pdb')
74+
$intermediatePdb = Join-Path $sourceDir $outputName
75+
$output = Join-Path $outputDir $outputName
76+
if (-not (Test-Path $output)) {
77+
&$pdb2pdb $assembly /out $intermediatePdb /extract
78+
if (Test-Path $intermediatePdb) {
79+
&$pdb2pdb $assembly /pdb $intermediatePdb /out $output
80+
Remove-Item $intermediatePdb
81+
82+
# Workaround for https://github.com/OpenCover/opencover/issues/800
83+
Copy-Item $assembly $outputDir
84+
}
85+
}
86+
}
87+
88+
$target_dir = [IO.Path]::GetDirectoryName($target_dll)
89+
Get-ChildItem $target_dir -Filter *.dll | Foreach-Object { Convert-Coverage-Pdb -assembly $_.FullName -outputDir $symbols_folder }
3490

3591
If (Test-Path $report_folder) {
3692
Remove-Item -Recurse -Force $report_folder
3793
}
3894

3995
mkdir $report_folder | Out-Null
4096

97+
If ($AppVeyor) {
98+
$AppVeyorArg = '-appveyor'
99+
}
100+
41101
&$opencover_console `
42102
-register:user `
43-
-threshold:1 `
44103
-returntargetcode `
45104
-hideskipped:All `
46105
-filter:"+[PublicApi*]*" `
47106
-excludebyattribute:*.ExcludeFromCodeCoverage* `
107+
-excludebyfile:*\*Designer.cs `
108+
-searchdirs:"$symbols_folder" `
48109
-output:"$report_folder\OpenCover.PublicApiAnalyzer.xml" `
49110
-target:"$xunit_runner_console" `
50-
-targetargs:"$target_dll -noshadow"
111+
-targetargs:"$target_dll -noshadow $AppVeyorArg"
51112

52-
&$report_generator -targetdir:$report_folder -reports:$report_folder\OpenCover.*.xml
113+
If ($AppVeyor -and -not $?) {
114+
$host.UI.WriteErrorLine('Build failed; coverage analysis aborted.')
115+
Exit $LASTEXITCODE
116+
}
53117

54-
$host.UI.WriteLine("Open $report_folder\index.htm to see code coverage results.")
118+
If (-not $NoReport) {
119+
&$report_generator -targetdir:$report_folder -reports:$report_folder\OpenCover.*.xml
120+
$host.UI.WriteLine("Open $report_folder\index.htm to see code coverage results.")
121+
}

codecov.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# https://docs.codecov.io/docs/codecov-yaml
2+
# https://github.com/codecov/support/wiki/Codecov-Yaml
3+
4+
coverage:
5+
status:
6+
project:
7+
default: false
8+
patch:
9+
default: false
10+
fixes:
11+
- "build/PublicApiAnalyzer/::PublicApiAnalyzer/"
12+
13+
comment:
14+
layout: "diff"
15+
16+
flags:
17+
production:
18+
paths:
19+
- PublicApiAnalyzer/PublicApiAnalyzer/
20+
- PublicApiAnalyzer/PublicApiAnalyzer.CodeFixes/
21+
test:
22+
paths:
23+
- PublicApiAnalyzer/PublicApiAnalyzer.Test/

0 commit comments

Comments
 (0)