11# Publishes beta-versions only
2- name : Publish Package
2+ name : Package
33on :
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,110 @@ 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 }})
84+ echo --- Coverage by unit tests ---
85+ line_coverage=$(xmllint --xpath "string(//coverage/@line-rate)" ${{ steps.files.outputs.UNIT_COVERAGE_FILE }})
86+ echo Line coverage: $line_coverage
87+ echo "LineCoverageUnit=$line_coverage" >> $GITHUB_OUTPUT
88+ echo "LINE_COVERAGE_UNIT=$line_coverage" >> $GITHUB_ENV
89+ branch_coverage=$(xmllint --xpath "string(//coverage/@branch-rate)" ${{ steps.files.outputs.UNIT_COVERAGE_FILE }})
90+ echo Branch coverage: $branch_coverage"
91+ echo "BranchCoverageUnit=$branch_coverage" >> $GITHUB_OUTPUT
92+ echo "BRANCH_COVERAGE_UNIT=$branch_coverage" >> $GITHUB_ENV
93+ echo --- Coverage by acceptance tests ---
94+ line_coverage=$(xmllint --xpath "string(//coverage/@line-rate)" ${{ steps.files.outputs.ACCEPTANCE_COVERAGE_FILE }})
7195 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 }})
96+ echo "LineCoverageAcceptance =$line_coverage" >> $GITHUB_OUTPUT
97+ echo "LINE_COVERAGE_ACCEPTANCE =$line_coverage" >> $GITHUB_ENV
98+ branch_coverage=$(xmllint --xpath "string(//coverage/@branch-rate)" ${{ steps.files.outputs.ACCEPTANCE_COVERAGE_FILE }})
7599 echo Branch coverage: $branch_coverage
76- echo "BranchCoverage=$branch_coverage" >> $GITHUB_OUTPUT
77- echo "BRANCH_COVERAGE=$branch_coverage" >> $GITHUB_ENV
100+ echo "BranchCoverageAcceptance=$branch_coverage" >> $GITHUB_OUTPUT
101+ echo "BRANCH_COVERAGE_ACCEPTANCE=$branch_coverage" >> $GITHUB_ENV
102+ lcu=$(printf "%1.4f" "$LineCoverageUnit")
103+ lca=$(printf "%1.4f" "$LineCoverageAcceptance")
104+ bcu=$(printf "%1.4f" "$BranchCoverageUnit")
105+ bca=$(printf "%1.4f" "$BranchCoverageAcceptance")
106+ # matrix="+------ COVERAGE MATRIX -------+"$'\n'
107+ # matrix+="| | Line | Branch |"$'\n'
108+ # matrix+="|------------|--------|--------|"$'\n'
109+ # matrix+="| Unit | $lcu | $bcu |"$'\n'
110+ # matrix+="| Acceptance | $lca | $bca |"$'\n'
111+ # matrix+="+------------------------------+"$'\n'
112+ # echo "$matrix"
113+ echo "+------ COVERAGE MATRIX -------+"
114+ echo "| | Line | Branch |"
115+ echo "|------------|--------|--------|"
116+ echo "| Unit | $lcu | $bcu |"
117+ echo "| Acceptance | $lca | $bca |"
118+ echo "+------------------------------+"
78119
79120 # The action below replaces the following command: dotnet tool run reportgenerator -reports:$coverage_file -targetdir:coveragereport-md -reporttypes:MarkdownSummaryGithub
80121 # Docs: https://reportgenerator.io/
81- - name : Generate coverage report (Markdown )
82- if : steps.files.outputs.COVERAGE_FILE_EXISTS == 'true'
122+ - name : Generate coverage report (Unit )
123+ if : steps.files.outputs.UNIT_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.UNIT_COVERAGE_FILE }}
127+ targetdir : coveragereport-u
128+ reporttypes : HtmlInline;MarkdownSummaryGithub
129+ - name : Generate coverage report (Acceptance)
130+ if : steps.files.outputs.ACCEPTANCE_COVERAGE_FILE_EXISTS == 'true'
131+ uses : danielpalme/ReportGenerator-GitHub-Action@5.4.7 # Docs: https://github.com/marketplace/actions/reportgenerator
132+ with :
133+ reports : ${{ steps.files.outputs.ACCEPTANCE_COVERAGE_FILE }}
134+ targetdir : coveragereport-a
135+ reporttypes : HtmlInline;MarkdownSummaryGithub
136+ - name : List report files
137+ run : |
138+ echo Listing files of unit-report...
139+ find coveragereport-u -type f -print | sort
140+ echo Listing files of acceptance-report...
141+ find coveragereport-a -type f -print | sort
88142
89143 # 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
144+ - name : Upload artifacts of coverage report (Unit)
145+ if : steps.files.outputs.UNIT_COVERAGE_FILE_EXISTS == 'true' && success()
91146 uses : actions/upload-artifact@v4 # https://github.com/actions/upload-artifact
92147 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
148+ name : CoverageReport-UnitTests # artifact name
149+ path : coveragereport-u # directory containing files to upload
150+ - name : Upload artifacts of coverage report (Acceptance)
151+ if : steps.files.outputs.ACCEPTANCE_COVERAGE_FILE_EXISTS == 'true' && success()
152+ uses : actions/upload-artifact@v4 # https://github.com/actions/upload-artifact
153+ with :
154+ name : CoverageReport-AcceptanceTests # artifact name
155+ path : coveragereport-a # directory containing files to upload
156+ - name : Publish coverage in job summary # only applicable if 'MarkdownSummaryGithub' or one of the other Markdown report types is generated
96157 run : |
97158 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
159+ find coveragereport-u/*.md -type f -print | sort
160+ find coveragereport-a/*.md -type f -print | sort
161+ # Re-format both MD-files for better presentation
162+ md=$'\n'
163+ md+="| _Coverage Matrix_ | Line | Branch |"$'\n'
164+ md+="| - | - | - |"$'\n'
165+ line=$(grep "|**Ocelot.Administration.IdentityServer4**|" coveragereport-u/SummaryGithub.md)
166+ line="${line/**Ocelot.Administration.IdentityServer4**/ Unit }"
167+ md+="$line\n"
168+ line=$(grep "|**Ocelot.Administration.IdentityServer4**|" coveragereport-a/SummaryGithub.md)
169+ line="${line/**Ocelot.Administration.IdentityServer4**/ Acceptance }"
170+ md+="$line\n"
171+ echo -e "Matrix markdown is >>$md"
172+ echo Reformatting MD-files...
173+ sed -i 's/# Summary/# Code Coverage Summary\n$md/g' coveragereport-u/SummaryGithub.md
174+ sed -i 's|<summary>Summary</summary>|<summary>Unit Tests</summary>|g' coveragereport-u/SummaryGithub.md
175+ sed -i 's/## Coverage/## Unit Test Coverage/g' coveragereport-u/SummaryGithub.md
176+ sed -i 's/# Summary/\n---\n/g' coveragereport-a/SummaryGithub.md
177+ sed -i 's|<summary>Summary</summary>|<summary>Acceptance Tests</summary>|g' coveragereport-a/SummaryGithub.md
178+ sed -i 's/## Coverage/## Acceptance Test Coverage/g' coveragereport-a/SummaryGithub.md
179+ # 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
180+ echo Publishing coverage in job summary...
181+ cat coveragereport-u/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
182+ cat coveragereport-a/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
101183 shell : bash
102184
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-
122185 publish :
123186 needs : build
124187 runs-on : ubuntu-latest
@@ -156,13 +219,13 @@ jobs:
156219 run : dotnet restore ./Ocelot.Administration.IdentityServer4.sln
157220
158221 - name : Build project
159- run : dotnet build ./src/Ocelot.Administration.IdentityServer4.csproj --configuration Release --no-restore
222+ run : dotnet build ./src/Ocelot.Administration.IdentityServer4.csproj --configuration Release --no-restore /p:ContinuousIntegrationBuild=true
160223
161224 - name : Pack project
162225 run : dotnet pack ./src/Ocelot.Administration.IdentityServer4.csproj --configuration Release --output ./packages
163226
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
227+ # - name: Publish to GitHub Packages
228+ # run: dotnet nuget push ./packages/*.nupkg --source "https://nuget.pkg.github.com/ThreeMammals/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
166229
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
230+ # - name: Publish to NuGet
231+ # run: dotnet nuget push ./packages/*.nupkg --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY_2025 }} --skip-duplicate
0 commit comments