Skip to content

chore: Bump Microsoft.NET.Test.Sdk from 17.8.0 to 18.0.1 #55

chore: Bump Microsoft.NET.Test.Sdk from 17.8.0 to 18.0.1

chore: Bump Microsoft.NET.Test.Sdk from 17.8.0 to 18.0.1 #55

Workflow file for this run

name: Code Coverage
on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]
jobs:
coverage:
name: Generate Code Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --no-restore --configuration Release
- name: Run tests with coverage
run: |
dotnet test \
--no-build \
--configuration Release \
--collect:"XPlat Code Coverage" \
--results-directory ./coverage \
--logger trx \
--verbosity normal
- name: Install ReportGenerator
run: dotnet tool install -g dotnet-reportgenerator-globaltool
- name: Generate coverage report
run: |
reportgenerator \
-reports:"./coverage/**/coverage.cobertura.xml" \
-targetdir:"./coveragereport" \
-reporttypes:"Html;Cobertura;TextSummary"
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
files: ./coverage/**/coverage.cobertura.xml
fail_ci_if_error: false
verbose: true
- name: Upload coverage report artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: ./coveragereport/
retention-days: 30
- name: Comment coverage on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
try {
const summaryPath = './coveragereport/Summary.txt';
if (fs.existsSync(summaryPath)) {
const summary = fs.readFileSync(summaryPath, 'utf8');
const lines = summary.split('\n');
const coverageLine = lines.find(line => line.includes('Line coverage:')) || 'Coverage data not available';
const body = `## 📊 Code Coverage Report
${coverageLine}
📈 [View detailed coverage report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📊 Code Coverage Report')
);
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
}
} catch (error) {
console.log('Could not post coverage comment:', error.message);
}