-
Notifications
You must be signed in to change notification settings - Fork 4
784 lines (678 loc) · 36.4 KB
/
newman.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
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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
on:
workflow_call:
inputs:
collection_path:
required: true
type: string
image_name:
required: true
type: string
os:
required: true
type: string
container_name:
required: true
type: string
centreon_url:
required: true
type: string
centreon_image:
required: true
type: string
database_image:
required: true
type: string
dependencies_lock_file:
required: true
type: string
major_version:
required: true
type: string
stability:
required: true
type: string
xray_keys_and_ids:
description: "The test execution and the test plan keys and ids"
required: true
type: string
secrets:
registry_username:
required: true
registry_password:
required: true
client_id:
required: true
client_secret:
required: true
jira_user:
required: true
jira_token_test:
required: true
jobs:
newman-test-list:
runs-on: ubuntu-22.04
outputs:
collections: ${{ steps.set_collections.outputs.collections }}
steps:
- name: Checkout Repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: List Postman Collections and Environments
id: set_collections
run: |
collection_path="${{ inputs.collection_path }}"
collections=$(find "$collection_path" -type f -name "*.postman_collection.json" -printf "%P\n" | sort | jq -R -s -c 'split("\n")[:-1]')
echo "collections=$collections" >> $GITHUB_OUTPUT
echo "GITHUB_OUTPUT contents:"
cat $GITHUB_OUTPUT
associate-test-cases:
runs-on: ubuntu-22.04
if: ${{ inputs.os == 'alma9' && contains(fromJson('["testing", "unstable"]'), inputs.stability) && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.is_nightly == 'true')) }}
outputs:
test_execution_id: ${{ steps.get-test-ids.outputs.test_execution_id }}
test_plan_id: ${{ steps.get-test-ids.outputs.test_plan_id }}
issue_list_ids: ${{ steps.xray-newman.outputs.issue_list_ids }}
api-issue-ids: ${{ steps.xray-newman.outputs.api-issue-ids }}
defaults:
run:
shell: bash
working-directory: centreon/tests/rest_api
steps:
- name: Checkout Repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Test Execution and test plan Keys
id: get-test-ids
run: |
test_execution_id=$(echo '${{ inputs.xray_keys_and_ids }}' | jq -r '.test_execution_id_'${{ inputs.os }})
test_plan_id=$(echo '${{ inputs.xray_keys_and_ids }}' | jq -r '.test_plan_id_'${{ inputs.os }})
echo "The Test Execution ID : $test_execution_id"
echo "The Test Plan ID : $test_plan_id"
echo "test_plan_id=$test_plan_id" >> $GITHUB_OUTPUT
echo "test_execution_id=$test_execution_id" >> $GITHUB_OUTPUT
shell: bash
- name: Generate Xray Token
id: generate-xray-token
run: |
token_response=$(curl -H "Content-Type: application/json" -X POST --data "{\"client_id\": \"${{ secrets.client_id }}\", \"client_secret\": \"${{ secrets.client_secret }}\"}" "https://xray.cloud.getxray.app/api/v1/authenticate")
xray_token=$(echo "$token_response" | sed -n 's/.*"\(.*\)".*/\1/p')
echo "xray_token=$xray_token" >> $GITHUB_OUTPUT
shell: bash
- name: Associate Test Cases with Test plan
id: xray-newman
run: |
get_test_ids() {
start=0
test_issue_ids=()
while true; do
xray_graphql_getTests='{
"query": "query getTests($jql: String, $limit: Int!, $start: Int) { getTests(jql: $jql, limit: $limit, start: $start) { total results { issueId } } }",
"variables": {
"jql": "reporter = \"712020:093f82f0-b0f1-4498-8369-fbe72fb50bcb\" AND project = MON AND type = \"Test\" AND testType = \"API\"",
"limit": 100,
"start": '$start'
}
}'
response=$(curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ steps.generate-xray-token.outputs.xray_token }}" \
--data "$xray_graphql_getTests" \
"https://xray.cloud.getxray.app/api/v2/graphql")
echo "Response from getTests:"
echo "$response"
# Parsing and processing test IDs
current_test_issue_ids=($(echo "$response" | jq -r '.data.getTests.results[].issueId'))
echo "Current Test Issue IDs: ${current_test_issue_ids[*]}"
# Check if there are no more test issues
if [ ${#current_test_issue_ids[@]} -eq 0 ]; then
echo "No more test issues. Exiting loop."
break
fi
# Concatenate the current batch of results to the overall test_issue_ids array
test_issue_ids+=("${current_test_issue_ids[@]}")
# Increment the start value for the next iteration
start=$((start + 100))
done
# Display all retrieved test issue IDs
echo "All Test Issue IDs: ${test_issue_ids[*]}"
}
get_test_ids
formatted_getTest_issue_ids_str="["
for issue_id in "${test_issue_ids[@]}"; do
formatted_getTest_issue_ids_str+="\"$issue_id\","
done
formatted_getTest_issue_ids_str="${formatted_getTest_issue_ids_str%,}"
formatted_getTest_issue_ids_str+="]"
echo "$formatted_getTest_issue_ids_str"
# Display the retrieved test issue IDs
echo "Test Issue IDs: ${test_issue_ids[*]}"
# Mutation to add tests to the test plan
xray_graphql_addTestsToTestPlan='{
"query": "mutation AddTestsToTestPlan($issueId: String!, $testIssueIds: [String]!) { addTestsToTestPlan(issueId: $issueId, testIssueIds: $testIssueIds) { addedTests warning } }",
"variables": {
"issueId": "'${{ steps.get-test-ids.outputs.test_plan_id }}'",
"testIssueIds": '"$formatted_getTest_issue_ids_str"'
}
}'
# Execute the mutation to add tests to the test plan
response_addTestsToTestPlan=$(curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ steps.generate-xray-token.outputs.xray_token }}" \
--data "$xray_graphql_addTestsToTestPlan" \
"https://xray.cloud.getxray.app/api/v2/graphql")
echo "Response from Add Tests to Test Plan:"
echo "$response_addTestsToTestPlan"
get_test_plan_issue_ids() {
start=0
issue=()
api_issue_ids=()
while true; do
xray_graphql_getTestPlan='{
"query": "query GetTestPlan($issueId: String, $start: Int) { getTestPlan(issueId: $issueId) { issueId tests(limit: 100, start: $start) { results { issueId testType { name } } } } }",
"variables": {
"issueId": "'${{ steps.get-test-ids.outputs.test_plan_id }}'",
"start": '$start'
}
}'
response=$(curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${{ steps.generate-xray-token.outputs.xray_token }}" --data "${xray_graphql_getTestPlan}" "https://xray.cloud.getxray.app/api/v2/graphql")
echo "Response from Get Test Plan:"
echo "$response"
# Parsing and processing test IDs
current_issue_ids=($(echo "$response" | jq -r '.data.getTestPlan.tests.results[] | .issueId'))
echo "Current Issue IDs: ${current_issue_ids[*]}"
# Concatenate the current batch of results to the overall issue_ids array
issue=("${issue[@]}" "${current_issue_ids[@]}")
# Parsing and processing test IDs for API tests and adding them to api_issue_ids
current_api_issue_ids=($(echo "$response" | jq -r '.data.getTestPlan.tests.results[] | select(.testType.name == "API") | .issueId'))
api_issue_ids=("${api_issue_ids[@]}" "${current_api_issue_ids[@]}")
# Increment the start value for the next iteration
start=$((start + 100))
# Check if there are more results
if [ -z "$response" ] || [ ${#current_issue_ids[@]} -eq 0 ]; then
echo "No more results. Exiting loop."
break
fi
done
# Display results
echo "API Issue IDs: ${api_issue_ids[*]}"
echo "api-issue-ids=${api_issue_ids[*]}" >> $GITHUB_OUTPUT
}
get_test_plan_issue_ids
issue_ids=("${api_issue_ids[@]}")
summaries=()
for issue_id in "${issue_ids[@]}"; do
echo "Processing issue ID: $issue_id"
jira_issue_url="https://centreon.atlassian.net/rest/api/2/issue/$issue_id"
response=$(curl --request GET \
--url "$jira_issue_url" \
--user "${{ secrets.jira_user }}:${{ secrets.jira_token_test }}" \
--header 'Accept: application/json')
summary=$(echo "$response" | jq -r '.fields.summary')
if [ "$response_code" -eq 404 ]; then
echo "The issue with ID $issue_id does not exist or you do not have permission to see it."
break
else
echo "The issue with ID $issue_id exists."
summaries+=("$summary")
fi
done
collections=($(find ./collections -type f -name "*.postman_collection.json"))
test_case_ids=()
xray_graphql_AddingTestsToTestPlan='{
"query": "mutation AddTestsToTestPlan($issueId: String!, $testIssueIds: [String]!) { addTestsToTestPlan(issueId: $issueId, testIssueIds: $testIssueIds) { addedTests warning } }",
"variables": {
"issueId":"${{ steps.get-test-ids.outputs.test_plan_id }}",
"testIssueIds": []
}
}'
existing_test_case_ids=("${issue_ids[@]}")
for collection_file in "${collections[@]}"; do
collection_name=$(basename "$collection_file" .postman_collection.json)
collection_name_sanitized="${collection_name//[^a-zA-Z0-9]/_}"
if [[ " ${summaries[*]} " =~ " ${collection_name_sanitized} " ]]; then
echo "The test case for $collection_name_sanitized already exists in the test plan."
else
# Adding a new test case
response=$(curl --request POST \
--url 'https://centreon.atlassian.net/rest/api/2/issue' \
--user '${{ secrets.jira_user }}:${{ secrets.jira_token_test }}' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"fields": {
"project": {
"key": "MON"
},
"summary": "'"$collection_name_sanitized"'",
"components": [{"name": "centreon-web"}],
"priority":{"name":"Low"},
"description": "Test case for '"$collection_name_sanitized"'",
"issuetype": {
"name": "Test"
}
}
}' \
--max-time 20)
if [ -z "$response" ]; then
echo "Failed to create the test case within the specified time."
else
test_case_id=$(echo "$response" | jq -r '.id')
# Checking if the test case is a new one
if [[ ! " ${existing_test_case_ids[*]} " =~ " ${test_case_id} " ]]; then
echo "New Test Case with ID: $test_case_id"
summaries+=("$collection_name_sanitized")
# Update GraphQL query to add this test to the test plan
xray_graphql_AddingTestsToTestPlan_variables=$(echo "$xray_graphql_AddingTestsToTestPlan" | jq --arg test_case_id "$test_case_id" '.variables.testIssueIds += [$test_case_id]')
# Execute the GraphQL mutation to update the testType only for new test cases
testType_mutation_response=$(curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${{ steps.generate-xray-token.outputs.xray_token }}" --data '{"query": "mutation { updateTestType(issueId: \"'$test_case_id'\", testType: {name: \"API\"} ) { issueId testType { name kind } } }"}' "https://xray.cloud.getxray.app/api/v2/graphql")
# Checking if the mutation was successful
if [ "$(echo "$testType_mutation_response" | jq -r '.data.updateTestType')" != "null" ]; then
echo "Successfully updated testType to API for Test Case with ID: $test_case_id"
else
echo "Failed to update testType for Test Case with ID: $test_case_id"
fi
# Execute the GraphQL mutation to add tests to the test plan
response=$(curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${{ steps.generate-xray-token.outputs.xray_token}}" --data "$xray_graphql_AddingTestsToTestPlan_variables" "https://xray.cloud.getxray.app/api/v2/graphql")
else
echo "Test Case with ID $test_case_id already exists in the test plan."
fi
fi
fi
done
get_test_plan_issue_ids
issue_list_ids=("${issue[@]}")
echo "issue_list_ids=("${issue[*]}")" >> $GITHUB_OUTPUT
test_issue_ids=("${issue_list_ids[@]}")
formatted_test_issue_ids_str="["
for issue_id in "${issue_list_ids[@]}"; do
formatted_test_issue_ids_str+="\"$issue_id\","
done
formatted_test_issue_ids_str="${formatted_test_issue_ids_str%,}"
formatted_test_issue_ids_str+="]"
echo "$formatted_test_issue_ids_str"
xray_graphql_addTestsToTestExecution='{
"query": "mutation AddTestsToTestExecution($issueId: String!, $testIssueIds: [String]) { addTestsToTestExecution(issueId: $issueId, testIssueIds: $testIssueIds) { addedTests warning } }",
"variables": {
"issueId": "${{ steps.get-test-ids.outputs.test_execution_id }}",
"testIssueIds": '$formatted_test_issue_ids_str'
}
}'
response_addTestsToTestExecution=$(curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${{ steps.generate-xray-token.outputs.xray_token }}" --data "${xray_graphql_addTestsToTestExecution}" "https://xray.cloud.getxray.app/api/v2/graphql")
echo "Response from Add Tests to Test Execution:"
echo "$response_addTestsToTestExecution"
newman-test-run:
needs: [newman-test-list, associate-test-cases]
if: ${{ !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
feature: ${{ fromJson(needs.newman-test-list.outputs.collections) }}
name: ${{ matrix.feature }}
defaults:
run:
shell: bash
working-directory: centreon/tests/rest_api
env:
IMAGE_TAG: ${{ github.head_ref || github.ref_name }}
SLIM_IMAGE_NAME: ${{ inputs.image_name }}-slim-${{ inputs.os }}
CONTAINER_NAME: ${{ inputs.container_name }}
CENTREON_URL: ${{ inputs.centreon_url }}
WEB_IMAGE: ${{ inputs.centreon_image }}
DATABASE_IMAGE: ${{ inputs.database_image }}
steps:
- name: Checkout Repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
version: 8
run_install: false
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version: 20
cache: pnpm
cache-dependency-path: ${{ inputs.dependencies_lock_file }}
- name: Install Dependencies for tests/rest_api
run: pnpm install --frozen-lockfile
shell: bash
env:
CYPRESS_INSTALL_BINARY: "0"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true"
- name: Login to registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}
username: ${{ secrets.registry_username }}
password: ${{ secrets.registry_password }}
- name: Restore standard slim image from cache
id: cache-docker-slim
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
continue-on-error: true
timeout-minutes: 6
with:
path: /tmp/cache/docker-image
key: docker-image-${{ env.SLIM_IMAGE_NAME }}-${{ env.IMAGE_TAG }}
env:
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 5
- name: Load standard slim image
if: ${{ steps.cache-docker-slim.outputs.cache-hit == 'true' }}
run: |
docker load --input /tmp/cache/docker-image/${{ env.SLIM_IMAGE_NAME }}.tar
docker tag ${{ env.SLIM_IMAGE_NAME }}:${{ env.IMAGE_TAG }} ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ env.SLIM_IMAGE_NAME }}:${{ env.IMAGE_TAG }}
shell: bash
- name: Start Centreon Web and database containers
env:
MYSQL_IMAGE: ${{ env.DATABASE_IMAGE }}
run: |
COLLECTION_DIRECTORY=$(dirname "collections/${{ matrix.feature }}")
if [[ -f "${COLLECTION_DIRECTORY}/.env" ]]; then
echo "Using environment file ${COLLECTION_DIRECTORY}/.env"
cat ${COLLECTION_DIRECTORY}/.env >> ../../../.github/docker/.env
fi
docker compose --profile web -f ../../../.github/docker/docker-compose.yml up -d --wait
if [[ -f "${COLLECTION_DIRECTORY}/setup.sh" ]]; then
echo "Running script ${COLLECTION_DIRECTORY}/setup.sh ..."
bash -ex "${COLLECTION_DIRECTORY}/setup.sh"
fi
if [[ -f "${COLLECTION_DIRECTORY}/setup-web.sh" ]]; then
echo "Running script ${COLLECTION_DIRECTORY}/setup-web.sh ..."
docker compose -f ../../../.github/docker/docker-compose.yml cp ${COLLECTION_DIRECTORY}/setup-web.sh web:/tmp/setup-web.sh
docker compose -f ../../../.github/docker/docker-compose.yml exec web bash -ex "/tmp/setup-web.sh"
fi
shell: bash
- name: Run Postman Tests and Generate HTML Report
run: |
collection_file="collections/${{ matrix.feature }}"
collection_name=$(basename "$collection_file" .postman_collection.json)
collection_directory="$(dirname "$collection_file")"
environment_file=$(find "$collection_directory" -maxdepth 1 -type f -name "*.postman_environment.json")
if [ -f "$environment_file" ]; then
echo "Environment: $environment_file"
pnpm newman run "$collection_file" -e "$environment_file" --working-dir "$collection_directory" --reporters cli,htmlextra,json-summary --reporter-htmlextra-title "$collection_name" --reporter-htmlextra-title "${collection_name// /_}" --reporter-htmlextra-export "newman/${collection_name}.html" --reporter-summary-json-export "postman_summaries/${collection_name}-summary.json"
else
echo "The file Environment-Collection.json was not found in the same directory as $collection_file"
exit 1
fi
shell: bash
- name: Display container logs
if: failure()
run: |
echo "::group::docker compose logs"
docker compose -f ../../../.github/docker/docker-compose.yml logs
echo "::endgroup::"
echo "::group::centreon-web.log"
docker compose -f ../../../.github/docker/docker-compose.yml exec web bash -c "cat /var/log/centreon/centreon-web.log 2>/dev/null || echo 'centreon-web.log does not exist'"
echo "::endgroup::"
echo "::group::sql-error.log"
docker compose -f ../../../.github/docker/docker-compose.yml exec web bash -c "cat /var/log/centreon/sql-error.log 2>/dev/null || echo 'sql-error.log does not exist'"
echo "::endgroup::"
shell: bash
- name: Replace / with - in the feature path
id: feature-path
if: always()
run: |
feature_name="${{ matrix.feature }}"
feature_name_with_dash="${feature_name//\//-}"
echo "Modified Feature Name: $feature_name_with_dash"
echo "feature_name_with_dash=$feature_name_with_dash" >> $GITHUB_OUTPUT
- name: Upload HTML Reports
if: failure()
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: newman-${{ inputs.os }}-html-reports-${{ steps.feature-path.outputs.feature_name_with_dash }}
path: centreon/tests/rest_api/newman/
- name: Upload test reports
if: always()
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: newman-${{ inputs.os }}-test-reports-${{ steps.feature-path.outputs.feature_name_with_dash }}
path: centreon/tests/rest_api/postman_summaries/*.json
retention-days: 1
synchronize-with-xray:
needs: [newman-test-run, associate-test-cases]
if: always()
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Generate Xray Token
id: generate-xray-token
run: |
token_response=$(curl -H "Content-Type: application/json" -X POST --data "{\"client_id\": \"${{ secrets.client_id }}\", \"client_secret\": \"${{ secrets.client_secret }}\"}" "https://xray.cloud.getxray.app/api/v1/authenticate")
xray_token=$(echo "$token_response" | sed -n 's/.*"\(.*\)".*/\1/p')
echo "xray_token=$xray_token" >> $GITHUB_OUTPUT
shell: bash
- name: Download Artifacts
uses: actions/download-artifact@87c55149d96e628cc2ef7e6fc2aab372015aec85 # v4.1.3
with:
pattern: newman-${{ inputs.os }}-test-reports-*
path: newman-json-test-reports
merge-multiple: true
- name: Delete Artifacts
run: |
artifact_pattern="newman-${{ inputs.os }}-test-reports-"
TOKEN="${{ secrets.GITHUB_TOKEN }}"
artifact_exists=true
while [ "$artifact_exists" = true ]; do
artifact_exists=false
artifacts_response=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts?per_page=100")
artifacts=$(echo $artifacts_response | jq -c '.artifacts[]')
echo "Those are the artifacts : $artifacts"
while read row; do
artifact_name=$(echo "$row" | jq -r '.name')
if [[ "$artifact_name" =~ ^.*"$artifact_pattern".* ]]; then
artifact_exists=true
echo "Deleting : $artifact_name"
artifact_id=$(echo "$row" | jq -r '.id')
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${artifact_id}"
fi
done <<< "$artifacts"
done
echo "End of Deleting"
shell: bash
- name: Extract and Store Summaries
run: |
declare -A json_info
for summary_file in newman-json-test-reports/*.json; do
summary_content=$(cat "$summary_file" | jq -c '{Name: .Collection.Info.Name, Stats: .Run.Stats, Failures: .Run.Failures}')
filename=$(basename "$summary_file" .json)
clean_filename="${filename// /_}"
clean_filename="${clean_filename//-/_}"
json_info["$clean_filename"]=$summary_content
done
for key in "${!json_info[@]}"; do
echo "Summary info for $key:"
echo "${json_info[$key]}"
done
- name: Change test execution status
if: ${{ inputs.os == 'alma9' && contains(fromJson('["testing", "unstable"]'), inputs.stability) && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.is_nightly == 'true')) }}
run: |
retry_command() {
local max_attempts=$1
local command=$2
local attempt=0
local exit_code=0
while [ $attempt -lt $max_attempts ]; do
attempt=$((attempt + 1))
echo "Attempt $attempt/$max_attempts: $command"
eval "$command"
exit_code=$?
if [ $exit_code -eq 0 ]; then
break
fi
echo "Error: $exit_code"
echo "Response: $(curl -v -s -o /dev/null -w "%{http_code}" "$command")"
sleep 30
done
if [ $exit_code -ne 0 ]; then
echo "Failed after $max_attempts attempts"
exit 1
fi
}
for summary_file in newman-json-test-reports/*.json; do
test_execution_id=${{ needs.associate-test-cases.outputs.test_execution_id }}
test_plan_id=${{ needs.associate-test-cases.outputs.test_plan_id }}
issue_ids="${{ needs.associate-test-cases.outputs.api-issue-ids }}"
# Convert issue_ids string to an array using space as the delimiter
IFS=' ' read -r -a issue_ids_array <<< "$issue_ids"
echo "issue_ids content: ${issue_ids_array[*]}"
filename=$(basename "$summary_file")
collection_name="${filename%-summary.json}"
collection_name="${collection_name//-/_}"
failed_requests=$(jq -r '.Run.Stats.Requests.failed' "$summary_file")
failed_assertions=$(jq -r '.Run.Stats.Assertions.failed' "$summary_file")
failures=$(jq -r '.Run.Failures' "$summary_file")
for issue_id in "${issue_ids_array[@]}"; do
echo "Processing issue ID: $issue_id"
jira_issue_url="https://centreon.atlassian.net/rest/api/2/issue/$issue_id"
command="curl --request GET --url '$jira_issue_url' --user '${{ secrets.jira_user }}:${{ secrets.jira_token_test }}' --header 'Accept: application/json' -o response.json"
retry_command 5 "$command"
response_code=$(jq -r '.statusCode' response.json)
if [ "$response_code" -eq 404 ]; then
echo "The issue with ID $issue_id does not exist or you do not have permission to see it."
else
echo "The issue with ID $issue_id exists."
summary=$(jq -r '.fields.summary' response.json)
echo "Summary: $summary"
echo "Collection Name: $collection_name"
if [ "$summary" == "$collection_name" ]; then
echo "Matching issue ID: $issue_id with Collection Name: $collection_name"
if [ "$failed_requests" -gt 0 ] || [ "$failed_assertions" -gt 0 ]; then
newStatus="FAILED"
else
newStatus="PASSED"
fi
xray_graphql_getTestRunIDs='{
"query": "query GetTestRuns($testIssueIds: [String], $testExecIssueIds: [String], $limit: Int!) { getTestRuns(testIssueIds: $testIssueIds, testExecIssueIds: $testExecIssueIds, limit: $limit) { total limit start results { id status { name color description } gherkin examples { id status { name color description } } test { issueId } testExecution { issueId } } } }",
"variables": {
"testIssueIds": ["'"$issue_id"'"],
"testExecIssueIds": ["'"$test_execution_id"'"],
"limit": 100
}
}'
echo "$xray_graphql_getTestRunIDs"
retry_attempts=0
max_attempts=5
while [ $retry_attempts -lt $max_attempts ]; do
response_getTestRun=$(curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${{ steps.generate-xray-token.outputs.xray_token}}" --data "$xray_graphql_getTestRunIDs" -v "https://xray.cloud.getxray.app/api/v2/graphql")
echo "$response_getTestRun"
if echo "$response_getTestRun" | jq -e '.error' > /dev/null; then
echo "Error in response: $(echo "$response_getTestRun" | jq -r '.error.text')"
echo "Retrying after a delay..."
retry_attempts=$((retry_attempts + 1))
sleep $((retry_attempts * 30))
else
break
fi
done
if [ $retry_attempts -ge $max_attempts ]; then
echo "Failed after $max_attempts attempts"
continue
fi
test_run_id=$(echo "$response_getTestRun" | jq -r ".data.getTestRuns.results[] | select(.test.issueId == \"$issue_id\") | .id")
if [ -n "$test_run_id" ]; then
echo "Found Test Run ID $test_run_id for Issue ID $issue_id and Collection Name $collection_name"
graphqlMutation="{\"query\": \"mutation { updateTestRunStatus(id: \\\"$test_run_id\\\", status: \\\"$newStatus\\\") }\"}"
echo "$graphqlMutation"
command="curl -X POST -H 'Content-Type: application/json' -H 'Authorization: Bearer ${{ steps.generate-xray-token.outputs.xray_token}}' --data '$graphqlMutation' -v 'https://xray.cloud.getxray.app/api/v2/graphql'"
retry_command 5 "$command"
else
echo "Test Run ID not found for Issue ID $issue_id and Collection Name $collection_name."
fi
fi
fi
done
done
- name: Perform Jira Transitions
if: ${{ inputs.os == 'alma9' && contains(fromJson('["testing", "unstable"]'), inputs.stability) && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.is_nightly == 'true')) }}
run: |
transition_ids=("61" "81" "21" "31")
issue_ids="${{ needs.associate-test-cases.outputs.api-issue-ids }}"
# Convert issue_ids string to an array using space as the delimiter
IFS=' ' read -r -a issue_ids_array <<< "$issue_ids"
echo "issue_ids content: ${issue_ids_array[*]}"
for test_issue_id in "${issue_ids_array[@]}"; do
# Make a GET request to get information about available transitions
get_response=$(curl --request GET \
--url "https://centreon.atlassian.net/rest/api/2/issue/${test_issue_id}/transitions?expand=transitions.fields" \
--user "${{ secrets.jira_user }}:${{ secrets.jira_token_test }}" \
--header 'Accept: application/json')
# Extract the transition ID from the response
current_transition_id=$(echo "$get_response" | jq -r '.transitions[0].id')
# Check if the current transition ID is 41
if [ "$current_transition_id" -eq 41 ]; then
echo "Skipping Jira transition for issue ID $test_issue_id as current transition ID is 41."
else
# Perform the POST request for transitions other than 41
for transition_id in "${transition_ids[@]}"; do
curl --request POST \
--url "https://centreon.atlassian.net/rest/api/2/issue/${test_issue_id}/transitions?expand=transitions.fields" \
--user "${{ secrets.jira_user }}:${{ secrets.jira_token_test }}" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"transition": {
"id": "'"$transition_id"'"
}
}'
echo "Processing issue ID: $test_issue_id"
echo "Performing Jira transition with transition ID: $transition_id..."
done
fi
done
- name: Generate and Display Summaries
if: ${{ contains(needs.newman-test-run.result, 'failure') }}
run: |
summaries=""
has_failures=false
for summary_file in newman-json-test-reports/*.json; do
collection_name=$(jq -r '.Collection.Info.Name' "$summary_file")
total_requests=$(jq -r '.Run.Stats.Requests.total' "$summary_file")
pending_requests=$(jq -r '.Run.Stats.Requests.pending' "$summary_file")
failed_requests=$(jq -r '.Run.Stats.Requests.failed' "$summary_file")
failed_assertions=$(jq -r '.Run.Stats.Assertions.failed' "$summary_file")
failures=$(jq -r '.Run.Failures' "$summary_file")
echo "$failures"
if [ "$failed_requests" -gt 0 ] || [ "$failed_assertions" -gt 0 ]; then
has_failures=true # Set has_failures to true if there are failures
summaries+="<table>"
summaries+="<tr><th>Collection Name</th><th>Total Requests</th><th>⏭️ Skipped requests</th><th>❌ Failed Requests</th><th>❌ Failed Assertions</th></tr>"
summaries+="<tr><td>$collection_name</td><td>$total_requests</td><td>$pending_requests</td><td>$failed_requests</td><td>$failed_assertions</td></tr>"
summaries+="</table>"
filtered_failures=$(echo "$failures" | jq -c '.[] | select(.Parent.Name // "" != "" and .Source.Name // "" != "" and .Error.Message // "" != "")')
while IFS= read -r row; do
parent_name=$(echo "$row" | jq -r '.Parent.Name')
source_name=$(echo "$row" | jq -r '.Source.Name')
error_message=$(echo "$row" | jq -r '.Error.Message')
summaries+="<p><strong>📁 Collection name:</strong> $parent_name<br><strong>📬 Request name:</strong> $source_name<br><strong>❌ Error message:</strong> $error_message</p>"
done <<< "$(echo "$filtered_failures")"
fi
echo "Processing summary file: $summary_file"
done
if [ -n "$summaries" ]; then
echo -e "$summaries" >> $GITHUB_STEP_SUMMARY
fi
regroup-artifacts:
needs: [newman-test-run]
if: always()
runs-on: ubuntu-22.04
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
if: ${{ contains(needs.newman-test-run.result, 'failure') }}
with:
name: newman-${{ inputs.os }}-html-reports
pattern: newman-${{ inputs.os }}-html-reports-*
retention-days: 1
- name: Delete merged artifacts
uses: geekyeggo/delete-artifact@24928e75e6e6590170563b8ddae9fac674508aa1 # v5.0.0
with:
name: newman-${{ inputs.os }}-html-reports-*
failOnError: false