@@ -33,47 +33,71 @@ jobs:
3333 run : dotnet test --no-restore --no-build ./unit/Ocelot.Administration.IdentityServer4.UnitTests.csproj --collect:"XPlat Code Coverage" --framework net8.0
3434 - name : Acceptance tests
3535 run : dotnet test --no-restore --no-build ./acceptance/Ocelot.Administration.IdentityServer4.AcceptanceTests.csproj --framework net8.0
36- - name : Find coverage file # https://reportgenerator.io/
37- id : coverage
36+ - name : Find files
37+ id : files
3838 run : |
3939 echo "GITHUB REF is ${{ github.ref }}"
4040 echo "GITHUB REF NAME is ${{ github.ref_name }}"
4141 echo "GITHUB SHA is ${{ github.sha }}"
42+ # https://reportgenerator.io/
4243 coverage_1st_folder=$(ls -d ./unit/TestResults/*/ | head -1)
4344 echo "Detected first folder : $coverage_1st_folder"
4445 coverage_file="${coverage_1st_folder%/}/coverage.cobertura.xml"
4546 echo "Detecting coverage file... -> $coverage_file"
4647 if [ -f "$coverage_file" ]; then
47- echo " Coverage file exists."
48- echo "FILE_EXISTS =true" >> $GITHUB_OUTPUT
48+ echo Coverage file exists.
49+ echo "COVERAGE_FILE_EXISTS =true" >> $GITHUB_OUTPUT
4950 echo "COVERAGE_FILE=$coverage_file" >> $GITHUB_OUTPUT
5051 else
51- echo " Coverage file DOES NOT exist!"
52- echo "FILE_EXISTS =false" >> $GITHUB_OUTPUT
52+ echo Coverage file DOES NOT exist!
53+ echo "COVERAGE_FILE_EXISTS =false" >> $GITHUB_OUTPUT
5354 exit 1
5455 fi
55- # dotnet tool restore
56- # dotnet tool run reportgenerator -reports:$coverage_file -targetdir:coveragereport
56+ - name : Install tools
57+ run : |
58+ # .NET tools aka .config/dotnet-tools.json
59+ echo Installing .NET tools aka dotnet-tools.json ...
60+ dotnet tool restore
61+ # Install XML tools
62+ echo Installing XML tools ...
63+ sudo apt update
64+ sudo apt install libxml2-utils xmlstarlet
65+
66+ # Extract actual coverage % from the Coverlet XML-file
67+ - name : Coverage by unit tests
68+ id : coverage
69+ run : |
70+ line_coverage=$(xmllint --xpath "string(//coverage/@line-rate)" ${{ steps.files.outputs.COVERAGE_FILE }})
71+ echo Line coverage: $line_coverage
72+ echo "LineCoverage=$line_coverage" >> $GITHUB_OUTPUT
73+ echo "LINE_COVERAGE=$line_coverage" >> $GITHUB_ENV
74+ branch_coverage=$(xmllint --xpath "string(//coverage/@branch-rate)" ${{ steps.files.outputs.COVERAGE_FILE }})
75+ echo Branch coverage: $branch_coverage
76+ echo "BranchCoverage=$branch_coverage" >> $GITHUB_OUTPUT
77+ echo "BRANCH_COVERAGE=$branch_coverage" >> $GITHUB_ENV
78+
79+ # The action below replaces the following command: dotnet tool run reportgenerator -reports:$coverage_file -targetdir:coveragereport
80+ # Docs: https://reportgenerator.io/
5781 - name : Generate coverage report (HTML)
58- if : steps.coverage .outputs.FILE_EXISTS == 'true'
82+ if : steps.files .outputs.COVERAGE_FILE_EXISTS == 'true'
5983 uses : danielpalme/ReportGenerator-GitHub-Action@5.4.7 # Docs: https://github.com/marketplace/actions/reportgenerator
6084 with :
61- reports : ${{ steps.coverage .outputs.COVERAGE_FILE }}
85+ reports : ${{ steps.files .outputs.COVERAGE_FILE }}
6286 targetdir : coveragereport
6387 reporttypes : Html
6488 - name : Generate coverage report (Markdown)
65- if : steps.coverage .outputs.FILE_EXISTS == 'true'
89+ if : steps.files .outputs.COVERAGE_FILE_EXISTS == 'true'
6690 uses : danielpalme/ReportGenerator-GitHub-Action@5.4.7 # Docs: https://github.com/marketplace/actions/reportgenerator
6791 with :
68- reports : ${{ steps.coverage .outputs.COVERAGE_FILE }}
92+ reports : ${{ steps.files .outputs.COVERAGE_FILE }}
6993 targetdir : coveragereport-md
7094 reporttypes : MarkdownSummaryGithub
7195 - name : List report files
7296 run : |
7397 echo List files of HTML report...
74- find coveragereport -type f -print
75- echo -e "\n\nList files of MD report..."
76- find coveragereport-md -type f -print
98+ find coveragereport -type f -print | sort
99+ echo List files of MD report...
100+ find coveragereport-md -type f -print | sort
77101
78102 # build2:
79103 # runs-on: ubuntu-latest
0 commit comments