-
Notifications
You must be signed in to change notification settings - Fork 1
363 lines (324 loc) · 11.2 KB
/
Copy pathci.yml
File metadata and controls
363 lines (324 loc) · 11.2 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
env:
DOTNET_NOLOGO: true
TEST_RESULTS_DIR: artifacts/test-results
jobs:
pr-checks:
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
global-json-file: global.json
- name: Restore
run: dotnet restore JD.AI.slnx
- name: Build (Release)
run: >
dotnet build JD.AI.slnx
--configuration Release
--no-restore
/p:ContinuousIntegrationBuild=true
- name: Verify formatting
run: >
dotnet format JD.AI.slnx
--severity warn
--verify-no-changes
- name: Test with coverage
timeout-minutes: 15
run: >
dotnet test JD.AI.slnx
--configuration Release
--no-build
--results-directory ${{ env.TEST_RESULTS_DIR }}
--filter "Category!=Integration&Category!=MlModel&Category!=FlakyEnvironment&Category!=E2E"
--collect:"XPlat Code Coverage"
--blame-hang-timeout 5m
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include="[JD.AI*]*"
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude="[*Tests]*"
- name: Install ReportGenerator
if: always()
run: dotnet tool update -g dotnet-reportgenerator-globaltool --version 5.5.4
- name: Combine coverage reports
if: always()
shell: bash
run: |
REPORTS=$(find "${TEST_RESULTS_DIR}" -type f -name "coverage.cobertura.xml" 2>/dev/null | tr '\n' ';')
if [ -z "$REPORTS" ] || [ "$REPORTS" = ";" ]; then
echo "No coverage files found — skipping report generation."
exit 0
fi
reportgenerator \
-reports:"$REPORTS" \
-targetdir:"coverage-report" \
-reporttypes:"HtmlInline;Cobertura;TextSummary;Badges" \
-assemblyfilters:"+JD.AI*;-*Tests*" \
-filefilters:"-**/*.Tests/*;-**/*Tests*/**"
echo "COVERAGE_SUMMARY<<EOF" >> $GITHUB_ENV
awk '/^[^ ]/ && NR>1 {exit} {print}' coverage-report/Summary.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: coverage-report
- name: Upload to Codecov
if: always()
continue-on-error: true
uses: codecov/codecov-action@v6
with:
files: coverage-report/Cobertura.xml
disable_search: true
handle_no_reports_found: true
fail_ci_if_error: false
- name: Enforce coverage floor
if: always()
shell: bash
env:
MIN_LINE_COVERAGE: "60"
run: |
if [ ! -f coverage-report/Cobertura.xml ]; then
echo "Coverage report missing."
exit 1
fi
python - <<'PY'
import os
import xml.etree.ElementTree as ET
min_cov = float(os.environ["MIN_LINE_COVERAGE"])
rate = float(ET.parse("coverage-report/Cobertura.xml").getroot().attrib["line-rate"]) * 100
if rate < min_cov:
raise SystemExit(f"Coverage {rate:.2f}% is below {min_cov:.2f}%")
print(f"Coverage {rate:.2f}% meets threshold {min_cov:.2f}%")
PY
- name: Add coverage summary to PR
if: always() && github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v3
with:
recreate: true
message: |
## Code Coverage
```
${{ env.COVERAGE_SUMMARY }}
```
release:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
global-json-file: global.json
- name: Restore
run: dotnet restore JD.AI.slnx
- name: Determine version (NBGV)
id: nbgv
uses: dotnet/nbgv@81f7c98786b56d9fa30c96223e7147d9bb582ff7 # node24 (unreleased past v0.5.1; pin SHA until v0.5.2 ships)
with:
setAllVars: true
- name: Build (Release)
run: >
dotnet build JD.AI.slnx
--configuration Release
--no-restore
/p:ContinuousIntegrationBuild=true
- name: Test (Release)
timeout-minutes: 15
run: >
dotnet test JD.AI.slnx
--configuration Release
--no-build
--results-directory ${{ env.TEST_RESULTS_DIR }}
--filter "Category!=Integration&Category!=MlModel&Category!=FlakyEnvironment&Category!=E2E"
--collect:"XPlat Code Coverage"
--blame-hang-timeout 5m
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include="[JD.AI*]*"
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude="[*Tests]*"
- name: Install ReportGenerator
if: always()
run: dotnet tool update -g dotnet-reportgenerator-globaltool --version 5.5.4
- name: Combine coverage reports
if: always()
shell: bash
run: |
REPORTS=$(find "${TEST_RESULTS_DIR}" -type f -name "coverage.cobertura.xml" 2>/dev/null | tr '\n' ';')
if [ -z "$REPORTS" ] || [ "$REPORTS" = ";" ]; then
echo "No coverage files found — skipping report generation."
exit 0
fi
reportgenerator \
-reports:"$REPORTS" \
-targetdir:"coverage-report" \
-reporttypes:"HtmlInline;Cobertura;TextSummary;Badges" \
-assemblyfilters:"+JD.AI*;-*Tests*" \
-filefilters:"-**/*.Tests/*;-**/*Tests*/**"
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: coverage-report
- name: Upload to Codecov
if: always()
uses: codecov/codecov-action@v6
with:
files: coverage-report/Cobertura.xml
token: ${{ secrets.CODECOV_TOKEN }}
disable_search: true
handle_no_reports_found: true
fail_ci_if_error: false
- name: Enforce coverage floor
if: always()
shell: bash
env:
MIN_LINE_COVERAGE: "60"
run: |
if [ ! -f coverage-report/Cobertura.xml ]; then
echo "Coverage report missing."
exit 1
fi
python - <<'PY'
import os
import xml.etree.ElementTree as ET
min_cov = float(os.environ["MIN_LINE_COVERAGE"])
rate = float(ET.parse("coverage-report/Cobertura.xml").getroot().attrib["line-rate"]) * 100
if rate < min_cov:
raise SystemExit(f"Coverage {rate:.2f}% is below {min_cov:.2f}%")
print(f"Coverage {rate:.2f}% meets threshold {min_cov:.2f}%")
PY
- name: Pack
run: >
dotnet pack JD.AI.slnx
--configuration Release
--no-build
--output ./artifacts
/p:ContinuousIntegrationBuild=true
- name: Upload packages
uses: actions/upload-artifact@v7
with:
name: nuget-packages
path: ./artifacts/*.nupkg
- name: Push to NuGet.org
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
if [ -n "$NUGET_API_KEY" ]; then
dotnet nuget push ./artifacts/*.nupkg \
--api-key "$NUGET_API_KEY" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
else
echo "Skipping NuGet.org push: API key not set."
fi
- name: Push to GitHub Packages
run: |
dotnet nuget push "./artifacts/*.nupkg" \
--source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
--api-key "${{ secrets.GITHUB_TOKEN }}" \
--skip-duplicate
- name: Create git tag
shell: bash
run: |
set -euo pipefail
TAG="v${NBGV_NuGetPackageVersion}"
if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists — skipping."
else
git tag "$TAG"
git push origin "$TAG"
echo "Created tag $TAG"
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: v${{ env.NBGV_NuGetPackageVersion }}
name: Release v${{ env.NBGV_NuGetPackageVersion }}
files: |
./artifacts/*.nupkg
generate_release_notes: true
outputs:
version: ${{ env.NBGV_NuGetPackageVersion }}
publish-binaries:
needs: release
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
strategy:
fail-fast: false
matrix:
include:
- rid: win-x64
os: windows-latest
archive: zip
- rid: win-arm64
os: windows-latest
archive: zip
- rid: linux-x64
os: ubuntu-latest
archive: tar.gz
- rid: linux-arm64
os: ubuntu-latest
archive: tar.gz
- rid: osx-x64
os: macos-latest
archive: tar.gz
- rid: osx-arm64
os: macos-latest
archive: tar.gz
runs-on: ${{ matrix.os }}
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
global-json-file: global.json
- name: Publish self-contained binary
env:
GITHUB_ACTIONS: "false"
run: >
dotnet publish src/JD.AI/JD.AI.csproj
--configuration Release
--runtime ${{ matrix.rid }}
--self-contained
-p:PublishSingleFile=true
-p:IncludeNativeLibrariesForSelfExtract=true
-p:ContinuousIntegrationBuild=true
--output ./publish
- name: Archive (zip)
if: matrix.archive == 'zip'
shell: pwsh
run: Compress-Archive -Path ./publish/* -DestinationPath ./jdai-${{ matrix.rid }}.zip
- name: Archive (tar.gz)
if: matrix.archive == 'tar.gz'
run: tar -czf ./jdai-${{ matrix.rid }}.tar.gz -C ./publish .
- name: Upload to GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: v${{ needs.release.outputs.version }}
files: |
./jdai-${{ matrix.rid }}.${{ matrix.archive }}