-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from jakubch1/main
Native AOT example
- Loading branch information
Showing
10 changed files
with
287 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# This workflow will build a .NET project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | ||
|
||
name: "Algorithms Scenario 05" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Algorithms/src/**', '.github/workflows/Algorithms_Scenario05.yml' ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./samples/Algorithms/src/Algorithms.Console | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 8.0.x | ||
- name: Publish | ||
run: dotnet publish -r linux-x64 -c Release /p:AotMsCodeCoverageInstrumentation="true" | ||
- name: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Run | ||
run: dotnet-coverage collect --output $GITHUB_WORKSPACE/report.cobertura.xml --output-format cobertura ./bin/Release/net8.0/linux-x64/publish/Algorithms.Console | ||
- name: ReportGenerator | ||
uses: danielpalme/ReportGenerator-GitHub-Action@5.2.0 | ||
with: | ||
reports: '${{ github.workspace }}/report.cobertura.xml' | ||
targetdir: '${{ github.workspace }}/coveragereport' | ||
reporttypes: 'MarkdownSummaryGithub' | ||
- name: Upload coverage into summary | ||
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | ||
- name: Archive code coverage results | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: code-coverage-report | ||
path: ${{ github.workspace }}/report.cobertura.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Scenario Description | ||
|
||
Collect code coverage using `dotnet-coverage` tool for Native AOT console application. | ||
|
||
> **_NOTE:_** `Microsoft.CodeCoverage.MSBuild` package needs to be added as reference of console application. Remember to re-publish your application without coverage instrumentation before deploying to production. | ||
# Collect code coverage using command line | ||
|
||
```shell | ||
git clone https://github.com/microsoft/codecoverage.git | ||
cd codecoverage/samples/Algorithms/src/Algorithms.Console/ | ||
dotnet publish -r win-x64 -c Release /p:AotMsCodeCoverageInstrumentation="true" | ||
dotnet tool install -g dotnet-coverage | ||
dotnet-coverage collect --output report.cobertura.xml --output-format cobertura bin/Release/net8.0/win-x64/publish/Algorithms.Console.exe | ||
``` | ||
|
||
You can also use [run.ps1](run.ps1) to collect code coverage. | ||
|
||
# Collect code coverage inside github workflow | ||
|
||
`reportgenerator` can be used to generate final github summary markdown. | ||
|
||
```yml | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 8.0.x | ||
- name: Publish | ||
run: dotnet publish -r linux-x64 -c Release /p:AotMsCodeCoverageInstrumentation="true" | ||
- name: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Run | ||
run: dotnet-coverage collect --output $GITHUB_WORKSPACE/report.cobertura.xml --output-format cobertura ./bin/Release/net8.0/linux-x64/publish/Algorithms.Console | ||
- name: ReportGenerator | ||
uses: danielpalme/ReportGenerator-GitHub-Action@5.2.0 | ||
with: | ||
reports: '${{ github.workspace }}/report.cobertura.xml' | ||
targetdir: '${{ github.workspace }}/coveragereport' | ||
reporttypes: 'MarkdownSummaryGithub' | ||
- name: Upload coverage into summary | ||
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | ||
- name: Archive code coverage results | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: code-coverage-report | ||
path: ${{ github.workspace }}/report.cobertura.xml | ||
``` | ||
[Full source example](../../../../.github/workflows/Algorithms_Scenario05.yml) | ||
[Run example](../../../../../../actions/workflows/Algorithms_Scenario05.yml) | ||
# Collect code coverage inside Azure DevOps Pipelines | ||
```yml | ||
steps: | ||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'publish' | ||
publishWebProjects: false | ||
zipAfterPublish: false | ||
arguments: '-r linux-x64 -c Release /p:AotMsCodeCoverageInstrumentation="true"' | ||
projects: '$(projectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'publish' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'custom' | ||
custom: "tool" | ||
arguments: 'install -g dotnet-coverage' | ||
displayName: 'install dotnet-coverage' | ||
|
||
- task: Bash@3 | ||
inputs: | ||
targetType: 'inline' | ||
script: 'dotnet-coverage collect --output-format cobertura --output $(Agent.TempDirectory)/report.cobertura.xml ./samples/Algorithms/src/Algorithms.Console/bin/Release/net8.0/linux-x64/publish/Algorithms.Console' | ||
displayName: 'run' | ||
|
||
- task: PublishCodeCoverageResults@2 | ||
inputs: | ||
summaryFileLocation: $(Agent.TempDirectory)/**/*.cobertura.xml | ||
``` | ||
[Full source example](azure-pipelines.yml) | ||
![alt text](azure-pipelines.jpg "Code Coverage tab in Azure DevOps pipelines") | ||
# Report example | ||
![alt text](example.report.jpg "Example report") | ||
[Link](example.report.cobertura.xml) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions
34
samples/Algorithms/scenarios/scenario05/azure-pipelines.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: "Algorithms Scenario 05" | ||
|
||
pool: | ||
vmImage: 'ubuntu-latest' | ||
|
||
variables: | ||
projectPath: './samples/Algorithms/src/Algorithms.Console/Algorithms.Console.csproj' # this is specific to example - in most cases not needed | ||
|
||
steps: | ||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'publish' | ||
publishWebProjects: false | ||
zipAfterPublish: false | ||
arguments: '-r linux-x64 -c Release /p:AotMsCodeCoverageInstrumentation="true"' | ||
projects: '$(projectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'publish' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'custom' | ||
custom: "tool" | ||
arguments: 'install -g dotnet-coverage' | ||
displayName: 'install dotnet-coverage' | ||
|
||
- task: Bash@3 | ||
inputs: | ||
targetType: 'inline' | ||
script: 'dotnet-coverage collect --output-format cobertura --output $(Agent.TempDirectory)/report.cobertura.xml ./samples/Algorithms/src/Algorithms.Console/bin/Release/net8.0/linux-x64/publish/Algorithms.Console' | ||
displayName: 'run' | ||
|
||
- task: PublishCodeCoverageResults@2 | ||
inputs: | ||
summaryFileLocation: $(Agent.TempDirectory)/**/*.cobertura.xml |
77 changes: 77 additions & 0 deletions
77
samples/Algorithms/scenarios/scenario05/example.report.cobertura.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?xml version="1.0" encoding="utf-8" standalone="yes"?> | ||
<coverage line-rate="0.95" branch-rate="1" complexity="3" version="1.9" timestamp="1706778071" lines-covered="19" lines-valid="20"> | ||
<packages> | ||
<package line-rate="1" branch-rate="1" complexity="2" name="Algorithms.Console"> | ||
<classes> | ||
<class line-rate="1" branch-rate="1" complexity="2" name="Program" filename="/home/runner/work/codecoverage/codecoverage/samples/Algorithms/src/Algorithms.Console/Program.cs"> | ||
<methods> | ||
<method line-rate="1" branch-rate="1" complexity="1" name="<Main>$" signature="(string[])"> | ||
<lines> | ||
<line number="4" hits="1" branch="False" /> | ||
<line number="5" hits="1" branch="False" /> | ||
<line number="7" hits="1" branch="False" /> | ||
<line number="8" hits="1" branch="False" /> | ||
<line number="9" hits="1" branch="False" /> | ||
</lines> | ||
</method> | ||
<method line-rate="1" branch-rate="1" complexity="1" name="<<Main>$>g__Print|0_0" signature="(string, int[])"> | ||
<lines> | ||
<line number="13" hits="1" branch="False" /> | ||
<line number="14" hits="1" branch="False" /> | ||
</lines> | ||
</method> | ||
</methods> | ||
<lines> | ||
<line number="4" hits="1" branch="False" /> | ||
<line number="5" hits="1" branch="False" /> | ||
<line number="7" hits="1" branch="False" /> | ||
<line number="8" hits="1" branch="False" /> | ||
<line number="9" hits="1" branch="False" /> | ||
<line number="13" hits="1" branch="False" /> | ||
<line number="14" hits="1" branch="False" /> | ||
</lines> | ||
</class> | ||
</classes> | ||
</package> | ||
<package line-rate="0.9230769230769231" branch-rate="1" complexity="1" name="Algorithms.Core"> | ||
<classes> | ||
<class line-rate="0.9230769230769231" branch-rate="1" complexity="1" name="Algorithms.Core.Merger" filename="/home/runner/work/codecoverage/codecoverage/samples/Algorithms/src/Algorithms.Core/Merger.cs"> | ||
<methods> | ||
<method line-rate="0.9230769230769231" branch-rate="1" complexity="1" name="Merge" signature="(int[], int[])"> | ||
<lines> | ||
<line number="7" hits="1" branch="False" /> | ||
<line number="8" hits="1" branch="False" /> | ||
<line number="9" hits="1" branch="False" /> | ||
<line number="11" hits="1" branch="False" /> | ||
<line number="13" hits="1" branch="False" /> | ||
<line number="15" hits="1" branch="False" /> | ||
<line number="16" hits="1" branch="False" /> | ||
<line number="18" hits="1" branch="False" /> | ||
<line number="21" hits="1" branch="False" /> | ||
<line number="22" hits="0" branch="False" /> | ||
<line number="24" hits="1" branch="False" /> | ||
<line number="25" hits="1" branch="False" /> | ||
<line number="27" hits="1" branch="False" /> | ||
</lines> | ||
</method> | ||
</methods> | ||
<lines> | ||
<line number="7" hits="1" branch="False" /> | ||
<line number="8" hits="1" branch="False" /> | ||
<line number="9" hits="1" branch="False" /> | ||
<line number="11" hits="1" branch="False" /> | ||
<line number="13" hits="1" branch="False" /> | ||
<line number="15" hits="1" branch="False" /> | ||
<line number="16" hits="1" branch="False" /> | ||
<line number="18" hits="1" branch="False" /> | ||
<line number="21" hits="1" branch="False" /> | ||
<line number="22" hits="0" branch="False" /> | ||
<line number="24" hits="1" branch="False" /> | ||
<line number="25" hits="1" branch="False" /> | ||
<line number="27" hits="1" branch="False" /> | ||
</lines> | ||
</class> | ||
</classes> | ||
</package> | ||
</packages> | ||
</coverage> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cd $PSScriptRoot/../../src/Algorithms.Console | ||
dotnet publish -r win-x64 -c Release /p:AotMsCodeCoverageInstrumentation="true" | ||
dotnet tool install -g dotnet-coverage | ||
dotnet-coverage collect --output report.cobertura.xml --output-format cobertura bin\Release\net8.0\win-x64\publish\Algorithms.Console.exe |
18 changes: 18 additions & 0 deletions
18
samples/Algorithms/src/Algorithms.Console/Algorithms.Console.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PublishAot>true</PublishAot> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../Algorithms.Core/Algorithms.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeCoverage.MSBuild" Version="17.10.1" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
using Algorithms.Core; | ||
|
||
int[] a = [1, 5, 10, 15]; | ||
int[] b = [0, 3, 4, 6, 7, 20]; | ||
|
||
Print(nameof(a), a); | ||
Print(nameof(b), b); | ||
Print("merged:", Merger.Merge(a, b)); | ||
|
||
void Print(string name, int[] array) | ||
{ | ||
Console.WriteLine($"{name}: [{string.Join(",", array)}]"); | ||
} |