Repository navigation
626 lines (591 loc) · 25.7 KB
/
Copy pathcpp_codecov.yml
File metadata and controls
626 lines (591 loc) · 25.7 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
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
name: Codecov C++ (SDK / CLI / workload)
# PR coverage intentionally uses pull_request_target: repository secrets and
# self-hosted runners are available only after the trusted workflow from main
# verifies that the PR author and event sender have write access, or a repository
# writer explicitly approves an external PR with ok-to-test. Product code is
# checked out at the exact PR head SHA, while coverage helpers come from the
# trusted commit that supplied this workflow.
on:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened, closed, labeled]
paths:
- "ydb/public/sdk/cpp/**"
- "ydb/apps/ydb/**"
- "ydb/public/lib/ydb_cli/**"
- "ydb/tests/functional/ydb_cli/**"
- "ydb/library/workload/**"
- ".github/actions/run_clang_codecov/**"
- ".github/actions/setup_ci_ydb_service_account_key_file_credentials/**"
- ".github/scripts/codecov/**"
- "!.github/scripts/codecov/tests/**"
- ".github/workflows/cpp_codecov.yml"
- ".github/codecov.yml"
push:
branches: [main]
paths:
- "ydb/public/sdk/cpp/**"
- "ydb/apps/ydb/**"
- "ydb/public/lib/ydb_cli/**"
- "ydb/tests/functional/ydb_cli/**"
- "ydb/library/workload/**"
- ".github/actions/run_clang_codecov/**"
- ".github/actions/setup_ci_ydb_service_account_key_file_credentials/**"
- ".github/scripts/codecov/**"
- "!.github/scripts/codecov/tests/**"
- ".github/workflows/cpp_codecov.yml"
- ".github/codecov.yml"
# GitHub cannot filter label names in `on`. Irrelevant labels therefore get a
# unique workflow group and skip every job. ok-to-test shares the PR group but
# label events cannot cancel a running workflow before the sender is verified.
# A later synchronize/closed event can still invalidate the approved PR SHA.
# Main runs are serialized as complete three-suite baselines. A newer pending
# main run supersedes an older pending run, but never cancels the one in progress.
concurrency:
group: >-
${{
github.event_name == 'pull_request_target'
&& format('{0}-pr-{1}{2}', github.workflow, github.event.pull_request.number,
github.event.action == 'labeled' && github.event.label.name != 'ok-to-test'
&& format('-ignore-{0}', github.run_id) || '')
|| format('{0}-main', github.workflow)
}}
cancel-in-progress: >-
${{ github.event_name == 'pull_request_target' && github.event.action != 'labeled' }}
permissions:
actions: read
contents: read
pull-requests: read
jobs:
detect:
name: Detect suites
if: >-
github.repository == 'ydb-platform/ydb' &&
(github.event_name != 'pull_request_target' ||
(github.event.pull_request.state == 'open' &&
github.base_ref == 'main' &&
(github.event.action != 'labeled' || github.event.label.name == 'ok-to-test')))
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.decide.outputs.matrix || '[]' }}
should_run: ${{ steps.decide.outputs.should_run || 'false' }}
checkout_repository: ${{ steps.metadata.outputs.checkout_repository }}
checkout_sha: ${{ steps.metadata.outputs.checkout_sha }}
base_sha: ${{ steps.metadata.outputs.base_sha }}
report_sha: ${{ steps.metadata.outputs.report_sha }}
report_branch: ${{ steps.metadata.outputs.report_branch }}
pr_number: ${{ steps.metadata.outputs.pr_number }}
storage_prefix: ${{ steps.metadata.outputs.storage_prefix }}
steps:
- name: Authorize PR coverage
id: authorization
if: github.event_name == 'pull_request_target'
uses: actions/github-script@v8
with:
# The restricted workflow GITHUB_TOKEN returned false 404 responses
# for this endpoint. This PAT is used only by the trusted gate.
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
script: |
const getPermission = async (username) => {
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username,
});
return data.permission;
} catch (error) {
if (!error.status || error.status !== 404) throw error;
return 'none';
}
};
const isWriter = (permission) => ['admin', 'write'].includes(permission);
if (context.payload.action === 'labeled') {
if (context.payload.label?.name !== 'ok-to-test') {
core.setOutput('allowed', 'false');
return;
}
const sender = context.payload.sender.login;
const permission = await getPermission(sender);
if (!isWriter(permission)) {
core.warning(
`Ignoring ok-to-test from @${sender}: write permission is required (${permission}).`
);
core.setOutput('allowed', 'false');
return;
}
core.info(`PR coverage approved by @${sender}.`);
core.setOutput('allowed', 'true');
return;
}
const users = [...new Set([
context.payload.pull_request.user.login,
context.payload.sender.login,
])];
for (const username of users) {
const permission = await getPermission(username);
if (!isWriter(permission)) {
core.notice(
`C++ coverage is waiting for a repository writer to apply ok-to-test ` +
`(@${username}: ${permission}).`
);
core.setOutput('allowed', 'false');
return;
}
}
core.setOutput('allowed', 'true');
- name: Pin PR head
id: pr
if: >-
github.event_name == 'pull_request_target' &&
steps.authorization.outputs.allowed == 'true'
uses: actions/github-script@v8
with:
script: |
const eventPr = context.payload.pull_request;
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: eventPr.number,
});
if (pr.state !== 'open' || pr.base.repo.full_name !== context.repo.owner + '/' + context.repo.repo || pr.base.ref !== 'main') {
core.setFailed('Coverage runs only for open pull requests targeting ydb-platform/ydb:main.');
return;
}
if (pr.head.sha !== eventPr.head.sha) {
core.setFailed('The PR head changed after this workflow started. Please use the latest run.');
return;
}
if (!pr.head.repo) {
core.setFailed('The PR head repository is unavailable.');
return;
}
const branch = pr.head.repo.full_name === pr.base.repo.full_name
? pr.head.ref
: pr.head.label;
core.setOutput('repository', pr.head.repo.full_name);
core.setOutput('sha', pr.head.sha);
core.setOutput('base_sha', eventPr.base.sha);
core.setOutput('branch', branch);
- name: Checkout trusted detection helpers from workflow source
if: >-
github.event_name != 'pull_request_target' ||
steps.authorization.outputs.allowed == 'true'
uses: actions/checkout@v5
with:
repository: ${{ github.repository }}
# A long-lived PR may have a base SHA older than this workflow and its
# helpers. workflow_sha is the trusted commit that supplied this YAML.
ref: ${{ github.workflow_sha }}
# PR detection needs merge-base history; main only needs the helpers.
fetch-depth: ${{ github.event_name == 'pull_request_target' && '0' || '1' }}
sparse-checkout: |
.github/scripts/codecov/codecov_suites.py
.github/scripts/codecov/detect_codecov_matrix.py
.github/scripts/codecov/check_patch_coverage.py
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Collect changed files
id: inputs
if: >-
github.event_name == 'pull_request_target' &&
steps.authorization.outputs.allowed == 'true'
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_SHA: ${{ steps.pr.outputs.sha }}
PR_BASE_SHA: ${{ steps.pr.outputs.base_sha }}
run: |
set -euo pipefail
changed_file=$(mktemp)
local_head_ref="refs/remotes/origin/codecov-pr-${PR_NUMBER}-head"
git fetch --no-tags --no-recurse-submodules origin \
"+refs/pull/${PR_NUMBER}/head:${local_head_ref}"
fetched_head=$(git rev-parse --verify "${local_head_ref}^{commit}")
if [ "$fetched_head" != "$PR_HEAD_SHA" ]; then
echo "The PR head changed while collecting files. Please use the latest run." >&2
exit 1
fi
git -c core.quotePath=false diff --name-only --no-renames \
"$PR_BASE_SHA...$PR_HEAD_SHA" -- \
> "$changed_file"
echo "changed_files_file=$changed_file" >> "$GITHUB_OUTPUT"
echo "Changed files:"
head -100 "$changed_file"
# Preserve the real PR diff, not Codecov's adjusted project baseline.
# Only line ranges and pinned SHAs are transferred, never PR code.
python3 .github/scripts/codecov/check_patch_coverage.py collect \
--base-sha "$PR_BASE_SHA" --head-sha "$PR_HEAD_SHA" \
--output "$RUNNER_TEMP/codecov-patch.json"
- name: Decide matrix
id: decide
if: >-
github.event_name != 'pull_request_target' ||
steps.authorization.outputs.allowed == 'true'
env:
EVENT_NAME: ${{ github.event_name }}
CHANGED_FILES_FILE: ${{ steps.inputs.outputs.changed_files_file }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = push ]; then
# Every relevant main push creates a self-contained baseline.
python3 .github/scripts/codecov/detect_codecov_matrix.py --all
else
python3 .github/scripts/codecov/detect_codecov_matrix.py \
--changed-files-file "$CHANGED_FILES_FILE"
fi
- name: Resolve checkout and report metadata
id: metadata
if: >-
github.event_name != 'pull_request_target' ||
steps.authorization.outputs.allowed == 'true'
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_SHA: ${{ github.sha }}
REF_NAME: ${{ github.ref_name }}
REPOSITORY: ${{ github.repository }}
PR_REPOSITORY: ${{ steps.pr.outputs.repository }}
PR_SHA: ${{ steps.pr.outputs.sha }}
PR_BASE_SHA: ${{ steps.pr.outputs.base_sha }}
PR_BRANCH: ${{ steps.pr.outputs.branch }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = pull_request_target ]; then
checkout_repository="$PR_REPOSITORY"
checkout_sha="$PR_SHA"
base_sha="$PR_BASE_SHA"
report_branch="$PR_BRANCH"
pr_number="$PR_NUMBER"
storage_prefix="ydb/pr-${PR_NUMBER}/coverage"
else
checkout_repository="$REPOSITORY"
checkout_sha="$EVENT_SHA"
base_sha=""
report_branch="$REF_NAME"
pr_number=""
storage_prefix="ydb/coverage"
fi
{
echo "checkout_repository=$checkout_repository"
echo "checkout_sha=$checkout_sha"
echo "base_sha=$base_sha"
echo "report_sha=$checkout_sha"
echo "report_branch=$report_branch"
echo "pr_number=$pr_number"
echo "storage_prefix=$storage_prefix"
} >> "$GITHUB_OUTPUT"
- name: Save pinned PR patch
if: >-
github.event_name == 'pull_request_target' &&
steps.decide.outputs.should_run == 'true'
uses: actions/upload-artifact@v4
with:
# A failed-jobs-only rerun can reuse detect from an earlier attempt.
name: codecov-patch-${{ github.run_id }}
path: ${{ runner.temp }}/codecov-patch.json
if-no-files-found: error
retention-days: 7
overwrite: true
coverage:
name: Coverage (${{ matrix.suite }})
needs: detect
if: >-
needs.detect.result == 'success' &&
needs.detect.outputs.should_run == 'true'
runs-on: [self-hosted, auto-provisioned, build-preset-relwithdebinfo]
timeout-minutes: 480
strategy:
fail-fast: false
matrix:
suite: ${{ fromJson(needs.detect.outputs.matrix) }}
steps:
- name: Checkout measured code
uses: actions/checkout@v5
with:
repository: ${{ needs.detect.outputs.checkout_repository }}
ref: ${{ needs.detect.outputs.checkout_sha }}
# Build/upload needs only the pinned tree; merge-base history is used
# separately in detect. Avoid fetching every branch and tag per suite.
fetch-depth: 1
allow-unsafe-pr-checkout: true
persist-credentials: false
- name: Checkout trusted coverage helpers from workflow source
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v5
with:
ref: ${{ github.workflow_sha }}
sparse-checkout: |
.github/actions/run_clang_codecov
.github/actions/setup_ci_ydb_service_account_key_file_credentials
.github/config
.github/scripts/codecov
path: _trusted_coverage_ci
persist-credentials: false
- name: Overlay trusted coverage helpers
if: github.event_name == 'pull_request_target'
run: bash _trusted_coverage_ci/.github/scripts/codecov/overlay_trusted_codecov_ci.sh
- name: Setup YDB access
uses: ./.github/actions/setup_ci_ydb_service_account_key_file_credentials
with:
ci_ydb_service_account_key_file_credentials: ${{ secrets.CI_YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS }}
ydb_qa_config: ${{ vars.YDB_QA_CONFIG }}
- name: Run suite
uses: ./.github/actions/run_clang_codecov
with:
suite: ${{ matrix.suite }}
muted_tests_file: ${{ github.event_name == 'pull_request_target' && '_trusted_coverage_ci/.github/config/muted_ya.txt' || '.github/config/muted_ya.txt' }}
codecov_token: ${{ secrets.CODECOV_TOKEN }}
github_token: ${{ github.token }}
aws_access_key_id: ${{ secrets.YDB_TECH_AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.YDB_TECH_AWS_SECRET_ACCESS_KEY }}
bazel_remote_uri: ${{ vars.REMOTE_CACHE_URL_YA }}
bazel_remote_username: ${{ secrets.REMOTE_CACHE_USERNAME }}
bazel_remote_password: ${{ secrets.REMOTE_CACHE_PASSWORD }}
pr_number: ${{ needs.detect.outputs.pr_number }}
commit_sha: ${{ needs.detect.outputs.report_sha }}
branch: ${{ needs.detect.outputs.report_branch }}
storage_prefix: ${{ needs.detect.outputs.storage_prefix }}
- name: Remove YDB credentials
if: always()
run: rm -f -- /tmp/ydb_service_account.json
patch:
name: Check if patch coverage is sufficient
needs: [detect, coverage]
if: >-
github.event_name == 'pull_request_target' &&
needs.detect.result == 'success' &&
needs.detect.outputs.should_run == 'true' &&
needs.coverage.result == 'success'
# Deliberately non-required: this workflow does not change merge rules or
# checks_integrated. The upload/HTML jobs remain successful below the target.
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout trusted patch checker
uses: actions/checkout@v5
with:
repository: ${{ github.repository }}
ref: ${{ github.workflow_sha }}
sparse-checkout: |
.github/scripts/codecov
.github/codecov.yml
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Download pinned PR patch
uses: actions/download-artifact@v4
with:
name: codecov-patch-${{ github.run_id }}
path: ${{ runner.temp }}/codecov-patch
- name: Download Codecov uploads and receipts
uses: actions/download-artifact@v4
with:
pattern: codecov-upload-*-${{ github.run_id }}
path: ${{ runner.temp }}/codecov-uploads
merge-multiple: true
- name: Check every affected component
env:
MATRIX: ${{ needs.detect.outputs.matrix }}
PR_BASE_SHA: ${{ needs.detect.outputs.base_sha }}
PR_HEAD_SHA: ${{ needs.detect.outputs.report_sha }}
run: |
set -euo pipefail
# Read the same policy as Codecov from this workflow's trusted tree.
# Ruby/Psych is already available on this GitHub-hosted runner.
ruby -rjson -ryaml -e \
'puts JSON.generate(YAML.safe_load(File.read(ARGV.fetch(0)), aliases: true))' \
.github/codecov.yml > "$RUNNER_TEMP/codecov-policy.json"
# The trusted LCOV and PR diff are sufficient for the verdict.
# Never wait for Codecov processing, notification statuses or main.
mapfile -t suites < <(python3 -c 'import json,os; print("\n".join(json.loads(os.environ["MATRIX"])))')
if [ "${#suites[@]}" -eq 0 ]; then
echo "Expected at least one coverage component" >&2
exit 1
fi
failed=0
for suite in "${suites[@]}"; do
case "$suite" in
cpp_sdk|cli|cli_workload) ;;
*) echo "Unexpected coverage component: $suite" >&2; exit 1 ;;
esac
if ! python3 .github/scripts/codecov/check_patch_coverage.py check \
--base-sha "$PR_BASE_SHA" --head-sha "$PR_HEAD_SHA" \
--flag "$suite" --run-id "$GITHUB_RUN_ID" \
--upload-receipt "$RUNNER_TEMP/codecov-uploads/codecov-upload-${suite}.json" \
--coverage-report "$RUNNER_TEMP/codecov-uploads/codecov-upload-${suite}.lcov" \
--changed-lines-file "$RUNNER_TEMP/codecov-patch/codecov-patch.json" \
--policy-file "$RUNNER_TEMP/codecov-policy.json"; then
failed=1
fi
done
exit "$failed"
- name: Explain main baseline availability
# Project comparisons are informational context, not a prerequisite for
# measuring HEAD or applying the local patch threshold. Run even below target.
if: ${{ !cancelled() }}
continue-on-error: true
timeout-minutes: 1
uses: actions/github-script@v8
env:
PR_BASE_SHA: ${{ needs.detect.outputs.base_sha }}
with:
github-token: ${{ github.token }}
script: |
const baseSha = process.env.PR_BASE_SHA;
let run;
let message;
try {
const { data } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'cpp_codecov.yml',
branch: 'main',
event: 'push',
head_sha: baseSha,
per_page: 100,
request: { timeout: 10000 },
});
const runs = data.workflow_runs.filter((item) =>
item.head_sha === baseSha &&
item.head_branch === 'main' &&
item.event === 'push'
);
run = runs.find((item) =>
item.status === 'completed' && item.conclusion === 'success'
) || runs[0];
if (!run) {
message = 'No main coverage run is recorded for this PR base.';
} else if (run.status !== 'completed') {
message = 'Main coverage for this PR base is still pending or running.';
} else if (run.conclusion !== 'success') {
message = 'Main coverage for this PR base did not complete successfully.';
} else {
message = 'The main coverage run for this PR base completed successfully.';
}
} catch (error) {
message = 'Main coverage availability could not be checked.';
}
core.info(message + ' Local patch coverage does not depend on it.');
core.summary
.addHeading('Main baseline (informational)', 3)
.addRaw(message + '\n\n')
.addRaw('The local patch verdict uses the configured policy, this PR diff and its exact LCOV. ' +
'No wait, retry or rebuild of the PR is needed for a main baseline. ' +
"Codecov's own project comparison and its choice of base are separate; " +
'availability here is not a guarantee of a processed Codecov baseline.\n\n');
if (run && Number.isSafeInteger(run.id) && run.id > 0) {
core.summary.addLink('Main coverage run',
`${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${run.id}`);
}
await core.summary.write();
landing:
name: Publish HTML landing page
needs: [detect, coverage]
if: >-
always() &&
needs.detect.result == 'success' &&
needs.detect.outputs.should_run == 'true' &&
needs.coverage.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout landing generator
uses: actions/checkout@v5
with:
repository: ${{ github.repository }}
ref: ${{ github.workflow_sha }}
sparse-checkout: .github/scripts/codecov/generate_coverage_landing.py
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Generate landing page
env:
MATRIX: ${{ needs.detect.outputs.matrix }}
run: |
set -euo pipefail
mkdir -p coverage_landing
mapfile -t suites < <(python3 -c 'import json,os; print("\n".join(json.loads(os.environ["MATRIX"])))')
args=()
for suite in "${suites[@]}"; do
case "$suite" in
cpp_sdk|cli|cli_workload)
args+=(--suite "${suite}=./${suite}/index.html")
;;
*)
echo "Unexpected suite: $suite" >&2
exit 1
;;
esac
done
python3 .github/scripts/codecov/generate_coverage_landing.py \
--output coverage_landing/index.html \
--title "YDB C++ coverage" \
"${args[@]}"
- name: Check Object Storage credentials
id: storage
env:
AWS_ACCESS_KEY_ID: ${{ secrets.YDB_TECH_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.YDB_TECH_AWS_SECRET_ACCESS_KEY }}
run: |
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi
- name: Install AWS CLI
if: steps.storage.outputs.enabled == 'true'
continue-on-error: true
run: |
set -euo pipefail
pip3 install --user 'awscli==1.46.0'
- name: Verify current PR head before landing publication
id: landing_pr_head
if: >-
needs.detect.outputs.pr_number != '' &&
steps.storage.outputs.enabled == 'true'
uses: actions/github-script@v8
env:
EXPECTED_SHA: ${{ needs.detect.outputs.report_sha }}
PR_NUMBER: ${{ needs.detect.outputs.pr_number }}
with:
github-token: ${{ github.token }}
script: |
const expectedSha = process.env.EXPECTED_SHA;
const pullNumber = Number(process.env.PR_NUMBER);
if (!/^[0-9a-f]{40}$/i.test(expectedSha)) {
core.setFailed('Expected PR head must be a 40-character hexadecimal SHA.');
return;
}
if (!Number.isSafeInteger(pullNumber) || pullNumber <= 0) {
core.setFailed('PR number must be a positive integer.');
return;
}
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullNumber,
});
if (pr.state !== 'open' || pr.head.sha !== expectedSha) {
core.setFailed(
`Refusing to publish a stale coverage landing page: expected open PR head ` +
`${expectedSha}, current state=${pr.state}, head=${pr.head.sha}.`
);
}
- name: Upload landing page
if: >-
steps.storage.outputs.enabled == 'true' &&
(needs.detect.outputs.pr_number == '' ||
steps.landing_pr_head.outcome == 'success')
continue-on-error: true
env:
AWS_ACCESS_KEY_ID: ${{ secrets.YDB_TECH_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.YDB_TECH_AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ru-central1
STORAGE_PREFIX: ${{ needs.detect.outputs.storage_prefix }}
run: |
set -euo pipefail
export PATH="${HOME}/.local/bin:${PATH}"
if ! command -v aws >/dev/null 2>&1; then
echo "AWS CLI is unavailable; skip best-effort landing upload" >&2
exit 0
fi
aws --endpoint-url https://storage.yandexcloud.net s3 cp \
coverage_landing/index.html \
"s3://ydb-appteam-sdk-reports/${STORAGE_PREFIX}/index.html"