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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
|
name: Run build and tests (ya make)
description: Run test targets listed in repository root ya.make (to be created previously)
inputs:
build_target:
required: true
build_preset:
required: true
default: "relwithdebinfo"
description: "relwithdebinfo, release-asan, release-tsan"
test_type:
required: false
type: string
default: ""
description: "run only specific test types (or all by default)"
test_size:
required: false
default: "small,medium,large"
description: "small or small-medium or all"
test_threads:
required: false
default: "56"
description: "Test threads count"
link_threads:
required: false
default: "12"
description: "link threads count"
additional_ya_make_args:
type: string
default: ""
testman_token:
required: false
description: "test manager auth token"
testman_url:
required: false
description: "test manager endpoint"
testman_project_id:
required: false
description: "test manager project id"
put_build_results_to_cache:
required: false
default: "true"
bazel_remote_uri:
required: false
description: "bazel-remote endpoint"
bazel_remote_username:
required: false
description: "bazel-remote username"
bazel_remote_password:
required: false
description: "bazel-remote password"
run_tests:
type: boolean
default: true
description: "run tests"
outputs:
success:
value: ${{ steps.build.outputs.status }}
description: "build success"
runs:
using: "composite"
steps:
- name: Install Node required for Testmo CLI
uses: actions/setup-node@v3
with:
node-version: 19
- name: Init
id: init
shell: bash
run: |
set -x
export TMP_DIR=$(pwd)/tmp
rm -rf $TMP_DIR
mkdir -p $TMP_DIR
echo "TMP_DIR=$TMP_DIR" >> $GITHUB_ENV
export LOG_DIR=$TMP_DIR/logs
echo "LOG_DIR=$LOG_DIR" >> $GITHUB_ENV
mkdir -p $LOG_DIR
export OUT_DIR=$TMP_DIR/out
echo "OUT_DIR=$OUT_DIR" >> $GITHUB_ENV
mkdir -p $OUT_DIR
export ARTIFACTS_DIR=$TMP_DIR/artifacts
echo "ARTIFACTS_DIR=$ARTIFACTS_DIR" >> $GITHUB_ENV
mkdir -p $ARTIFACTS_DIR
export TEST_ARTIFACTS_DIR=$TMP_DIR/test_artifacts
echo "TEST_ARTIFACTS_DIR=$TEST_ARTIFACTS_DIR" >> $GITHUB_ENV
mkdir -p $TEST_ARTIFACTS_DIR
export REPORTS_ARTIFACTS_DIR=$TMP_DIR/artifacts/test_reports
echo "REPORTS_ARTIFACTS_DIR=$REPORTS_ARTIFACTS_DIR" >> $GITHUB_ENV
mkdir -p $REPORTS_ARTIFACTS_DIR
export JUNIT_REPORT_PARTS=$TMP_DIR/junit-split
echo "JUNIT_REPORT_PARTS=$JUNIT_REPORT_PARTS" >> $GITHUB_ENV
mkdir -p $JUNIT_REPORT_PARTS
echo "JUNIT_REPORT_XML=$TMP_DIR/junit.xml" >> $GITHUB_ENV
echo "TESTMO_URL=${{ inputs.testman_url }}" >> $GITHUB_ENV
echo "SUMMARY_LINKS=$(mktemp)" >> $GITHUB_ENV
echo "BUILD_PRESET=${{ inputs.build_preset }}" >> $GITHUB_ENV
echo "YA_TEST_LOG_FILENAME=$LOG_DIR/ya_test.log" >> $GITHUB_ENV
echo "YA_TEST_LOG_URL=$S3_URL_PREFIX/test_logs/ya_test.log" >> $GITHUB_ENV
echo "S3_LOG_BUCKET_PATH=$S3_BUCKET_PATH/test_logs" >> $GITHUB_ENV
export log_url="$S3_URL_PREFIX/build_logs/ya_make.log"
echo "LOG_URL=$log_url" >> $GITHUB_ENV
echo "log_url=$log_url" >> $GITHUB_OUTPUT
# install test mo
npm install -g @testmo/testmo-cli
- name: Upload tests result to testmo
id: th
if: inputs.testman_token && inputs.run_tests
shell: bash
env:
PR_NUMBER: ${{ github.event.number }}
TESTMO_TOKEN: ${{ inputs.testman_token }}
run: |
set -x
RUN_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
BRANCH_TAG="$GITHUB_REF_NAME"
ARCH="${{ runner.arch == 'X64' && 'x86-64' || runner.arch == 'ARM64' && 'arm64' || 'unknown' }}"
case "$BUILD_PRESET" in
relwithdebinfo)
TESTMO_SOURCE="ya-${ARCH}"
;;
debug)
TESTMO_SOURCE="ya-${ARCH}-debug"
;;
release-*)
TESTMO_SOURCE="ya-${ARCH}-${BUILD_PRESET/release-/}"
;;
*)
echo "Invalid preset: $BUILD_PRESET"
exit 1
;;
esac
case $GITHUB_EVENT_NAME in
workflow_dispatch)
TESTMO_RUN_NAME="${{ github.run_id }} manual"
EXTRA_TAG="manual"
;;
pull_request | pull_request_target)
TESTMO_RUN_NAME="${{ github.run_id }} PR #${PR_NUMBER}"
EXTRA_TAG="pr"
BRANCH_TAG=""
;;
schedule)
TESTMO_RUN_NAME="${{ github.run_id }} schedule"
EXTRA_TAG="schedule"
;;
push)
TESTMO_RUN_NAME="${{ github.run_id }} POST"
EXTRA_TAG="post-commit"
;;
*)
TESTMO_RUN_NAME="${{ github.run_id }}"
EXTRA_TAG=""
;;
esac
testmo automation:resources:add-link --name build --url "$RUN_URL" --resources testmo.json
testmo automation:resources:add-field --name git-sha --type string --value "${GITHUB_SHA:0:7}" --resources testmo.json
RUN_ID=$(
testmo automation:run:create --instance "$TESTMO_URL" --project-id ${{ inputs.testman_project_id }} \
--name "$TESTMO_RUN_NAME" --source "$TESTMO_SOURCE" --resources testmo.json \
--tags "$BRANCH_TAG" --tags "$EXTRA_TAG"
)
echo "runid=${RUN_ID}" >> $GITHUB_OUTPUT
echo "TEST_HISTORY_URL=${TESTMO_URL}/automation/runs/view/${RUN_ID}" >> $GITHUB_ENV
# Print test history link
echo "10 [Test history](${TEST_HISTORY_URL})" >> $SUMMARY_LINKS
- name: set environment variables required by some tests
if: inputs.run_tests
shell: bash
run: |
echo "PSQL_BINARY=/usr/bin/psql" >> $GITHUB_ENV
- name: ya build and test
id: build
shell: bash
run: |
set -x
readarray -d ',' -t test_size < <(printf "%s" "${{ inputs.test_size }}")
readarray -d ',' -t test_type < <(printf "%s" "${{ inputs.test_type }}")
params=(
-T
${test_size[@]/#/--test-size=} ${test_type[@]/#/--test-type=}
--stat
--test-threads "${{ inputs.test_threads }}" --link-threads "${{ inputs.link_threads }}"
-DUSE_EAT_MY_DATA
)
case "$BUILD_PRESET" in
debug)
params+=(--build "debug")
;;
relwithdebinfo)
params+=(--build "relwithdebinfo")
;;
release)
params+=(--build "release")
;;
release-clang14)
params+=(--build "release")
params+=(--target-platform="CLANG14-LINUX-X86_64")
params+=(-DLLD_VERSION=16)
params+=(-DSTRIP)
;;
release-asan)
params+=(
--build "release" --sanitize="address"
-DDEBUGINFO_LINES_ONLY
)
;;
release-tsan)
params+=(
--build "release" --sanitize="thread"
-DDEBUGINFO_LINES_ONLY
)
;;
release-msan)
params+=(
--build "release" --sanitize="memory"
-DDEBUGINFO_LINES_ONLY
)
;;
*)
echo "Invalid preset: $BUILD_PRESET"
exit 1
;;
esac
if [ ! -z "${{ inputs.additional_ya_make_args }}" ]; then
params+=(${{ inputs.additional_ya_make_args }})
fi
if [ ! -z "${{ inputs.bazel_remote_uri }}" ]; then
params+=(--bazel-remote-store)
params+=(--bazel-remote-base-uri "${{ inputs.bazel_remote_uri }}")
fi
if [ "${{ inputs.put_build_results_to_cache }}" = "true" ]; then
params+=(--bazel-remote-username "${{ inputs.bazel_remote_username }}")
params+=(--bazel-remote-password "${{ inputs.bazel_remote_password }}")
params+=(--bazel-remote-put --dist-cache-max-file-size=209715200)
fi
if [ true = ${{ inputs.run_tests }} ]; then
params+=(-A)
fi
echo "::debug::get version"
./ya --version
echo "Build+Tests **{platform_name}-${BUILD_PRESET}** is running..." | GITHUB_TOKEN="${{ github.token }}" .github/scripts/tests/comment-pr.py
set +ex
(./ya make ${{ inputs.build_target }} "${params[@]}" \
--stat --log-file "$YA_TEST_LOG_FILENAME" -DCONSISTENT_DEBUG \
--no-dir-outputs --test-failure-code 0 --build-all \
--cache-size 2TB --force-build-depends --evlog-file "$TMP_DIR/ya_evlog.jsonl" \
--junit "$JUNIT_REPORT_XML" --output "$OUT_DIR"; echo $? > exit_code) |& tee $TMP_DIR/ya_make.log
set -ex
RC=`cat exit_code`
echo "10 [Ya make output]($LOG_URL)" >> $SUMMARY_LINKS
echo "20 [Ya logs]($YA_TEST_LOG_URL)" >> $SUMMARY_LINKS
if [ $RC -ne 0 ]; then
echo "ya make returned $RC, build failed"
echo "status=failed" >> $GITHUB_OUTPUT
else
echo "status=true" >> $GITHUB_OUTPUT
fi
- name: comment-build-status
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -x
if [ "${{ steps.build.outputs.status }}" == "failed" ]; then
curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
-d '{"state":"failure","description":"The check has been failed","context":"build_${{inputs.build_preset}}"}'
echo "Build failed. see the [logs]($LOG_URL)." | .github/scripts/tests/comment-pr.py --fail
else
curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
-d '{"state":"success","description":"The check has been completed successfully","context":"build_${{inputs.build_preset}}"}'
echo "Build successful." | .github/scripts/tests/comment-pr.py --ok
fi
- name: process reports
if: inputs.run_tests
shell: bash
run: |
set -x
# archive unitest reports (orig)
gzip -c $JUNIT_REPORT_XML > $REPORTS_ARTIFACTS_DIR/orig_junit.xml.gz
# postprocess junit report
.github/scripts/tests/transform-ya-junit.py -i \
-m .github/config/muted_ya.txt \
--ya-out "$OUT_DIR" \
--log-url-prefix "$S3_URL_PREFIX/logs/" \
--log-out-dir "$ARTIFACTS_DIR/logs/" \
--test-stuff-out "$TEST_ARTIFACTS_DIR/" \
--test-stuff-prefix "$S3_TEST_ARTIFACTS_URL_PREFIX/" \
"$JUNIT_REPORT_XML"
.github/scripts/tests/split-junit.py -o "$JUNIT_REPORT_PARTS" "$JUNIT_REPORT_XML"
# archive unitest reports (transformed)
tar -C $JUNIT_REPORT_PARTS/.. -czf $REPORTS_ARTIFACTS_DIR/junit_parts.xml.tar.gz $(basename $JUNIT_REPORT_PARTS)
- name: Test history upload results to YDB
if: inputs.run_tests
continue-on-error: true
shell: bash
env:
PR_NUMBER: ${{ github.event.number }}
JOB_NAME: ${{ github.workflow }}
JOB_ID: ${{github.run_id }}
run: |
set -x
python3 -m pip install ydb ydb[yc] codeowners
#Variables
echo "JUNIT_REPORT_XML=${JUNIT_REPORT_XML}"
echo "BUILD_PRESET=${BUILD_PRESET}"
echo "PR_NUMBER=${PR_NUMBER}"
echo "JOB_NAME=${JOB_NAME}"
echo "JOB_ID=${JOB_ID}"
echo "GITHUB_REF_NAME=${GITHUB_REF_NAME}"
result=`.github/scripts/upload_tests_results.py --test-results-file ${JUNIT_REPORT_XML} --run-timestamp $(date +%s) --commit $(git rev-parse HEAD) --build-type ${BUILD_PRESET} --pull ${PR_NUMBER} --job-name ${JOB_NAME} --job-id ${JOB_ID} --branch ${GITHUB_REF_NAME}`
- name: Unit test history upload results
if: inputs.testman_token && inputs.run_tests
shell: bash
env:
TESTMO_TOKEN: ${{ inputs.testman_token }}
run: |
set -x
PROXY_ADDR=127.0.0.1:8888
openssl req -x509 -newkey rsa:2048 \
-keyout $TMP_DIR/key.pem -out $TMP_DIR/cert.pem \
-sha256 -days 1 -nodes -subj "/CN=127.0.0.1"
./ydb/ci/testmo-proxy/testmo-proxy.py -l $PROXY_ADDR \
--cert-file "$TMP_DIR/cert.pem" \
--cert-key "$TMP_DIR/key.pem" \
--target-timeout 3,10 \
--max-request-time 55 \
"$TESTMO_URL" &
proxy_pid=$!
NODE_TLS_REJECT_UNAUTHORIZED=0 testmo automation:run:submit-thread \
--instance "https://$PROXY_ADDR" --run-id "${{ steps.th.outputs.runid }}" \
--results "$JUNIT_REPORT_PARTS/*.xml"
kill $proxy_pid
- name: Test history run complete
if: always() && inputs.testman_token && inputs.run_tests
shell: bash
env:
TESTMO_TOKEN: ${{ inputs.testman_token }}
run: |
testmo automation:run:complete --instance "$TESTMO_URL" --run-id ${{ steps.th.outputs.runid }}
- name: sync logs results to s3
if: always()
shell: bash
run: |
set -x
echo "::group::s3-sync"
s3cmd sync --follow-symlinks --acl-public --no-progress --stats --no-check-md5 "$LOG_DIR/" "$S3_LOG_BUCKET_PATH/"
s3cmd sync --acl-public --no-progress --stats --no-check-md5 "$TMP_DIR/ya_make.log" "$S3_BUCKET_PATH/build_logs/"
echo "::endgroup::"
- name: analyze tests results
shell: bash
if: always() && inputs.run_tests
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -x
if [ "${{ inputs.run_tests }}" != "true" ]; then
# I have no idea why 'always() && inputs.run_tests' not working
# Probably because of implicit bool->str cast?
exit 0
fi
mkdir $ARTIFACTS_DIR/summary/
cat $SUMMARY_LINKS | python3 -c 'import sys; print(" | ".join([v for _, v in sorted([l.strip().split(" ", 1) for l in sys.stdin], key=lambda a: (int(a[0]), a))]))' >> $GITHUB_STEP_SUMMARY
.github/scripts/tests/generate-summary.py \
--summary-out-path $ARTIFACTS_DIR/summary/ \
--summary-url-prefix $S3_URL_PREFIX/summary/ \
--test-history-url "$TEST_HISTORY_URL" \
--test-log-url="$YA_TEST_LOG_URL" \
--build-preset "$BUILD_PRESET" \
--status-report-file statusrep.txt \
"Tests" ya-test.html "$JUNIT_REPORT_XML"
teststatus=$(cat statusrep.txt)
if [[ $teststatus == "success" ]];then
testmessage="The check has been completed successfully"
else
testmessage="The check has been failed"
fi
curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
-d '{"state":"'$teststatus'","description":"'"$testmessage"'","context":"test_${{inputs.build_preset}}"}'
if [[ $teststatus != "success" ]];then
echo "status=failed" >> $GITHUB_OUTPUT
fi
- name: sync test results to s3
if: always() && inputs.run_tests
shell: bash
run: |
set -x
echo "::group::s3-sync"
s3cmd sync -r --follow-symlinks --acl-public --no-progress --stats --no-check-md5 "$ARTIFACTS_DIR/" "$S3_BUCKET_PATH/"
s3cmd sync -r --follow-symlinks --acl-public --no-progress --stats --no-check-md5 "$TEST_ARTIFACTS_DIR/" "$S3_TEST_ARTIFACTS_BUCKET_PATH/"
echo "::endgroup::"
- name: check test results
if: inputs.run_tests
shell: bash
run: |
.github/scripts/tests/fail-checker.py "$JUNIT_REPORT_XML"
- name: show free space
if: always()
shell: bash
run: df -h
|