Skip to content

Commit f2f4561

Browse files
committed
Coverage steps
1 parent 75cb7ae commit f2f4561

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

.github/workflows/publish.yml

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fi
2020
- name: Setup .NET 8
2121
if: env.dotnet8_installed == 'false'
22-
uses: actions/setup-dotnet@v4
22+
uses: actions/setup-dotnet@v4 # https://github.com/actions/setup-dotnet
2323
with:
2424
dotnet-version: 8.0.x
2525
dotnet-quality: 'ga'
@@ -33,47 +33,79 @@ 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
95+
- name: Upload coverage MD-report artifact
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: CoverageReport # Artifact name
99+
path: coveragereport-md # Directory containing files to upload
100+
- name: Publish coverage in build summary # Only applicable if 'MarkdownSummaryGithub' or one of the other Markdown report types is generated
101+
run: cat coveragereport-md/SummaryGithub.md >> $GITHUB_STEP_SUMMARY # Adjust path and filename if necessary
102+
shell: bash
71103
- name: List report files
72104
run: |
73105
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
106+
find coveragereport -type f -print | sort
107+
echo List files of MD report...
108+
find coveragereport-md -type f -print | sort
77109
78110
# build2:
79111
# runs-on: ubuntu-latest

0 commit comments

Comments
 (0)