Skip to content

Commit

Permalink
Create coverage badges
Browse files Browse the repository at this point in the history
- optimize workflow
  • Loading branch information
JoergHoffmannatGitHub committed Jan 7, 2024
1 parent db43b58 commit 51d042d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
28 changes: 28 additions & 0 deletions .github/matchers/dotnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"problemMatcher": [
{
"owner": "dotnet-file",
"pattern": [
{
"regexp": "^(.+)\\((\\d+).+\\):\\s(\\w+)\\s(.+)\\:\\s(.*)$",
"file": 1,
"line": 2,
"severity": 3,
"code": 4,
"message": 5
}
]
},
{
"owner": "dotnet-run",
"pattern": [
{
"regexp": "^.+\\s\\:\\s(\\w+)\\s(.*)\\:\\s(.*)$",
"severity": 1,
"code": 2,
"message": 3
}
]
}
]
}
26 changes: 14 additions & 12 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,34 @@ jobs:
with:
dotnet-version: 8.0.x

# Dotnet matcher
- name: 🔍 Enable problem matchers
run: echo "::add-matcher::.github/matchers/dotnet.json"

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/[email protected]

# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: 🦸‍♂️ Restore steriods # this is the caching step, remove if you don't think you need it
uses: actions/cache@v3
with:
path: ~/.nuget/packages
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- name: Restore the application
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}

# Execute all unit tests in the solution
- name: Execute unit tests
run: |
echo "## ❔ Test results" >> $GITHUB_STEP_SUMMARY
dotnet test --configuration $env:Configuration --no-restore --logger GitHubActions '/p:CollectCoverage=true;CoverletOutputFormat=\"json,lcov,cobertura,opencover\";MergeWith=${{github.workspace}}/coverage.json;CoverletOutput=${{github.workspace}}/coverage' -- RunConfiguration.CollectSourceInformation=true
run: dotnet test --configuration $env:Configuration --no-restore --logger GitHubActions '/p:CollectCoverage=true;CoverletOutputFormat=\"json,lcov,cobertura,opencover\";MergeWith=${{github.workspace}}/coverage.json;CoverletOutput=${{github.workspace}}/coverage' -- RunConfiguration.CollectSourceInformation=true
env:
Configuration: ${{ matrix.configuration }}

- name: 📝 Code Coverage report
run: |
dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.1.23
reportgenerator -reports:${{github.workspace}}/coverage.cobertura.xml -targetdir:${{github.workspace}}/report -reporttypes:MarkdownSummaryGithub "-filefilters:-*.g.cs" -verbosity:Warning
sed -i 's/# Summary/## 📝 Code Coverage/g' ${{github.workspace}}/report/SummaryGithub.md
sed -i 's/## Coverage/### Code Coverage details/g' ${{github.workspace}}/report/SummaryGithub.md
cat ${{github.workspace}}/report/*.md >> $GITHUB_STEP_SUMMARY

# Create coverage badges
- name: OpenCover Badge Generator
Expand All @@ -65,7 +68,6 @@ jobs:
path-to-opencover-xml: ${{github.workspace}}/coverage.opencover.xml
path-to-badges: ./
minimum-coverage: 75
commit-badges: false
repo-token: ${{ secrets.GITHUB_TOKEN }}

# Archive the package
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
CoverageResults/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.Props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Copyright>© $([System.DateTime]::Now.ToString('yyyy'))</Copyright>
<RepositoryUrl>https://github.com/JoergHoffmannatGitHub/Family.Show</RepositoryUrl>
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<NoWarn>CA1416</NoWarn>
</PropertyGroup>
<!-- Versioning projects -->
Expand Down

0 comments on commit 51d042d

Please sign in to comment.