This repository contains reusable workflows for interacting with .NET CLI test command in your CI/CD pipeline.
These workflows is part of the Codebelt umbrella and ensures a consistent way of:
- Defining your CI/CD pipeline
- Structuring your repository
- Keeping your codebase small and feasible
- Writing clean and maintainable code
- Deploying your code to different environments
- Automating as much as possible
A paved path to excel as a DevSecOps Engineer.
- default.yml - the
dotnet testworkflow that:- fetches the codebase,
- installs the .NET SDK,
- installs the Report Generator for .NET tool,
- conditionally restores cached content,
- downloads build artifacts,
- tests the solution through the action, which selects VSTest or Microsoft.Testing.Platform from the repository's
global.json, - generates a coverage report using ReportGenerator,
- writes to GitHub job summary,
- uploads the coverage report as workflow artifacts,
- uploads the test results as workflow artifacts.
To call this workflow in your GitHub repository, you can follow these steps:
pack-call:
uses: codebeltnet/jobs-dotnet-test/.github/workflows/default.yml@v3with:
# Optional path to the project(s) file to build. Supports globbing. Default is an empty string.
projects: ''
# Defines the build configuration. Default is Release (to reduce risk of surprises when transitioning to Production).
configuration: 'Release'
# The type of machine to run the job on. Default is ubuntu-24.04.
runs-on: 'ubuntu-24.04'
# When set to true, includes preview versions of .NET. Default is false.
include-preview: false
# Sets the verbosity level of the command. Allowed values are quiet, minimal, normal, detailed, and diagnostic. Default is quiet.
verbosity-level: 'quiet'
# The name of the folder where the coverage report will be written. Default is Coverage.
coverage-report-folder-name: 'Coverage'
# The name of the folder where the test results will be written. Default is TestResults.
test-results-folder-name: 'TestResults'
# Provides a way to fully customize the build. Default is an empty string. See https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2022#switches for more information.
build-switches: ''
# When set, the current workspace will be overwritten with the content of the restore cache. Default is an empty string.
restore-cache-key: ''
# The pattern used to download build artifacts. Default is '*-' plus the configuration.
download-pattern: ''
# The time to wait for a test to complete before collecting a dump. Default is 10 minutes.
blame-hang-timeout: '10m'
# The type of dump to collect when a test hangs. Default is mini.
blame-hang-dump-type: 'mini'
# Additional arguments to pass to the test runner. Default is an empty string.
test-arguments: ''
# Whether to build the project(s) before testing. Default is false.
build: false
# Whether to restore the project(s) before testing. Default is false.
restore: false
# The maximum time in minutes to allow the job to run. Default is 15 minutes.
timeout-minutes: 15This workflow has no secrets.
Repositories using the .NET 10+ Microsoft.Testing.Platform dotnet test experience must opt in from the repository root with:
{
"test": {
"runner": "Microsoft.Testing.Platform"
}
}MTP test projects must reference coverlet.MTP for supported targets and Microsoft.Testing.Extensions.HangDump 2.3.0 or newer. The test action keeps xUnit TRX reporting and produces Coverlet OpenCover coverage for supported modern .NET targets and net48 (verified with coverlet.MTP 10.0.1). Other .NET Framework test modules are still executed and reported without MTP Coverlet coverage.
Coverlet MTP can write timestamped names such as coverage.opencover.<timestamp>.xml. The workflow discovers those files and normalizes their filenames to coverage.<timestamp>.opencover.xml before reporting and artifact upload; the OpenCover XML content is unchanged. This keeps the existing TestResults artifact and scanner patterns such as **/*opencover.xml compatible. ReportGenerator uses OpenCover as its input and continues producing the GitHub Markdown summary, HTML reports, and aggregate Cobertura report.
When the selected test path includes a target expected to produce coverage, the workflow fails with the TestResults directory, produced files, runner mode, and expected pattern if no OpenCover file is found. If the test action does not report whether coverage is expected, the workflow assumes it is expected so a missing file cannot pass silently. A run that explicitly reports only targets outside the coverage-capable set is test-only and does not create an empty coverage report.
This workflow has no outputs.
Run the deterministic OpenCover discovery, filename normalization, reporting, and artifact contract checks with pwsh -NoProfile -File tests/Test-CoverageContract.ps1.
jobs:
build:
uses: codebeltnet/jobs-dotnet-test/.github/workflows/default.yml@v3
with:
configuration: Release- Bootstrapper API - https://github.com/codebeltnet/bootstrapper/blob/main/.github/workflows/pipelines.yml
- Extensions for Asp.Versioning API - https://github.com/codebeltnet/asp-versioning/blob/main/.github/workflows/pipelines.yml
- Extensions for AWS Signature Version 4 API - https://github.com/codebeltnet/aws-signature-v4/blob/main/.github/workflows/pipelines.yml
- Extensions for Globalization API - https://github.com/codebeltnet/globalization/blob/main/.github/workflows/pipelines.yml
- Extensions for Newtonsoft.Json API - https://github.com/codebeltnet/newtonsoft-json/blob/main/.github/workflows/pipelines.yml
- Extensions for Swashbuckle.AspNetCore API - https://github.com/codebeltnet/swashbuckle-aspnetcore/blob/main/.github/workflows/pipelines.yml
- Extensions for xUnit API - https://github.com/codebeltnet/xunit/blob/main/.github/workflows/pipelines.yml
- Extensions for YamlDotNet API - https://github.com/codebeltnet/yamldotnet/blob/main/.github/workflows/pipelines.yml
- Shared Kernel API - https://github.com/codebeltnet/shared-kernel/blob/main/.github/workflows/pipelines.yml
- Unitify API - https://github.com/codebeltnet/unitify/blob/main/.github/workflows/pipelines.yml
Contributions are welcome! Feel free to submit issues, feature requests, or pull requests to help improve these workflows.
This project is licensed under the MIT License - see the LICENSE file for details.