Skip to content

Merge pull request #128 from OpenIPC/dev #175

Merge pull request #128 from OpenIPC/dev

Merge pull request #128 from OpenIPC/dev #175

name: Generate Test Coverage Report
concurrency:
group: coverage-${{ github.ref }}
cancel-in-progress: true
# Runs on master branch commits,
# every commit in a pull request, any published release.
on:
workflow_dispatch:
push:
branches: ["master"]
pull_request:
branches: ["master"]
release:
types: [published]
jobs:
build:
# Permissions this GitHub Action needs for other things in GitHub
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: List Downloaded Files
run: ls -R .
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore workloads
run: dotnet workload restore
- name: Restore dependencies
run: dotnet restore OpenIPC_Config/OpenIPC_Config.csproj
- name: Build project
run: dotnet build OpenIPC_Config/OpenIPC_Config.csproj --configuration Release
- name: "Restore/Build/Test"
run: dotnet test OpenIPC_Config.Tests --configuration Release --verbosity normal --logger trx --collect:"XPlat Code Coverage"
- name: Combine Coverage Reports # This is because one report is produced per project, and we want one result for all of them.
uses: danielpalme/ReportGenerator-GitHub-Action@5.2.4
with:
reports: "**/*.cobertura.xml" # REQUIRED # The coverage reports that should be parsed (separated by semicolon). Globbing is supported.
targetdir: "${{ github.workspace }}" # REQUIRED # The directory where the generated report should be saved.
reporttypes: "HtmlInline;Cobertura" # The output formats and scope (separated by semicolon) Values: Badges, Clover, Cobertura, CsvSummary, Html, Html_Dark, Html_Light, Html_BlueRed, HtmlChart, HtmlInline, HtmlInline_AzurePipelines, HtmlInline_AzurePipelines_Dark, HtmlInline_AzurePipelines_Light, HtmlSummary, JsonSummary, Latex, LatexSummary, lcov, MarkdownSummary, MarkdownSummaryGithub, MarkdownDeltaSummary, MHtml, PngChart, SonarQube, TeamCitySummary, TextSummary, TextDeltaSummary, Xml, XmlSummary
verbosity: "Info" # The verbosity level of the log messages. Values: Verbose, Info, Warning, Error, Off
title: "Code Coverage" # Optional title.
tag: "${{ github.run_number }}_${{ github.run_id }}" # Optional tag or build version.
customSettings: "" # Optional custom settings (separated by semicolon). See: https://github.com/danielpalme/ReportGenerator/wiki/Settings.
toolpath: "reportgeneratortool" # Default directory for installing the dotnet tool.
- name: Upload Combined Coverage XML
uses: actions/upload-artifact@v4
with:
name: coverage
path: ${{ github.workspace }}/Cobertura.xml
retention-days: 1
- name: Publish Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: "Cobertura.xml"
badge: true
fail_below_min: false # just informative for now
format: markdown
hide_branch_rate: false
hide_complexity: false
indicators: true
output: both
thresholds: "10 30"
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
- name: Upload Test Result Files
uses: actions/upload-artifact@v4
with:
name: test-results
path: ${{ github.workspace }}/**/TestResults/**/*
retention-days: 1
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2.16.1
if: always()
with:
trx_files: "${{ github.workspace }}/**/*.trx"
- name: Cleanup Disk Space
if: always() # Run even if previous steps fail
run: |
# Remove unnecessary files after testing
rm -rf "${{ github.workspace }}/**/*.trx"
rm -rf "${{ github.workspace }}/**/*.cobertura.xml"
rm -rf "${{ github.workspace }}/Cobertura.xml"
rm -rf "${{ github.workspace }}/code-coverage-results.md"
- name: Prune Old Artifacts
if: always() # Run even if previous steps fail
uses: c-hive/gha-remove-artifacts@v1
with:
age: '1 day'
skip-recent: 2