-
Notifications
You must be signed in to change notification settings - Fork 0
255 lines (243 loc) · 12.1 KB
/
publish.yml
File metadata and controls
255 lines (243 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# Publishes beta-versions only
name: Publish
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check .NET 10
id: check-dotnet10
run: |
dotnet --version
echo -------------------------------
MY_DOTNET_VERSION=$(dotnet --version)
if [[ "$MY_DOTNET_VERSION" =~ ^10\.0\.[0-9]+$ ]]; then
echo "dotnet10_installed=true" >> $GITHUB_ENV
else
echo "dotnet10_installed=false" >> $GITHUB_ENV
fi
- name: Setup .NET 10
if: env.dotnet10_installed == 'false'
uses: actions/setup-dotnet@v5 # https://github.com/actions/setup-dotnet
with:
dotnet-version: 10.0.x
dotnet-quality: 'ga'
- name: Checkout
uses: actions/checkout@v6 # https://github.com/actions/checkout
- name: Restore
run: dotnet restore ./Ocelot.Tracing.OpenTracing.slnx -p:TargetFramework=net10.0
- name: Build
run: dotnet build --no-restore ./Ocelot.Tracing.OpenTracing.slnx --framework net10.0
- name: Unit tests
run: dotnet test --no-restore --no-build ./unit/Ocelot.Tracing.OpenTracing.UnitTests.csproj --collect:"XPlat Code Coverage" --framework net10.0
- name: Acceptance tests
run: dotnet test --no-restore --no-build ./acceptance/Ocelot.Tracing.OpenTracing.Acceptance.csproj --collect:"XPlat Code Coverage" --framework net10.0
- name: Find files
id: files
run: |
echo "GITHUB REF is ${{ github.ref }}"
echo "GITHUB REF NAME is ${{ github.ref_name }}"
echo "GITHUB SHA is ${{ github.sha }}"
# Coverage by unit tests -> https://github.com/coverlet-coverage/coverlet
coverage_1st_folder=$(ls -d ./unit/TestResults/*/ | head -1)
echo "Detected first folder : $coverage_1st_folder"
coverage_file="${coverage_1st_folder%/}/coverage.cobertura.xml"
echo "Detecting unit coverage file... -> $coverage_file"
if [ -f "$coverage_file" ]; then
echo Unit coverage file exists.
echo "UNIT_COVERAGE_FILE_EXISTS=true" >> $GITHUB_OUTPUT
echo "UNIT_COVERAGE_FILE=$coverage_file" >> $GITHUB_OUTPUT
else
echo Unit coverage file DOES NOT exist!
echo "UNIT_COVERAGE_FILE_EXISTS=false" >> $GITHUB_OUTPUT
exit 1
fi
# Coverage by acceptance tests -> https://github.com/coverlet-coverage/coverlet
coverage_1st_folder=$(ls -d ./acceptance/TestResults/*/ | head -1)
echo "Detected first folder : $coverage_1st_folder"
coverage_file="${coverage_1st_folder%/}/coverage.cobertura.xml"
echo "Detecting acceptance coverage file... -> $coverage_file"
if [ -f "$coverage_file" ]; then
echo Acceptance coverage file exists.
echo "ACCEPTANCE_COVERAGE_FILE_EXISTS=true" >> $GITHUB_OUTPUT
echo "ACCEPTANCE_COVERAGE_FILE=$coverage_file" >> $GITHUB_OUTPUT
else
echo Acceptance coverage file DOES NOT exist!
echo "ACCEPTANCE_COVERAGE_FILE_EXISTS=false" >> $GITHUB_OUTPUT
exit 1
fi
- name: Install tools
run: |
# .NET tools aka .config/dotnet-tools.json
echo Installing .NET tools aka dotnet-tools.json ...
dotnet tool restore
# Install XML tools
echo Installing XML tools ...
sudo apt update
sudo apt install libxml2-utils # aka xmllint read-command. xmlstarlet is not required
# Extract actual coverage % from the Coverlet XML-file
- name: Read coverage
id: coverage
run: |
echo Coverage by unit tests
line_coverage_u=$(xmllint --xpath "string(//coverage/@line-rate)" ${{ steps.files.outputs.UNIT_COVERAGE_FILE }})
echo " Line coverage: $line_coverage_u"
echo "LineCoverageUnit=$line_coverage_u" >> $GITHUB_OUTPUT
echo "LINE_COVERAGE_UNIT=$line_coverage_u" >> $GITHUB_ENV
branch_coverage_u=$(xmllint --xpath "string(//coverage/@branch-rate)" ${{ steps.files.outputs.UNIT_COVERAGE_FILE }})
echo " Branch coverage: $branch_coverage_u"
echo "BranchCoverageUnit=$branch_coverage_u" >> $GITHUB_OUTPUT
echo "BRANCH_COVERAGE_UNIT=$branch_coverage_u" >> $GITHUB_ENV
echo Coverage by acceptance tests
line_coverage_a=$(xmllint --xpath "string(//coverage/@line-rate)" ${{ steps.files.outputs.ACCEPTANCE_COVERAGE_FILE }})
echo " Line coverage: $line_coverage_a"
echo "LineCoverageAcceptance=$line_coverage_a" >> $GITHUB_OUTPUT
echo "LINE_COVERAGE_ACCEPTANCE=$line_coverage_a" >> $GITHUB_ENV
branch_coverage_a=$(xmllint --xpath "string(//coverage/@branch-rate)" ${{ steps.files.outputs.ACCEPTANCE_COVERAGE_FILE }})
echo " Branch coverage: $branch_coverage_a"
echo "BranchCoverageAcceptance=$branch_coverage_a" >> $GITHUB_OUTPUT
echo "BRANCH_COVERAGE_ACCEPTANCE=$branch_coverage_a" >> $GITHUB_ENV
lcu=$(printf "%1.4f" $line_coverage_u)
lca=$(printf "%1.4f" $line_coverage_a)
bcu=$(printf "%1.4f" $branch_coverage_u)
bca=$(printf "%1.4f" $branch_coverage_a)
echo '+------ COVERAGE MATRIX -------+'
echo '| | Line | Branch |'
echo '|------------|--------|--------|'
echo '| Unit |' $lcu \| $bcu \|
echo '| Acceptance |' $lca \| $bca \|
echo '+------------------------------+'
# The action below replaces the following command: dotnet tool run reportgenerator -reports:$coverage_file -targetdir:coveragereport-md -reporttypes:MarkdownSummaryGithub
# Docs: https://reportgenerator.io/
- name: Generate coverage report (Unit)
if: steps.files.outputs.UNIT_COVERAGE_FILE_EXISTS == 'true'
uses: danielpalme/ReportGenerator-GitHub-Action@5.5.1 # Docs: https://github.com/marketplace/actions/reportgenerator
with:
reports: ${{ steps.files.outputs.UNIT_COVERAGE_FILE }}
targetdir: coveragereport-u
reporttypes: HtmlInline;MarkdownSummaryGithub
- name: Generate coverage report (Acceptance)
if: steps.files.outputs.ACCEPTANCE_COVERAGE_FILE_EXISTS == 'true'
uses: danielpalme/ReportGenerator-GitHub-Action@5.5.1 # Docs: https://github.com/marketplace/actions/reportgenerator
with:
reports: ${{ steps.files.outputs.ACCEPTANCE_COVERAGE_FILE }}
targetdir: coveragereport-a
reporttypes: HtmlInline;MarkdownSummaryGithub
- name: List report files
run: |
echo Listing files of unit-report...
find coveragereport-u -type f -print | sort
echo Listing files of acceptance-report...
find coveragereport-a -type f -print | sort
# 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
- name: Upload artifacts of coverage report (Unit)
if: steps.files.outputs.UNIT_COVERAGE_FILE_EXISTS == 'true' && success()
uses: actions/upload-artifact@v6 # https://github.com/actions/upload-artifact
with:
name: CoverageReport-UnitTests # artifact name
path: coveragereport-u # directory containing files to upload
- name: Upload artifacts of coverage report (Acceptance)
if: steps.files.outputs.ACCEPTANCE_COVERAGE_FILE_EXISTS == 'true' && success()
uses: actions/upload-artifact@v6 # https://github.com/actions/upload-artifact
with:
name: CoverageReport-AcceptanceTests # artifact name
path: coveragereport-a # directory containing files to upload
- name: Publish coverage in job summary # only applicable if 'MarkdownSummaryGithub' or one of the other Markdown report types is generated
if: steps.files.outputs.UNIT_COVERAGE_FILE_EXISTS == 'true' && success()
run: |
echo "::group::Listing files of MD report"
find coveragereport-u/*.md -type f -print | sort
find coveragereport-a/*.md -type f -print | sort
echo "::endgroup::"
echo "::group::SummaryGithub.md"
cat coveragereport-u/SummaryGithub.md
echo "::endgroup::"
echo Reformat both MD-files for better presentation
file_u="coveragereport-u/SummaryGithub.md"
file_a="coveragereport-a/SummaryGithub.md"
md='| _Coverage Matrix_ | Line | Branch |'$'\n'
md+='| - | - | - |'$'\n'
line=$(grep -F "|**Ocelot.Tracing.OpenTracing**|" $file_u)
line="${line/Ocelot.Tracing.OpenTracing/Unit}"
line="${line//\*\*/ }"
md+=$line$'\n'
line=$(grep -F "|**Ocelot.Tracing.OpenTracing**|" $file_a)
line="${line/Ocelot.Tracing.OpenTracing/Acceptance}"
line="${line//\*\*/ }"
md+=$line$'\n'$'\n'
md+='---'$'\n'
echo Matrix markdown is "$md"
escaped_md="${md//|/\\|}"
escaped_md="${escaped_md//./\\.}"
escaped_md="${escaped_md//$'\n'/\\n}"
echo Escaped markdown is $escaped_md
echo Reformatting MD-files...
# Unit
sed -i 's/# Summary/# Code Coverage Summary/g' $file_u
sed -i "1a $escaped_md" $file_u # insert markdown-string after the 1st line
sed -i 's|<details open><summary>Summary</summary>|<details><summary>Coverage Summary</summary>|g' $file_u
sed -i '/## Coverage/d' $file_u # delete line
sed -i '/<details><summary>Coverage Summary/i ## Unit Test Coverage' $file_u # insert line
# Acceptance
sed -i 's/# Summary/\n---\n/g' $file_a
sed -i 's|<details open><summary>Summary</summary>|<details><summary>Coverage Summary</summary>|g' $file_a
sed -i '/## Coverage/d' $file_a # delete line
sed -i '/<details><summary>Coverage Summary/i ## Acceptance Test Coverage' $file_a # insert line
# 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
echo Publishing coverage in job summary...
cat $file_u >> $GITHUB_STEP_SUMMARY
cat $file_a >> $GITHUB_STEP_SUMMARY
shell: bash
- name: Codecov
if: steps.files.outputs.UNIT_COVERAGE_FILE_EXISTS == 'true' && success()
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ThreeMammals/Ocelot.Tracing.OpenTracing
files: ${{ steps.files.outputs.UNIT_COVERAGE_FILE }}
flags: unit
continue-on-error: true
publish:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: .NET Version
run: dotnet --version
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: .NET Info
run: dotnet --info
- name: Checkout repository
uses: actions/checkout@v6
- name: README.md
run: |
echo "::group::Original README.md"
cat README.md
echo "::endgroup::"
echo ------------------------
# Replaces relative GitHub paths with NuGet-friendly absolute URLs
sed -i 's|/ocelot_icon.png|https://raw.githubusercontent.com/ThreeMammals/Ocelot.Tracing.OpenTracing/refs/heads/main/ocelot_icon.png|g; s|/opentracing_icon.png|https://raw.githubusercontent.com/ThreeMammals/Ocelot.Tracing.OpenTracing/refs/heads/main/opentracing_icon.png|g' README.md
# Removes tags <sub> and </sub>
sed -i 's/<\/\?sub>//g' README.md
echo "::group::New content of README.md"
cat README.md
echo "::endgroup::"
- name: Restore dependencies
run: dotnet restore ./Ocelot.Tracing.OpenTracing.slnx
- name: Pack project
run: dotnet pack ./src/Ocelot.Tracing.OpenTracing.csproj --configuration Release --output ./packages /p:ContinuousIntegrationBuild=true
- name: Publish to GitHub Packages
run: dotnet nuget push ./packages/*.nupkg --source "https://nuget.pkg.github.com/ThreeMammals/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
- name: Publish to NuGet
run: dotnet nuget push ./packages/*.nupkg --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY_2025 }} --skip-duplicate