Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
367 lines (343 loc) · 13.7 KB
/
Copy pathaction.yml
File metadata and controls
367 lines (343 loc) · 13.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
name: 'Run CLT test'
description: 'This action runs a CLT test'
outputs:
timing-results:
description: 'Path to the current worker timing measurements.'
value: ${{ steps.collect-timings.outputs.path }}
test-results:
description: 'Path to JSON Lines with a result for each executed CLT test.'
value: ${{ steps.init-test-results.outputs.path }}
inputs:
image:
description: |-
Docker image on that we will use to run CLT tests
required: true
type: string
init_code:
description: |-
Code that is to be executed on init stage before running tests
required: false
type: string
default: ''
run_args:
description: |-
Run args that we will pass to each test we run
required: false
type: string
default: ''
test_prefix:
description: |-
Filter tests by using this prefix in tests folder.
You can specify multiple prefixes each on one line for groupping.
required: false
type: string
default: 'tests/'
tests:
description: |-
JSON array of exact CLT recording paths. Each path may include or omit the .rec suffix.
When set, this takes precedence over test_prefix and never expands a glob.
required: false
type: string
default: ''
timeout:
description: |-
Allowed timeout in minutes for tests
required: false
type: number
default: 5
artifact:
description: |-
Artifact to download in case you want to use local built docker image to run.
required: false
type: string
repository:
description: |-
Repository to checkout.
required: false
type: string
ref:
description: |-
The branch name or ref to the original repo we test that we will checkout.
Optional and by default we use default branch of it.
required: false
type: string
default: ''
comment_mode:
description: |-
If we are in a pull request, we publish summary results of tests to it as comments.
By default, it uses the 'always' mode that publishes a comment on any results.
You can set it to 'failures' to create a comment in the pull request only when an error occurred.
required: false
type: string
default: 'always'
ui_host:
description: |-
UI host domain for generating edit links for failed tests.
When provided, failed tests will include edit links pointing to the UI.
Example: 'https://clt-ui.example.com'
required: false
type: string
runs:
using: "composite"
steps:
- name: Checkout the calling repo
uses: actions/checkout@v5
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
- name: Checkout CLT
uses: actions/checkout@v5
# TODO: remove the env section once https://github.com/actions/runner/issues/2525 is solved. Using 'env' is just a workaround.
env:
GH_ACTION_REPOSITORY: ${{ github.action_repository }}
GH_ACTION_REF: ${{ github.action_ref }}
with:
repository: '${{ env.GH_ACTION_REPOSITORY }}'
ref: '${{ env.GH_ACTION_REF }}'
path: 'clt'
- name: Download artifact
if: ${{ inputs.artifact }}
uses: manticoresoftware/download_artifact_with_retries@v5
with:
name: ${{ inputs.artifact }}
path: .
- name: Initialize the testing Env
if: ${{ inputs.init_code }}
run: |
${{ inputs.init_code }}
shell: bash
- id: init-test-results
name: Initialize per-test results
shell: bash
run: |
results_path="$RUNNER_TEMP/clt-test-results.jsonl"
: > "$results_path"
echo "path=$results_path" >> "$GITHUB_OUTPUT"
- name: Run all tests
env:
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
CLT_EXACT_TESTS: ${{ inputs.tests }}
run: |
set +e
should_exit=0
test_success=0
test_failed=0
timings_tests="${RUNNER_TEMP}/clt-timing-tests"
last_started_test="${RUNNER_TEMP}/clt-last-started-test"
last_started_at="${RUNNER_TEMP}/clt-last-started-at-ms"
test_results="${RUNNER_TEMP}/clt-test-results.jsonl"
: > "$timings_tests"
rm -f "$last_started_test" "$last_started_at"
start_time=$(date +%s)
declare -A failed_tests
record_test_result() {
local test="$1" status="$2" exit_code="$3" duration_ms="$4"
jq -cn --arg test "$test" --arg status "$status" \
--argjson exit_code "$exit_code" --argjson duration_ms "$duration_ms" \
'{test: $test, status: $status, exit_code: $exit_code, duration_ms: $duration_ms}' >> "$test_results"
}
if [ -f "${{ inputs.artifact }}" ]; then
cat "${{ inputs.artifact }}" | docker import - "${{ inputs.image }}"
fi
run_test() {
local test="$1"
local started_ms
started_ms=$(date +%s%3N)
printf '%s\n' "$test" > "$last_started_test"
printf '%s\n' "$started_ms" > "$last_started_at"
echo "Running test: $test with command: CLT_RUN_ARGS=\"${{ inputs.run_args }}\" clt/clt test -t $test ${{ inputs.image }}"
echo "Run locally: clt test -d -t $test ${{ inputs.image }}"
CLT_RUN_ARGS="${{ inputs.run_args }}" clt/clt test -t "$test" "${{ inputs.image }}"
exit_code=$?
local finished_ms
finished_ms=$(date +%s%3N)
rep_file="${test%.rec}.rep"
cat "$rep_file"
if [ $exit_code -ne 0 ]; then
echo -n $'\n'$'\n'$'\n'
echo "🚨 Test failed with exit code: $exit_code"
echo "CLT-CMP diff output:"
cmp_file="${test%.rec}.cmp"
output="$(cat "$cmp_file")"
failed_tests[$test]="$output"
echo "$output"
should_exit=1
((test_failed++))
record_test_result "$test" "failed" "$exit_code" "$((finished_ms - started_ms))"
else
((test_success++))
record_test_result "$test" "passed" "0" "$((finished_ms - started_ms))"
printf '%s\n' "$test" >> "$timings_tests"
fi
rm -f "$last_started_test" "$last_started_at"
echo "–––"
}
if [[ -n "$CLT_EXACT_TESTS" ]]; then
if ! jq -e 'type == "array" and all(.[]; type == "string")' <<< "$CLT_EXACT_TESTS" >/dev/null; then
echo 'tests must be a JSON array of strings' >&2
exit 2
fi
while IFS= read -r requested_test; do
[[ -n "$requested_test" ]] || continue
test="${requested_test%.rec}.rec"
if [[ ! -f "$test" ]]; then
echo "Requested exact test does not exist: $test" >&2
should_exit=1
((test_failed++))
record_test_result "$test" "missing" "null" "0"
continue
fi
run_test "$test"
done < <(jq -r '.[]' <<< "$CLT_EXACT_TESTS")
else
while read -r prefix; do
for test in ${prefix}*.rec; do
run_test "$test"
done
done <<< "$(sed 's/^[[:space:]]*//;s/[[:space:]]*$//' <<< "${{ inputs.test_prefix }}")"
fi
end_time=$(date +%s)
test_duration=$((end_time - start_time))
# URL encoding function for bash
url_encode() {
local string="${1}"
local strlen=${#string}
local encoded=""
local pos c o
for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}"
}
# Determine branch name to pass to UI (use GitHub context, avoid SHAs)
is_sha() { [[ "$1" =~ ^[0-9a-fA-F]{7,40}$ ]]; }
current_branch=""
if [ -n "${{ inputs.ref }}" ] && ! is_sha "${{ inputs.ref }}" ; then
current_branch="${{ inputs.ref }}"
elif [ "${{ github.event_name }}" = "pull_request" ] || [ "${{ github.event_name }}" = "pull_request_review" ] || [ "${{ github.event_name }}" = "pull_request_target" ]; then
current_branch="${{ github.event.pull_request.head.ref }}"
if [ -z "$current_branch" ]; then current_branch="${{ github.head_ref }}"; fi
else
current_branch="${{ github.ref_name }}"
fi
if [ -z "$current_branch" ]; then current_branch="master"; fi
# Debug output for branch detection
echo "Detected branch: $current_branch (event: ${{ github.event_name }})"
# URL encode docker image for passing to UI
encoded_docker_image=$(url_encode "${{ inputs.image }}")
# Build failed tests array for URL parameters
failed_tests_params=""
if [ ${#failed_tests[@]} -ne 0 ] && [ -n "${{ inputs.ui_host }}" ]; then
for key in "${!failed_tests[@]}"; do
encoded_test=$(url_encode "$key")
if [ -z "$failed_tests_params" ]; then
failed_tests_params="failed_tests[]=$encoded_test"
else
failed_tests_params="$failed_tests_params&failed_tests[]=$encoded_test"
fi
done
fi
# Write summary
if [ "$test_failed" -gt "0" ]; then
test_emoji="❌"
else
# We stop processing if all tests passed
exit 0
fi
job_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
commit_url="${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}"
commit_sha="$(echo "${{ github.sha }}" | cut -c1-7 )"
test_scope="${{ inputs.test_prefix }}"
[[ -n "$CLT_EXACT_TESTS" ]] && test_scope="exact test selection"
echo "## ${{ github.job }}" >> $GITHUB_STEP_SUMMARY
echo "${test_emoji} CLT tests in \`$test_scope\`" >> $GITHUB_STEP_SUMMARY
echo "✅ OK: $test_success" >> $GITHUB_STEP_SUMMARY
echo "❌ Failed: $test_failed" >> $GITHUB_STEP_SUMMARY
echo "⏳ Duration: ${test_duration}s" >> $GITHUB_STEP_SUMMARY
echo "👉 [Check Action Results]($job_url) for commit [$commit_sha]($commit_url)" >> $GITHUB_STEP_SUMMARY
if [ ${#failed_tests[@]} -ne 0 ]; then
echo "### Failed tests:" >> $GITHUB_STEP_SUMMARY
# Edit links placed right under the header for proper rendering (outside details)
if [ -n "${{ inputs.ui_host }}" ]; then
echo >> $GITHUB_STEP_SUMMARY
echo "🔧 Edit failed tests in UI:" >> $GITHUB_STEP_SUMMARY
for key in "${!failed_tests[@]}"; do
encoded_test_path=$(url_encode "$key")
encoded_branch=$(url_encode "$current_branch")
edit_url="${{ inputs.ui_host }}/?test_path=$encoded_test_path&branch=$encoded_branch&docker_image=$encoded_docker_image&$failed_tests_params"
echo "- [Edit $key]($edit_url)" >> $GITHUB_STEP_SUMMARY
done
echo >> $GITHUB_STEP_SUMMARY
fi
for key in "${!failed_tests[@]}"; do
value="${failed_tests[$key]}"
echo '<details>' >> $GITHUB_STEP_SUMMARY
echo "<summary>$key</summary>" >> $GITHUB_STEP_SUMMARY
echo >> $GITHUB_STEP_SUMMARY
echo '```diff' >> $GITHUB_STEP_SUMMARY
echo "$value" | sed 's/\x1b\[[0-9;]*m//g' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo >> $GITHUB_STEP_SUMMARY
echo '</details>' >> $GITHUB_STEP_SUMMARY
done
fi
should_comment="$should_exit"
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
if [ "${{ inputs.comment_mode }}" == 'always' ]; then
should_comment=1
elif [ "${{ inputs.comment_mode }}" == 'failures' ]; then
should_comment="$should_exit"
else
should_comment=0
fi
else
should_comment=0
fi
if [[ "$should_comment" == "1" ]]; then
gh pr comment $PR_NUMBER --body "$(cat $GITHUB_STEP_SUMMARY)" -R ${{ github.repository }}
fi
# If we have some test failed, we exit
if [[ "$should_exit" == "1" ]]; then
exit 1
fi
shell: bash
- name: Report interrupted CLT test
if: ${{ always() }}
shell: bash
env:
CLT_LAST_STARTED_TEST: ${{ runner.temp }}/clt-last-started-test
CLT_LAST_STARTED_AT: ${{ runner.temp }}/clt-last-started-at-ms
CLT_RESULTS_PATH: ${{ runner.temp }}/clt-test-results.jsonl
run: |
[[ -f "$CLT_LAST_STARTED_TEST" ]] || exit 0
test="$(<"$CLT_LAST_STARTED_TEST")"
started_ms=$(cat "$CLT_LAST_STARTED_AT" 2>/dev/null || date +%s%3N)
finished_ms=$(date +%s%3N)
if [[ -f "$CLT_RESULTS_PATH" ]]; then
jq -cn --arg test "$test" --arg status "interrupted" \
--argjson exit_code null --argjson duration_ms "$((finished_ms - started_ms))" \
'{test: $test, status: $status, exit_code: $exit_code, duration_ms: $duration_ms}' >> "$CLT_RESULTS_PATH"
fi
rep_file="${test%.rec}.rep"
echo "Last started CLT test: $test"
if [[ -f "$rep_file" ]]; then
cat "$rep_file"
else
echo "No replay file found: $rep_file"
fi
- id: collect-timings
name: Collect timing measurements
if: ${{ always() }}
shell: bash
env:
CLT_TIMINGS_TESTS: ${{ runner.temp }}/clt-timing-tests
CLT_TIMINGS_RESULTS_PATH: ${{ runner.temp }}/clt-timings/results.tsv
run: |
bash clt/scripts/update-timings.sh
echo "path=$CLT_TIMINGS_RESULTS_PATH" >> "$GITHUB_OUTPUT"