-
-
Notifications
You must be signed in to change notification settings - Fork 748
435 lines (369 loc) · 12.3 KB
/
ci.yml
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
name: CI
on:
pull_request_target:
branches:
- main
concurrency:
group: ci-new-2-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
check-changes:
name: Check for Changes
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
outputs:
website_changes: ${{ steps.check-website.outputs.website_changes }}
library_changes: ${{ steps.check-library.outputs.library_changes }}
src_changes: ${{ steps.check-src.outputs.src_changes }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Check for changes in website directory
id: check-website
run: |
changes=$(git diff --name-only HEAD~1 HEAD -- ./website)
if [[ -n "$changes" ]]; then
echo "::set-output name=website_changes::true"
else
echo "::set-output name=website_changes::false"
fi
- name: Check for changes outside website directory
id: check-library
run: |
changes=$(git diff --name-only HEAD~1 HEAD -- ':!./website')
if [[ -n "$changes" ]]; then
echo "::set-output name=library_changes::true"
else
echo "::set-output name=library_changes::false"
fi
- name: Check for changes in src directory
id: check-src
run: |
changes=$(git diff --name-only HEAD~1 HEAD -- ./src)
if [[ -n "$changes" ]]; then
echo "::set-output name=src_changes::true"
else
echo "::set-output name=src_changes::false"
fi
pr-labeler:
name: Apply Labels
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/labeler@v3
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
spellcheck:
name: "Spellcheck Documentation"
runs-on: ubuntu-latest
needs: check-changes
if: needs.check-changes.outputs.website_changes == 'true'
steps:
- uses: actions/checkout@v2
name: Check out the code
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: '16.x'
cache: 'yarn'
cache-dependency-path: 'website/yarn.lock'
- name: Install cspell
run: npm install -g cspell
- name: run cspell
run: cspell --config ./cSpell.json "website/src/**/*.md" --no-progress
website-tests:
name: "Website Tests"
needs: check-changes
if: needs.check-changes.outputs.website_changes == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: '14.x'
cache: 'yarn'
cache-dependency-path: 'website/yarn.lock'
- name: Cache Yarn Packages
uses: actions/cache@v3
with:
path: |
website/.yarn/cache
website/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('website/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Packages
run: yarn --immutable --network-timeout 100000
working-directory: website
- name: Build Website
run: yarn build --prefix-paths
working-directory: website
configure:
name: Generate Test Matrix
runs-on: ubuntu-latest
needs: check-changes
if: needs.check-changes.outputs.library_changes == 'true'
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout to repository
uses: actions/checkout@v3
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
7.x
8.x
- name: Generate Test Matrix
run: dotnet run --project ./.build -- GenerateMatrix
- name: Export Test Matrix
id: set-matrix
run: echo "matrix=$(jq -c . < ./matrix.json)" >> $GITHUB_OUTPUT
library-tests:
name: Run ${{ matrix.name }}
runs-on: ubuntu-latest
needs: [configure, check-changes]
if: needs.check-changes.outputs.library_changes == 'true'
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.configure.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.x
7.x
8.x
- uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Run Build
id: run-build
run: dotnet build ${{ matrix.path }} --framework net7.0 --verbosity q --property WarningLevel=0
timeout-minutes: 5
- name: Create directory for test results
run: mkdir -p ./.test-results
- name: Run tests
id: run-tests
timeout-minutes: 15
continue-on-error: true
run: |
dotnet test ${{ matrix.path }} --no-build --framework net7.0 --verbosity q /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=./.coverage/${{ matrix.name }}.xml --logger "trx;LogFileName=./.test-results/${{ matrix.name }}.trx" /p:ExcludeByFile="**/test/**" 2>&1 | tee test_output.txt
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
exit 1
fi
env:
CI_BUILD: true
- name: Upload test_output.txt for debugging
if: steps.run-tests.outcome == 'failure'
uses: actions/upload-artifact@v2
with:
name: test-output
path: test_output.txt
- name: Post test results to PR
if: steps.run-tests.outcome == 'failure'
run: |
# Check if test_output.txt exists
if [[ ! -f test_output.txt ]]; then
echo "test_output.txt does not exist."
exit 1
fi
# Get the failed tests (or continue if no match is found)
FAILED_TESTS=$(grep ".*\[FAIL\]$" test_output.txt || true)
# Iterate through the failed tests to prepare the comment
echo "$FAILED_TESTS" | while read -r test; do
TEST_NAME=$(echo $test | awk '{$NF=""; print $0}' | sed 's/ *$//' | sed 's/^\[xUnit\.net [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9]\] //')
MISMATCH_FILE=$(find . -name "__mismatch__" -type d | xargs -I {} find {} -name "$TEST_NAME.*" || true)
if [[ -f $MISMATCH_FILE ]]; then
CONTENT=$(cat $MISMATCH_FILE)
echo "${TEST_NAME} [FAIL]" >> comment.txt
echo "**$CONTENT**" >> comment.txt
else
echo "${TEST_NAME} [FAIL]" >> comment.txt
fi
done
# Use GitHub environment variable to get the PR number
PR_NUMBER=${{ github.event.pull_request.number }}
# Comment on the PR using the PR number
gh pr comment $PR_NUMBER --body-file comment.txt
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Copy test results
continue-on-error: true
run: |
mkdir -p ./output/coverage
mkdir -p ./output/test-results
cp "${{ matrix.directoryPath }}/.coverage/${{ matrix.name }}.net7.0.xml" ./output/coverage/
cp "${{ matrix.directoryPath }}/.test-results/${{ matrix.name }}.net7.0.xml" ./output/test-results/
- name: Upload Test Results as Artifacts
if: always()
uses: actions/upload-artifact@v2
with:
name: test-results-${{ matrix.name }}
path: ./output/test-results/*.trx
- name: Upload Coverage Files as Artifacts
if: always()
uses: actions/upload-artifact@v2
with:
name: coverage-${{ matrix.name }}
path: ./output/coverage/*.xml
- name: Upload mismatch files as Artifacts
if: steps.run-tests.outcome == 'failure'
uses: actions/upload-artifact@v2
with:
name: mismatch-files-${{ matrix.name }}
path: |
**/__mismatch__/*
- name: Fail if tests failed or were cancelled
run: exit 1
if: |
steps.run-tests.outcome == 'failure' ||
steps.run-tests.outcome == 'cancelled'
sonar:
runs-on: ubuntu-latest
name: Sonar Pull-Request
needs: check-changes
if: needs.check-changes.outputs.library_changes == 'true'
steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Java
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
architecture: x64
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.x
7.x
8.x
- uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Run Sonar Analysis
run: ./build.cmd SonarPr --SonarToken $SONARTOKEN
env:
HC_GITHUB_PR_NR: ${{ github.event.pull_request.number }}
HC_GITHUB_HEAD_REF: ${{ github.event.pull_request.head.ref }}
HC_GITHUB_BASE_REF: ${{ github.event.pull_request.base.ref }}
GITHUB_REPOSITORY: ${{ github.repository }}
SONARTOKEN: ${{ secrets.SONARTOKEN }}
codeql:
name: CodeQL
runs-on: ubuntu-latest
needs: check-changes
if: needs.check-changes.outputs.src_changes == 'true'
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.x
7.x
8.x
- uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore
run: ./build.sh restore
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: csharp
- name: Build
run: dotnet build ./src/All.sln --no-restore
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
merge-coverage:
name: Merge and Upload Coverage
needs: library-tests
if: always() && needs.library-tests.result != 'cancelled'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install .NET
if: ${{ !cancelled() }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.x
7.x
8.x
- uses: actions/cache@v3
if: ${{ !cancelled() }}
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Create All.sln
if: ${{ !cancelled() }}
run: ./build.sh CreateAllSln
- name: Build
if: ${{ !cancelled() }}
run: dotnet build ./src/All.sln
- name: Download all coverage artifacts
if: ${{ !cancelled() }}
uses: actions/download-artifact@v2
with:
path: ./output/download
- name: Merge Coverage Files
if: ${{ !cancelled() }}
timeout-minutes: 10
run: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator "-reports:./output/download/**/*.xml" "-targetdir:./output/coverage/merged" -reporttypes:Opencover -license:$ReportGenerator_License
env:
ReportGenerator_License: ${{ secrets.REPORTGENERATOR_LICENSE }}
- name: Upload Combined Coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v2
timeout-minutes: 10
with:
file: ./output/coverage/merged/OpenCover.xml
token: ${{ secrets.CODECOV_TOKEN }}
name: graphql-platform
flags: unittests
fail_ci_if_error: true
ci-status-check:
name: "CI Status Check"
needs: [library-tests, website-tests]
if: always()
runs-on: ubuntu-latest
steps:
- name: Check if Library Tests or Website Tests failed
run: exit 1
if: |
always() &&
(needs.library-tests.result == 'failure' ||
needs.website-tests.result == 'failure')