From b9393795a79a2e41d28586e5f2faeebe1824bf0b Mon Sep 17 00:00:00 2001 From: Jahav Date: Wed, 29 Nov 2017 00:32:34 +0100 Subject: [PATCH 1/8] Add cover report generation for .NET Core .NET Core has worse tool support than .NET Framework and requires few different steps. --- README.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3594e34..431eb06 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,11 @@ choco install opencover.portable the OpenCover commandline will become available. -### xUnit +Generation of coverage report is slighly different depending on the .NET platform of your test projects. + +### .NET Framework project + +#### xUnit First install the xUnit console runner via [Nuget](https://www.nuget.org/packages/xunit.runner.console/2.3.0-beta1-build3642) or [Chocolatey](https://chocolatey.org/packages/XUnit). If we run the following in PowerShell to install xUnit via Chocolatey @@ -36,7 +40,7 @@ OpenCover.Console.exe -register:user -target:"xunit.console.x86.exe" -targetargs Then a coverage report will be generated. -### MSTest +#### MSTest Execute the following in your solution's root, @@ -46,6 +50,29 @@ OpenCover.Console.exe -register:user -target:"C:\Program Files (x86)\Microsoft V where you may need to change the `-target` flag to point to the correct version of MSTest. + +### .NET Core project + +If you don't yet have .NET Core SDK installed, install it + +```powershell +choco install dotnetcore-sdk +``` + +In case of .NET Core projects, there is no difference between `MSTest` and `xUnit` for coverage report generation. + +Make sure all covered projects generate full pdb file (not only test projects), either through `full` in the `.csproj` file or by using a Visual Studio: Project Properties > Build > Advanced > Debugging information. By default, projects created by `dotnet` or by Visual Studio use a portable format for pdb files. Support for portable pdb format [hasn't been released in OpenCover yet](https://github.com/OpenCover/opencover/issues/610). If you fail to set full pdb, the `OpenCover` will print out a message notifying you that it has no results along with common causes. + +The .NET Core test assembly can't be run by a `xunit.console.x86.exe`, because that tool works only with .NET Framework assemblies. The tests are run by `dotnet test` (possibly `dotnet xunit` if you [add dotnet-xunit](https://xunit.github.io/docs/getting-started-dotnet-core.html#create-project) CLI tool to your project). + +Execute the following command in your solution's root: + +```powershell +OpenCover.Console.exe -register:user -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:test -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml" -oldstyle +``` + +where `-oldstyle` switch is necessary, because .NET Core uses `System.Private.CoreLib` instead of `mscorlib` and thus `OpenCover` can't use `mscorlib` for code instrumentation. You may also need to change the location of `dotnet.exe` to depending on the installed location. + ## Uploading Report Many options exit for uploading reports to Codecov. Three commonly used uploaders for .NET are From 184273545db185554bea5c986eae2ef1b7cad850 Mon Sep 17 00:00:00 2001 From: Thomas Pedbereznak Date: Thu, 26 Apr 2018 10:31:46 +0200 Subject: [PATCH 2/8] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 431eb06..8e4089f 100644 --- a/README.md +++ b/README.md @@ -193,3 +193,5 @@ If you use [Cake](http://cakebuild.net/) (C# Make) for your build automation, th ## Sample Project An example C# project using AppVeyor, xUnit, OpenCover, and Codecov-exe is [DotNetAnalyzers/StyleCopAnalyzers](https://github.com/DotNetAnalyzers/StyleCopAnalyzers). + +We are happy to help if you have any questions. Please contact email our Support at [support@codecov.io](mailto:support@codecov.io) From e09d29642a015a5b89e559e2394c76e88b42100a Mon Sep 17 00:00:00 2001 From: AraHaan Date: Fri, 14 Sep 2018 11:12:09 -0400 Subject: [PATCH 3/8] Update MyTargetClassTests.cs --- MyUnitTests/MyTargetClassTests.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/MyUnitTests/MyTargetClassTests.cs b/MyUnitTests/MyTargetClassTests.cs index cfe9454..b9f0601 100644 --- a/MyUnitTests/MyTargetClassTests.cs +++ b/MyUnitTests/MyTargetClassTests.cs @@ -24,5 +24,19 @@ public void VerifySubtraction() var intResult = objTargetClass.SubractNumbers(intFirstNumber, intsecondNumber); Assert.Equal(15 - 10, intResult); } + + [Fact] + public void VerifyDivision() + { + const int intFirstNumber = 15; + const int intsecondNumber = 10; + var objTargetClass = new MyTargetClass(); + + // in this though there seems to be some data loss. + var intResult = objTargetClass.DivideNumbers(intFirstNumber, intsecondNumber); + + // ensure this is always a int. + Assert.Equal((int)(15 / 10), intResult); + } } -} \ No newline at end of file +} From 668da25c4a16e775bf17915dfedece6d2585036c Mon Sep 17 00:00:00 2001 From: Jaxel Rojas Date: Thu, 29 Nov 2018 22:14:11 -0400 Subject: [PATCH 4/8] Update appveyor.yml Added missing quotation mark. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index f60a588..ed65b9a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,4 +11,4 @@ build: test_script: - OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\MyUnitTests\bin\Debug\MyUnitTests.dll -noshadow" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml" -- codecov -f "MyProject_coverage.xml \ No newline at end of file +- codecov -f "MyProject_coverage.xml" From 17fa35bf0ce68bad105c5020ac7ca64842924170 Mon Sep 17 00:00:00 2001 From: Paul Rohorzka Date: Sun, 16 Dec 2018 22:03:16 +0100 Subject: [PATCH 5/8] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e4089f..f748598 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ where `-oldstyle` switch is necessary, because .NET Core uses `System.Private.Co ## Uploading Report -Many options exit for uploading reports to Codecov. Three commonly used uploaders for .NET are +Many options exist for uploading reports to Codecov. Three commonly used uploaders for .NET are 1. [Codecov-exe](https://github.com/codecov/codecov-exe) (C# source code) 2. [Bash](https://github.com/codecov/codecov-bash) From c8c89edf7c14abe03836931fb9ca4079b29e2822 Mon Sep 17 00:00:00 2001 From: Thomas Hu Date: Tue, 4 Aug 2020 14:11:34 -0400 Subject: [PATCH 6/8] Update README --- README.md | 112 +++++++++++++++--------------------------------------- 1 file changed, 30 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index f748598..08e3953 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,28 @@ -# Codecov C# Example +# [Codecov](https://codecov.io) C# Example -| [https://codecov.io](https://codecov.io/) | [@codecov](https://twitter.com/codecov) | [hello@codecov.io](mailto:hello@codecov.io) | -| ----------------------- | ------------- | --------------------- | - -[![AppVeyor](https://img.shields.io/appveyor/ci/stevepeak/example-csharp.svg)](https://ci.appveyor.com/project/stevepeak/example-csharp/branch/master) [![codecov](https://codecov.io/gh/codecov/example-csharp/branch/master/graph/badge.svg)](https://codecov.io/gh/codecov/example-csharp) +[![AppVeyor](https://img.shields.io/appveyor/ci/stevepeak/example-csharp.svg)](https://ci.appveyor.com/project/stevepeak/example-csharp/branch/master) -## Solution +## Guide +### AppVeyor Setup +Add to your `appveyor.yml` file. +```yml +image: Visual Studio 2015 -Start by restoring the nuget packages and building the solution. +before_build: +- nuget restore +- choco install opencover.portable +- choco install codecov -## Generate the Coverage File +build: + project: CodecovProject.sln + verbosity: minimal +test_script: +- OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\MyUnitTests\bin\Debug\MyUnitTests.dll -noshadow" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml" +- codecov -f "MyProject_coverage.xml +``` +### Producing Coverage Reports Coverage is generated using [OpenCover](https://github.com/OpenCover/opencover). You can obtain it from [NuGet](https://www.nuget.org/packages/opencover) or [Chocolatey](https://chocolatey.org/packages/opencover.portable). If we run the following command in PowerShell to install OpenCover via Chocolatey, ```powershell @@ -22,9 +33,9 @@ the OpenCover commandline will become available. Generation of coverage report is slighly different depending on the .NET platform of your test projects. -### .NET Framework project +#### .NET Framework project -#### xUnit +##### xUnit First install the xUnit console runner via [Nuget](https://www.nuget.org/packages/xunit.runner.console/2.3.0-beta1-build3642) or [Chocolatey](https://chocolatey.org/packages/XUnit). If we run the following in PowerShell to install xUnit via Chocolatey @@ -40,7 +51,7 @@ OpenCover.Console.exe -register:user -target:"xunit.console.x86.exe" -targetargs Then a coverage report will be generated. -#### MSTest +##### MSTest Execute the following in your solution's root, @@ -51,7 +62,7 @@ OpenCover.Console.exe -register:user -target:"C:\Program Files (x86)\Microsoft V where you may need to change the `-target` flag to point to the correct version of MSTest. -### .NET Core project +#### .NET Core project If you don't yet have .NET Core SDK installed, install it @@ -73,34 +84,7 @@ OpenCover.Console.exe -register:user -target:"C:/Program Files/dotnet/dotnet.exe where `-oldstyle` switch is necessary, because .NET Core uses `System.Private.CoreLib` instead of `mscorlib` and thus `OpenCover` can't use `mscorlib` for code instrumentation. You may also need to change the location of `dotnet.exe` to depending on the installed location. -## Uploading Report - -Many options exist for uploading reports to Codecov. Three commonly used uploaders for .NET are - -1. [Codecov-exe](https://github.com/codecov/codecov-exe) (C# source code) -2. [Bash](https://github.com/codecov/codecov-bash) -3. [Python](https://github.com/codecov/codecov-python) - -For OS X and Linux builds, the recommended uploader is bash. For windows builds, all three uploaders work, but Codecov-exe does not require any dependencies. For example, the bash uploader and python uploader would require bash or python to be installed. This may or may not be an option. - -### Codecov-exe - -First install Codecov-exe via [Nuget](https://www.nuget.org/packages/Codecov/) or [Chocolatey](https://chocolatey.org/packages/codecov). If we run the following in PowerShell to install it via Chocolatey - -```powershell -choco install codecov -``` - -and then run the following in PowerShell - -``` -.\codecov -f "MyProject_coverage.xml" -t -``` - -the report will be uploaded. - ### Bash - In bash run the following to upload the report ```bash @@ -109,21 +93,6 @@ chmod +x codecov ./codecov -f "MyProject_coverage.xml" -t ``` -### Python - -First installed python (if you don't have it already). A simple way to install python is [Chocolatey](https://chocolatey.org/packages/python) - -```powershell -choco install python -``` - -Next run the following in PowerShell - -``` -pip install codecov -.\codecov -f "MyProject_coverage.xml" -t -``` - ### Continous Integration The previous examples assumed local development. More commonly, you'll use a CI service like [AppVeyor](https://www.appveyor.com/) or [TeamCity](https://www.jetbrains.com/teamcity/). For TeamCity builds please see the [documentation](https://github.com/codecov/codecov-exe#teamcity). For AppVeyor builds using xUnit, your yaml file would look something like @@ -166,32 +135,11 @@ test_script: - .\packages\\codecov.exe -f "MyProject_coverage.xml" ``` -#### Python - -```yaml -image: Visual Studio 2015 - -before_build: -- nuget restore -- choco install opencover.portable - -build: - project: CodecovProject.sln - verbosity: minimal - -test_script: -- OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\MyUnitTests\bin\Debug\MyUnitTests.dll -noshadow" -filter:"+[UnitTestTargetProject*]* -[MyUnitTests*]*" -output:".\MyProject_coverage.xml" -- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%" -- pip install codecov -- codecov -f "MyProject_coverage.xml" -``` - -## Cake.Codecov - -If you use [Cake](http://cakebuild.net/) (C# Make) for your build automation, there is a [Cake.Codecov](http://cakebuild.net/dsl/codecov/) addin available. Cake also has built in support for [OpenCover](http://cakebuild.net/dsl/opencover/). It makes using OpenCover and Codecov-exe really easy! - -## Sample Project - -An example C# project using AppVeyor, xUnit, OpenCover, and Codecov-exe is [DotNetAnalyzers/StyleCopAnalyzers](https://github.com/DotNetAnalyzers/StyleCopAnalyzers). +## Caveats +### Private Repo +Repository tokens are required for (a) all private repos, (b) public repos not using Travis-CI, CircleCI, GitHub Actions, or AppVeyor. Find your repository token at Codecov and provide via appending `-t ` to you where you upload reports e.g. `.\codecov -f "MyProject_coverage.xml" -t ` -We are happy to help if you have any questions. Please contact email our Support at [support@codecov.io](mailto:support@codecov.io) +## Links +- [Community Boards](https://community.codecov.io) +- [Support](https://codecov.io/support) +- [Documentation](https://docs.codecov.io) From 34c4a723300f3857c4777665e56a0d791dbc0e54 Mon Sep 17 00:00:00 2001 From: fossabot Date: Wed, 26 Aug 2020 18:20:10 -0500 Subject: [PATCH 7/8] Add license scan report and status Signed off by: fossabot --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 08e3953..29f8b4e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![codecov](https://codecov.io/gh/codecov/example-csharp/branch/master/graph/badge.svg)](https://codecov.io/gh/codecov/example-csharp) [![AppVeyor](https://img.shields.io/appveyor/ci/stevepeak/example-csharp.svg)](https://ci.appveyor.com/project/stevepeak/example-csharp/branch/master) +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-csharp.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-csharp?ref=badge_shield) ## Guide ### AppVeyor Setup @@ -143,3 +144,7 @@ Repository tokens are required for (a) all private repos, (b) public repos not u - [Community Boards](https://community.codecov.io) - [Support](https://codecov.io/support) - [Documentation](https://docs.codecov.io) + + +## License +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-csharp.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-csharp?ref=badge_large) \ No newline at end of file From db50cdf0e45d5406c5893f9fd34d12f7d75ee7f6 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Mon, 22 Jan 2024 12:30:32 -0800 Subject: [PATCH 8/8] chore(ci): add fossa workflow --- .github/workflows/enforce-license-compliance.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/enforce-license-compliance.yml diff --git a/.github/workflows/enforce-license-compliance.yml b/.github/workflows/enforce-license-compliance.yml new file mode 100644 index 0000000..86be741 --- /dev/null +++ b/.github/workflows/enforce-license-compliance.yml @@ -0,0 +1,14 @@ +name: Enforce License Compliance + +on: + pull_request: + branches: [main, master] + +jobs: + enforce-license-compliance: + runs-on: ubuntu-latest + steps: + - name: 'Enforce License Compliance' + uses: getsentry/action-enforce-license-compliance@57ba820387a1a9315a46115ee276b2968da51f3d # main + with: + fossa_api_key: ${{ secrets.FOSSA_API_KEY }}