initial commit #25
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 And Test RES.Configuration | |
on: | |
push: | |
branches: | |
- "master" | |
paths-ignore: | |
- '**.md' | |
pull_request: | |
workflow_dispatch: | |
env: | |
APP_NAME: RES.Configuration | |
jobs: | |
Build_And_Test: | |
name: Build And Test | |
runs-on: windows-2019 | |
steps: | |
- name: Checkout PR merged with Master | |
uses: actions/checkout@v3 | |
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' | |
with: | |
ref: refs/pull/${{ github.event.number }}/merge | |
- name: Checkout Master | |
uses: actions/checkout@v3 | |
if: github.event_name != 'pull_request' && github.event_name != 'pull_request_target' | |
- name: Use .NET Core SDK 5.x | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 5.0.x | |
- name: Install OpenCover | |
run: choco install opencover.portable | |
- name: Install nunit-console | |
run: | | |
msiexec /i D:\a\configuration\configuration\NUnit.Console-3.15.4.msi /qn /norestart | |
- name: Restore RES.Configuration | |
run: dotnet restore RES.Configuration.sln | |
- name: Build RES.Configuration | |
run: dotnet build RES.Configuration.sln --configuration Release --no-restore | |
- name: Run OpenCover | |
shell: cmd | |
run: | | |
C:\ProgramData\chocolatey\lib\opencover.portable\tools\OpenCover.Console.exe -register:Path64 -target:"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" -targetargs:"${{ github.workspace }}\BuiltDlls\Release\RES.Configuration.Test.dll" -output:"coverage.xml" -returntargetcode -filter:"+[RES.Configuration.Test]*" -oldStyle -register:user | |
# C:\ProgramData\chocolatey\lib\opencover.portable\tools\\OpenCover.Console.exe -register:Path64 -target:"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" -targetargs:"${{ github.workspace }}\BuiltDlls\Release\RES.Configuration.Test.dll" -output:"coverage.xml" -returntargetcode -filter:"+[RES.Configuration]* -[RES.Configuration.Test]*" -oldStyle -register:user | |
- name: Create Test Result Summary in Markdown Format | |
id: test_result | |
shell: pwsh | |
run: | | |
$XMLPath = 'TestResult.xml' | |
$xml = [xml](Get-Content $XMLPath) | |
$test_run = $xml.SelectNodes('//test-run') | |
$total_tests = $test_run.total | |
$passed = $test_run.passed | |
$failed = $test_run.failed | |
$warnings = $test_run.warnings | |
$inconclusive = $test_run.inconclusive | |
$skipped = $test_run.skipped | |
$duration = $test_run.duration | |
$duration = [Math]::Round($duration, 2, [MidpointRounding]::ToEven) | |
echo "passed=$passed" >> $env:GITHUB_OUTPUT | |
echo "total_tests=$total_tests" >> $env:GITHUB_OUTPUT | |
'# Test Report<br>' | Out-File '${{ env.APP_NAME }}-test-results.md' | |
'## Summary<br>'| Out-File '${{ env.APP_NAME }}-test-results.md' -Append | |
$total_tests + ' tests ran in ' + $duration + ' seconds.<br>' | Out-File '${{ env.APP_NAME }}-test-results.md' -Append | |
'- ' + $passed + ' tests passed<br>' | Out-File '${{ env.APP_NAME }}-test-results.md' -Append | |
'- ' + $failed + ' tests failed<br>' | Out-File '${{ env.APP_NAME }}-test-results.md' -Append | |
'- ' + $skipped + ' tests skipped<br>' | Out-File '${{ env.APP_NAME }}-test-results.md' -Append | |
- name: Use ReportGenerator to Convert Code Coverage Results to Markdown Format | |
uses: danielpalme/[email protected] | |
with: | |
reports: coverage.xml | |
targetdir: ${{ github.workspace }} | |
reporttypes: MarkdownSummary | |
- name: Write Test and Coverage Results to Job Summary | |
shell: bash | |
run: | | |
mv Summary.md ${{ env.APP_NAME }}-coverage-results-windows.md | |
cat ${{ env.APP_NAME }}-test-results.md >> $GITHUB_STEP_SUMMARY | |
cat ${{ env.APP_NAME }}-coverage-results.md >> $GITHUB_STEP_SUMMARY | |
- name: Extract code coverage % | |
id: code_coverage | |
shell: bash | |
run: | | |
coverage=`grep -o '**Line coverage:**[^"]*' ${{ env.APP_NAME }}-coverage-results.md` | |
echo $coverage | |
numbers=$(echo $coverage | tr -cd '[. [:digit:]]') | |
percent=$(echo $numbers | cut -f1 -d' ') | |
echo "percent=$percent" >> $GITHUB_OUTPUT | |
- name: Upload Test and Coverage Reports to Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-and-coverage-results | |
path: | | |
${{ env.APP_NAME }}-test-results.md | |
${{ env.APP_NAME }}-coverage-results.md | |
- name: Create nuget package | |
run: | | |
dotnet pack RES.Configuration/RES.Configuration.csproj --configuration Release --no-restore --no-build --output ${{ github.workspace }}/artifacts | |
- name: Upload nuget package to Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: RES.Configuration | |
path: | | |
artifacts/*.nupkg |