Add run unit tests in pipeline #359
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the main branch | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
# Allows to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Workflow jobs | |
jobs: | |
Build: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout | |
- name: Git checkout | |
uses: actions/checkout@v2 | |
# Needs .NET | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: 8.0.x | |
# Run dotnet restore | |
- name: Run dotnet restore | |
run: dotnet restore Cmf.CustomerPortal.Sdk.sln | |
# Run dotnet build | |
- name: Run dotnet build | |
run: dotnet build Cmf.CustomerPortal.Sdk.sln --no-restore --configuration Release | |
# Run tests with coverage | |
- name: Run Unit Tests with Coverage | |
run: | | |
dotnet test Cmf.CustomerPortal.Sdk.sln --no-build --no-restore --configuration Release \ | |
--collect:"XPlat Code Coverage" \ | |
--logger trx \ | |
--results-directory TestResults | |
- name: Merge Coverage Reports | |
run: | | |
dotnet tool install --global dotnet-reportgenerator-globaltool | |
reportgenerator -reports:TestResults/**/coverage.cobertura.xml \ | |
-targetdir:TestResults/MergedCoverage \ | |
-reporttypes:Cobertura | |
- name: Code Coverage Report | |
uses: irongut/[email protected] | |
with: | |
filename: TestResults/MergedCoverage/Cobertura.xml | |
badge: true | |
fail_below_min: true | |
format: markdown | |
hide_branch_rate: false | |
hide_complexity: true | |
indicators: true | |
output: both | |
thresholds: '7 7' | |
- 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: Write to Job Summary | |
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY | |
# Run build | |
- name: Build Windows | |
if: github.event.pull_request.base.ref == 'main-123694-PortalSDKUnitTestsInPipeline' | |
env: | |
DOTNET_CLI_TELEMETRY_OPTOUT: true | |
run: dotnet publish --no-build --no-restore --configuration Release --self-contained --runtime win-x64 Cmf.CustomerPortal.Sdk.sln | |
- name: Build Linux | |
if: github.event.pull_request.base.ref == 'main' | |
env: | |
DOTNET_CLI_TELEMETRY_OPTOUT: true | |
run: dotnet publish --no-build --no-restore --configuration Release --self-contained --runtime linux-x64 Cmf.CustomerPortal.Sdk.sln | |
# Read version | |
- name: Read tool version | |
if: github.event.pull_request.base.ref == 'main' | |
uses: QwerMike/xpath-action@v1 | |
id: getver | |
with: | |
filename: src/Version.props | |
expression: '/Project/PropertyGroup/Version/text()' | |
# Archive | |
- name: Archive Console Win64 | |
if: github.event.pull_request.base.ref == 'main' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Cmf.CustomerPortal.Sdk.Console-${{ steps.getver.outputs.result }}.win-x64 | |
path: src/Console/bin/Release/net8.0/win-x64/publish/ | |
- name: Archive Console Linux64 | |
if: github.event.pull_request.base.ref == 'main' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Cmf.CustomerPortal.Sdk.Console-${{ steps.getver.outputs.result }}.linux-x64 | |
path: src/Console/bin/Release/net8.0/linux-x64/publish/ | |
- name: Archive PowerShell | |
if: github.event.pull_request.base.ref == 'main' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Cmf.CustomerPortal.Sdk.PowerShell-${{ steps.getver.outputs.result }} | |
path: src/Powershell/bin/Release/net8.0/linux-x64/publish/ |