Skip to content

Create coverage-report.yml #14

Create coverage-report.yml

Create coverage-report.yml #14

Workflow file for this run

name: .NET Core Test Coverage and Comment PR with Markdown Report
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build-and-report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Run tests and collect coverage
run: dotnet test --logger trx --collect:"XPlat Code Coverage"
- name: Install ReportGenerator
run: dotnet tool install -g dotnet-reportgenerator-globaltool
- name: Generate coverage report in Markdown
run: reportgenerator "-reports:**/*.xml" "-targetdir:coveragereport" "-reporttypes:Markdown"
- name: Upload Markdown coverage report
uses: actions/upload-artifact@v4
with:
name: markdown-coverage-report
path: coveragereport/summary.md
- name: Post coverage report in PR comment
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const path = require('path');
const markdownReport = fs.readFileSync(path.join('coveragereport', 'summary.md'), 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: markdownReport
})
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}