Skip to content

Commit 9e4f6b5

Browse files
committed
Beta.4 version: Coverage by acceptance tests
1 parent 59af7df commit 9e4f6b5

File tree

3 files changed

+121
-61
lines changed

3 files changed

+121
-61
lines changed

.github/workflows/publish.yml

Lines changed: 118 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Publishes beta-versions only
2-
name: Publish Package
2+
name: Package
33
on:
44
push:
55
branches:
@@ -32,25 +32,39 @@ jobs:
3232
- name: Unit tests
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
35-
run: dotnet test --no-restore --no-build ./acceptance/Ocelot.Administration.IdentityServer4.AcceptanceTests.csproj --framework net8.0
35+
run: dotnet test --no-restore --no-build ./acceptance/Ocelot.Administration.IdentityServer4.AcceptanceTests.csproj --collect:"XPlat Code Coverage" --framework net8.0
3636
- name: Find files
3737
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/
42+
# Coverage by unit tests -> https://github.com/coverlet-coverage/coverlet
4343
coverage_1st_folder=$(ls -d ./unit/TestResults/*/ | head -1)
4444
echo "Detected first folder : $coverage_1st_folder"
4545
coverage_file="${coverage_1st_folder%/}/coverage.cobertura.xml"
46-
echo "Detecting coverage file... -> $coverage_file"
46+
echo "Detecting unit coverage file... -> $coverage_file"
4747
if [ -f "$coverage_file" ]; then
48-
echo Coverage file exists.
49-
echo "COVERAGE_FILE_EXISTS=true" >> $GITHUB_OUTPUT
50-
echo "COVERAGE_FILE=$coverage_file" >> $GITHUB_OUTPUT
48+
echo Unit coverage file exists.
49+
echo "UNIT_COVERAGE_FILE_EXISTS=true" >> $GITHUB_OUTPUT
50+
echo "UNIT_COVERAGE_FILE=$coverage_file" >> $GITHUB_OUTPUT
5151
else
52-
echo Coverage file DOES NOT exist!
53-
echo "COVERAGE_FILE_EXISTS=false" >> $GITHUB_OUTPUT
52+
echo Unit coverage file DOES NOT exist!
53+
echo "UNIT_COVERAGE_FILE_EXISTS=false" >> $GITHUB_OUTPUT
54+
exit 1
55+
fi
56+
# Coverage by acceptance tests -> https://github.com/coverlet-coverage/coverlet
57+
coverage_1st_folder=$(ls -d ./acceptance/TestResults/*/ | head -1)
58+
echo "Detected first folder : $coverage_1st_folder"
59+
coverage_file="${coverage_1st_folder%/}/coverage.cobertura.xml"
60+
echo "Detecting acceptance coverage file... -> $coverage_file"
61+
if [ -f "$coverage_file" ]; then
62+
echo Acceptance coverage file exists.
63+
echo "ACCEPTANCE_COVERAGE_FILE_EXISTS=true" >> $GITHUB_OUTPUT
64+
echo "ACCEPTANCE_COVERAGE_FILE=$coverage_file" >> $GITHUB_OUTPUT
65+
else
66+
echo Acceptance coverage file DOES NOT exist!
67+
echo "ACCEPTANCE_COVERAGE_FILE_EXISTS=false" >> $GITHUB_OUTPUT
5468
exit 1
5569
fi
5670
- name: Install tools
@@ -64,61 +78,111 @@ jobs:
6478
sudo apt install libxml2-utils # aka xmllint read-command. xmlstarlet is not required
6579
6680
# Extract actual coverage % from the Coverlet XML-file
67-
- name: Coverage by unit tests
81+
- name: Read coverage
6882
id: coverage
6983
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
84+
echo Coverage by unit tests
85+
line_coverage_u=$(xmllint --xpath "string(//coverage/@line-rate)" ${{ steps.files.outputs.UNIT_COVERAGE_FILE }})
86+
echo " Line coverage: $line_coverage_u"
87+
echo "LineCoverageUnit=$line_coverage_u" >> $GITHUB_OUTPUT
88+
echo "LINE_COVERAGE_UNIT=$line_coverage_u" >> $GITHUB_ENV
89+
branch_coverage_u=$(xmllint --xpath "string(//coverage/@branch-rate)" ${{ steps.files.outputs.UNIT_COVERAGE_FILE }})
90+
echo " Branch coverage: $branch_coverage_u"
91+
echo "BranchCoverageUnit=$branch_coverage_u" >> $GITHUB_OUTPUT
92+
echo "BRANCH_COVERAGE_UNIT=$branch_coverage_u" >> $GITHUB_ENV
93+
echo Coverage by acceptance tests
94+
line_coverage_a=$(xmllint --xpath "string(//coverage/@line-rate)" ${{ steps.files.outputs.ACCEPTANCE_COVERAGE_FILE }})
95+
echo " Line coverage: $line_coverage_a"
96+
echo "LineCoverageAcceptance=$line_coverage_a" >> $GITHUB_OUTPUT
97+
echo "LINE_COVERAGE_ACCEPTANCE=$line_coverage_a" >> $GITHUB_ENV
98+
branch_coverage_a=$(xmllint --xpath "string(//coverage/@branch-rate)" ${{ steps.files.outputs.ACCEPTANCE_COVERAGE_FILE }})
99+
echo " Branch coverage: $branch_coverage_a"
100+
echo "BranchCoverageAcceptance=$branch_coverage_a" >> $GITHUB_OUTPUT
101+
echo "BRANCH_COVERAGE_ACCEPTANCE=$branch_coverage_a" >> $GITHUB_ENV
102+
lcu=$(printf "%1.4f" $line_coverage_u)
103+
lca=$(printf "%1.4f" $line_coverage_a)
104+
bcu=$(printf "%1.4f" $branch_coverage_u)
105+
bca=$(printf "%1.4f" $branch_coverage_a)
106+
echo '+------ COVERAGE MATRIX -------+'
107+
echo '| | Line | Branch |'
108+
echo '|------------|--------|--------|'
109+
echo '| Unit |' $lcu \| $bcu \|
110+
echo '| Acceptance |' $lca \| $bca \|
111+
echo '+------------------------------+'
78112
79113
# The action below replaces the following command: dotnet tool run reportgenerator -reports:$coverage_file -targetdir:coveragereport-md -reporttypes:MarkdownSummaryGithub
80114
# Docs: https://reportgenerator.io/
81-
- name: Generate coverage report (Markdown)
82-
if: steps.files.outputs.COVERAGE_FILE_EXISTS == 'true'
115+
- name: Generate coverage report (Unit)
116+
if: steps.files.outputs.UNIT_COVERAGE_FILE_EXISTS == 'true'
117+
uses: danielpalme/ReportGenerator-GitHub-Action@5.4.7 # Docs: https://github.com/marketplace/actions/reportgenerator
118+
with:
119+
reports: ${{ steps.files.outputs.UNIT_COVERAGE_FILE }}
120+
targetdir: coveragereport-u
121+
reporttypes: HtmlInline;MarkdownSummaryGithub
122+
- name: Generate coverage report (Acceptance)
123+
if: steps.files.outputs.ACCEPTANCE_COVERAGE_FILE_EXISTS == 'true'
83124
uses: danielpalme/ReportGenerator-GitHub-Action@5.4.7 # Docs: https://github.com/marketplace/actions/reportgenerator
84125
with:
85-
reports: ${{ steps.files.outputs.COVERAGE_FILE }}
86-
targetdir: coveragereport-md
87-
reporttypes: MarkdownSummaryGithub
126+
reports: ${{ steps.files.outputs.ACCEPTANCE_COVERAGE_FILE }}
127+
targetdir: coveragereport-a
128+
reporttypes: HtmlInline;MarkdownSummaryGithub
129+
- name: List report files
130+
run: |
131+
echo Listing files of unit-report...
132+
find coveragereport-u -type f -print | sort
133+
echo Listing files of acceptance-report...
134+
find coveragereport-a -type f -print | sort
88135
89136
# DOCS Storing and sharing data from a workflow -> https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/storing-and-sharing-data-from-a-workflow
90-
- name: Upload coverage MD-report artifact
137+
- name: Upload artifacts of coverage report (Unit)
138+
if: steps.files.outputs.UNIT_COVERAGE_FILE_EXISTS == 'true' && success()
91139
uses: actions/upload-artifact@v4 # https://github.com/actions/upload-artifact
92140
with:
93-
name: CoverageReport-markdown # Artifact name
94-
path: coveragereport-md # Directory containing files to upload
95-
- name: Publish coverage in build summary # Only applicable if 'MarkdownSummaryGithub' or one of the other Markdown report types is generated
141+
name: CoverageReport-UnitTests # artifact name
142+
path: coveragereport-u # directory containing files to upload
143+
- name: Upload artifacts of coverage report (Acceptance)
144+
if: steps.files.outputs.ACCEPTANCE_COVERAGE_FILE_EXISTS == 'true' && success()
145+
uses: actions/upload-artifact@v4 # https://github.com/actions/upload-artifact
146+
with:
147+
name: CoverageReport-AcceptanceTests # artifact name
148+
path: coveragereport-a # directory containing files to upload
149+
- name: Publish coverage in job summary # only applicable if 'MarkdownSummaryGithub' or one of the other Markdown report types is generated
96150
run: |
97151
echo Listing files of MD report...
98-
find coveragereport-md -type f -print | sort
99-
echo Publishing coverage in build summary...
100-
cat coveragereport-md/SummaryGithub.md >> $GITHUB_STEP_SUMMARY # Adjust path and filename if necessary
152+
find coveragereport-u/*.md -type f -print | sort
153+
find coveragereport-a/*.md -type f -print | sort
154+
# Re-format both MD-files for better presentation
155+
md=$'\n'
156+
md+='| _Coverage Matrix_ | Line | Branch |'$'\n'
157+
md+='| - | - | - |'$'\n'
158+
# echo Matrix markdown is "$md"
159+
line=$(grep -F "|**Ocelot.Administration.IdentityServer4**|" coveragereport-u/SummaryGithub.md)
160+
# echo Line is $line
161+
line="${line/Ocelot.Administration.IdentityServer4/Unit}"
162+
line="${line//\*\*/ }"
163+
# echo Line is $line
164+
md+=$line$'\n'
165+
# echo Matrix markdown is "$md"
166+
line=$(grep -F "|**Ocelot.Administration.IdentityServer4**|" coveragereport-a/SummaryGithub.md)
167+
# echo Line is $line
168+
line="${line/Ocelot.Administration.IdentityServer4/Acceptance}"
169+
line="${line//\*\*/ }"
170+
# $ echo Line is $line
171+
md+=$line$'\n'
172+
echo Matrix markdown is "$md"
173+
echo Reformatting MD-files...
174+
sed -i 's/# Summary/# Code Coverage Summary\n$md/g' coveragereport-u/SummaryGithub.md
175+
sed -i 's|<summary>Summary</summary>|<summary>Unit Tests</summary>|g' coveragereport-u/SummaryGithub.md
176+
sed -i 's/## Coverage/## Unit Test Coverage/g' coveragereport-u/SummaryGithub.md
177+
sed -i 's/# Summary/\n---\n/g' coveragereport-a/SummaryGithub.md
178+
sed -i 's|<summary>Summary</summary>|<summary>Acceptance Tests</summary>|g' coveragereport-a/SummaryGithub.md
179+
sed -i 's/## Coverage/## Acceptance Test Coverage/g' coveragereport-a/SummaryGithub.md
180+
# Adding a job summary -> https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#adding-a-job-summary
181+
echo Publishing coverage in job summary...
182+
cat coveragereport-u/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
183+
cat coveragereport-a/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
101184
shell: bash
102185

103-
# The action below replaces the following command: dotnet tool run reportgenerator -reports:$coverage_file -targetdir:coveragereport -reporttypes:HtmlInline
104-
# Docs: https://reportgenerator.io/
105-
- name: Generate coverage report (HTML)
106-
if: steps.files.outputs.COVERAGE_FILE_EXISTS == 'true'
107-
uses: danielpalme/ReportGenerator-GitHub-Action@5.4.7 # Docs: https://github.com/marketplace/actions/reportgenerator
108-
with:
109-
reports: ${{ steps.files.outputs.COVERAGE_FILE }}
110-
targetdir: coveragereport
111-
reporttypes: HtmlInline # Html is applicable for websites only
112-
- name: List HTML report files
113-
run: |
114-
echo Listing files of HTML report...
115-
find coveragereport -type f -print | sort
116-
- name: Upload coverage HTML-report artifact
117-
uses: actions/upload-artifact@v4 # https://github.com/actions/upload-artifact
118-
with:
119-
name: CoverageReport-html
120-
path: coveragereport/*.html
121-
122186
publish:
123187
needs: build
124188
runs-on: ubuntu-latest
@@ -156,13 +220,13 @@ jobs:
156220
run: dotnet restore ./Ocelot.Administration.IdentityServer4.sln
157221

158222
- name: Build project
159-
run: dotnet build ./src/Ocelot.Administration.IdentityServer4.csproj --configuration Release --no-restore
223+
run: dotnet build ./src/Ocelot.Administration.IdentityServer4.csproj --configuration Release --no-restore /p:ContinuousIntegrationBuild=true
160224

161225
- name: Pack project
162226
run: dotnet pack ./src/Ocelot.Administration.IdentityServer4.csproj --configuration Release --output ./packages
163227

164-
- name: Publish to GitHub Packages
165-
run: dotnet nuget push ./packages/*.nupkg --source "https://nuget.pkg.github.com/ThreeMammals/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
228+
# - name: Publish to GitHub Packages
229+
# run: dotnet nuget push ./packages/*.nupkg --source "https://nuget.pkg.github.com/ThreeMammals/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
166230

167-
- name: Publish to NuGet
168-
run: dotnet nuget push ./packages/*.nupkg --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY_2025 }} --skip-duplicate
231+
# - name: Publish to NuGet
232+
# run: dotnet nuget push ./packages/*.nupkg --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY_2025 }} --skip-duplicate

src/Ocelot.Administration.IdentityServer4.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<IncludeSymbols>True</IncludeSymbols>
1010
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1111
<!--Package properties-->
12-
<Version>24.0.0-beta.3</Version>
12+
<Version>24.0.0-beta.4</Version>
1313
<PackageId>Ocelot.Administration.IdentityServer4</PackageId>
1414
<PackageDescription>Provides Ocelot extensions to use the Administration API and IdentityServer4 dependencies that come with it</PackageDescription>
1515
<PackageReleaseNotes>https://github.com/ThreeMammals/Ocelot.Administration.IdentityServer4/releases</PackageReleaseNotes>

src/OcelotBuilderExtensions.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,8 @@ private static List<ApiResource> Resources(IdentityServerConfiguration configura
100100
[
101101
new(configuration.ApiName, configuration.ApiName)
102102
{
103-
ApiSecrets =
104-
[
105-
new()
106-
{
107-
Value = configuration.ApiSecret.Sha256(),
108-
},
103+
ApiSecrets = [
104+
new() { Value = configuration.ApiSecret.Sha256() },
109105
],
110106
},
111107
];

0 commit comments

Comments
 (0)