Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix coverage reporting #1901

Merged
merged 10 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,26 @@ jobs:
./bin/smi/buildTestPackage.py \
${{ needs.init.outputs.build_ref }} \
"$cov"
- name: upload coverage
- name: upload coverage to codecov
if: ${{ matrix.os == 'linux' }}
uses: codecov/codecov-action@v4.5.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/coverage.cobertura.xml
directory: coverage/
fail_ci_if_error: true
- name: upload dist
- name: upload dist as artifact
uses: actions/upload-artifact@v4
with:
name: SmiServices-${{ needs.init.outputs.build_ref }}-smi-${{ matrix.os }}.zip
path: dist/${{ needs.init.outputs.build_ref }}/*
if-no-files-found: error
- name: upload coverage as artifact
if: ${{ matrix.os == 'linux' }}
uses: actions/upload-artifact@v4
with:
name: SmiServices-${{ needs.init.outputs.build_ref }}-smi-${{ matrix.os }}-coverage
path: coverage/*
if-no-files-found: error
ctp:
needs: [init]
strategy:
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<IsPublishable>false</IsPublishable>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<RunSettingsFilePath>$(MSBuildThisFileDirectory)\nunit.runsettings</RunSettingsFilePath>
<RuntimeIdentifiers>linux-x64;win-x64;osx-arm64</RuntimeIdentifiers>
<SatelliteResourceLanguages>none</SatelliteResourceLanguages>
<TargetFramework>net8.0</TargetFramework>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="CsvHelper" Version="33.0.1" />
<PackageVersion Include="Equ" Version="2.3.0" />
<PackageVersion Include="HIC.DicomTypeTranslation" Version="4.1.3" />
Expand All @@ -32,6 +31,7 @@
<!-- Test Packages -->
<PackageVersion Include="HIC.BadMedicine.Dicom" Version="0.1.0" />
<PackageVersion Include="HIC.RDMP.Plugin.Test" Version="8.2.3" />
<PackageVersion Include="Microsoft.CodeCoverage" Version="17.10.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="NUnit" Version="4.1.0" />
Expand Down
2 changes: 0 additions & 2 deletions PACKAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
| Package | Source Code | License | Purpose |
| --------------------------------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| CommandLineParser | [GitHub](https://github.com/commandlineparser/commandline) | [MIT](https://opensource.org/licenses/MIT) | Command line argument parsing |
| coveralls.io | [GitHub](https://github.com/coveralls-net/coveralls.net) | [GNU](https://github.com/coveralls-net/coveralls.net#license) | Uploader for dot net coverage reports to Coveralls.io |
| CsvHelper | [GitHub](https://github.com/JoshClose/CsvHelper) | [MS-PL and Apache 2.0](https://github.com/JoshClose/CsvHelper/blob/master/LICENSE.txt) | Writing reports out to CSV reports |
| Equ | [GitHub](https://github.com/thedmi/Equ) | [MIT](https://opensource.org/licenses/MIT) | Automatic equality functions |
| fo-dicom.Drawing | [GitHub](https://github.com/fo-dicom/fo-dicom) | [MS-PL](https://opensource.org/licenses/MS-PL) | Support library for reading DICOM pixel data |
Expand All @@ -24,7 +23,6 @@
| Microsoft.Extensions.Caching.Memory | [GitHub](https://github.com/dotnet/extensions) | [Apache 2.0](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Memory/3.1.7/License) | Caching ID mappings retrieved from Redis/MySQL |
| Newtonsoft.Json | [GitHub](https://github.com/JamesNK/Newtonsoft.Json) | [MIT](https://opensource.org/licenses/MIT) | Serialization of objects for sharing/transmission |
| NLog | [GitHub](https://github.com/NLog/NLog) | [BSD 3-Clause](https://github.com/NLog/NLog/blob/dev/LICENSE.txt) | Flexible user configurable logging |
| OpenCover | [GitHub](https://github.com/OpenCover/opencover) | [MIT Compatible](https://github.com/OpenCover/opencover/blob/master/LICENSE) | Calculates code coverage for tests |
| RabbitMQ.Client | [GitHub](https://github.com/rabbitmq/rabbitmq-dotnet-client) | [Apache License v2 / MPL 1.1](https://github.com/rabbitmq/rabbitmq-dotnet-client/blob/main/LICENSE) | Handles messaging between microservices |
| StackExchange.Redis | [GitHub](https://github.com/StackExchange/StackExchange.Redis) | [MIT](https://opensource.org/licenses/MIT) | Required for RedisSwapper |
| Stanford.NLP.CoreNLP | [GitHub Pages](https://sergey-tihon.github.io/Stanford.NLP.NET/) | [GNU v2](https://github.com/sergey-tihon/Stanford.NLP.NET/blob/master/LICENSE.txt) | Name / Organisation detection in text |
Expand Down
84 changes: 15 additions & 69 deletions bin/smi/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,6 @@
import downloadTessdata


_COV_DIR = C.PROJ_ROOT / "coverage"


def _run_csproj_tests(
csproj: Path,
configuration: str,
no_build: bool,
coverage: bool,
*args: str
) -> None:

cov_json = _COV_DIR / "coverage.json"

cov_params = ()
if coverage:
cov_params = (
"/p:CollectCoverage=true",
f'/p:CoverletOutput="{_COV_DIR.resolve()}/"',
f'/p:MergeWith="{cov_json.resolve()}"',
'/p:Exclude="[*.Tests]*"',
)

cmd = (
"dotnet",
"test",
"--configuration", configuration,
"--settings", (C.PROJ_ROOT / "data/nunit.runsettings").resolve(),
"--no-build" if no_build else "",
csproj,
*cov_params,
*args,
)
C.run(cmd)


def main(argv: Optional[Sequence[str]] = None) -> int:

parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -100,44 +65,25 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
except FileExistsError:
pass

cov_dir = C.PROJ_ROOT / "coverage"
if not args.no_coverage:
if _COV_DIR.is_dir():
shutil.rmtree(_COV_DIR)
_COV_DIR.mkdir()

test_csprojs = [
Path(x).resolve() for x in
glob.glob(f"{C.PROJ_ROOT}/tests/**/*.csproj", recursive=True)
]
if cov_dir.is_dir():
shutil.rmtree(cov_dir)

test_cmd = ("--filter", args.test[0]) if args.test else ()
cmd = ("dotnet", "tool", "restore")
C.run(cmd)

have_failures = False
for csproj in test_csprojs[:-1]:
try:
_run_csproj_tests(
csproj,
args.configuration,
args.no_build,
not args.no_coverage,
*test_cmd
)
except subprocess.CalledProcessError:
have_failures = True

# NOTE(rkm 2021-06-01) Run last test with additional option to generate merged opencover file
_run_csproj_tests(
test_csprojs[-1],
args.configuration,
args.no_build,
not args.no_coverage,
'/p:CoverletOutputFormat="cobertura"' if not args.no_coverage else "",
*test_cmd,
f = ("--filter", args.test[0]) if args.test else ""
cmd = (
"dotnet", "dotnet-coverage", "collect",
"--settings", "coverage.settings",
"--",
"dotnet", "test",
"--configuration", args.configuration,
"--no-build" if args.no_build else "",
*f,
)

if have_failures:
print("Error: At least one test suite failed", file=sys.stderr)
return 1
C.run(cmd)

return 0

Expand Down
5 changes: 5 additions & 0 deletions coverage.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<Format>cobertura</Format>
<CoverageFileName>coverage/cobertura.xml</CoverageFileName>
</Configuration>
13 changes: 13 additions & 0 deletions dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-coverage": {
"version": "17.11.3",
"commands": [
"dotnet-coverage"
],
"rollForward": false
}
}
}
1 change: 1 addition & 0 deletions news/1901-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch coverage collection from coverlet.msbuild to Microsoft.CodeCoverage and dotnet-coverage
File renamed without changes.
9 changes: 5 additions & 4 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"/>
<ItemGroup>
<PackageReference Include="coverlet.msbuild">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeCoverage"/>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="NUnit"/>
<PackageReference Include="NUnit3TestAdapter">
Expand All @@ -17,4 +14,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<EnableStaticNativeInstrumentation>False</EnableStaticNativeInstrumentation>
<EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation>
</PropertyGroup>
</Project>
Loading