-
Notifications
You must be signed in to change notification settings - Fork 12
288 lines (253 loc) · 12.8 KB
/
full-integration-tests.yaml
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
## Workflow is only for Magento 2 Main repo - app/code and dev/tests/integration are supported only
## 3rd party modules are not supported yet
name: Integration Tests - Full Test Suite
run-name: ${{ github.actor }} is running Full Integration Test Suite
on:
workflow_call:
inputs:
repository:
type: string
description: "Repository"
required: true
head:
type: string
description: "head SHA"
required: true
test_directory:
type: string
description: "Test directory to run integration tests"
required: false
permissions:
contents: write
jobs:
matrix-calculator:
runs-on: ubuntu-latest
outputs:
php_versions: ${{ steps.set-matrix.outputs.php_versions }}
database_versions: ${{ steps.set-matrix.outputs.database_versions }}
search_versions: ${{ steps.set-matrix.outputs.search_versions }}
message_queue_versions: ${{ steps.set-matrix.outputs.message_queue_versions }}
cache_versions: ${{ steps.set-matrix.outputs.cache_versions }}
http_cache_versions: ${{ steps.set-matrix.outputs.http_cache_versions }}
testsuite_dirs: ${{ steps.set-matrix-testsuite.outputs.testsuite_dirs }}
steps:
- name: Checkout commit
uses: actions/checkout@v4
with:
repository: ${{ github.event.inputs.repository }}
ref: ${{ github.event.inputs.head }}
fetch-depth: 1
- id: set-matrix
name: Calculate Matrix
run: |
echo "php_versions=$(jq -c .services.php supported-services.json)" >> "$GITHUB_OUTPUT"
echo "database_versions=$(jq -c .services.database supported-services.json)" >> "$GITHUB_OUTPUT"
echo "search_versions=$(jq -c .services.search supported-services.json)" >> "$GITHUB_OUTPUT"
echo "message_queue_versions=$(jq -c .services.message_queue supported-services.json)" >> "$GITHUB_OUTPUT"
echo "cache_versions=$(jq -c .services.cache supported-services.json)" >> "$GITHUB_OUTPUT"
echo "http_cache_versions=$(jq -c .services.http_cache supported-services.json)" >> "$GITHUB_OUTPUT"
- id: set-matrix-testsuite
name: Calculate Matrix for testsuite
working-directory: dev/tests/integration
run: |
### TODO: rebuild all that hell to node-js
if [ -n "${{ github.event.inputs.test_directory }}" ]; then
echo "testsuite_dirs=['${{ github.event.inputs.test_directory }}']" >> "$GITHUB_OUTPUT"
exit 0
fi
OUTPUT_FILE="integration-testsuites.json"
TESTSUITE_DIR="./testsuite/Magento"
CODE_DIR="../../../app/code"
MAX_DIRS_PER_LINE=1
## variable with array of exclusion list of directories - they will be handled separately and splitted on more batches
EXCLUSION_LIST=("./testsuite/Magento/Catalog" "./testsuite/Magento/Bundle" "./testsuite/Magento/AsynchronousOperations" "./testsuite/Magento/Sales")
## variable with array of exclusion list of files - separate run will be executed for each file (separate place in tests matrix)
STANDALONE_TESTS=("./testsuite/Magento/AsynchronousOperations/Model/MassScheduleTest.php" "./testsuite/Magento/Catalog/Observer/SwitchPriceAttributeScopeOnConfigChangeTest.php" "./testsuite/Magento/Catalog/Model/CategoryTest.php" "./testsuite/Magento/Bundle/Model/ProductTest.php" "./testsuite/Magento/Catalog/Block/Adminhtml/Category/Tab/ProductTest.php")
# Initialize variables
dir_count=0
json_content="{\n\t\"testsuites\": [\n\t\t\""
current_line=""
# Function to add a directory to the current line, handling comma and count
add_dir_to_line() {
local dir=$1
# Check if current_line is empty to avoid leading commas
if [ -z "$current_line" ]; then
current_line="$dir"
else
current_line="$current_line,$dir"
fi
dir_count=$((dir_count + 1))
if [ "$dir_count" -eq "$MAX_DIRS_PER_LINE" ]; then
json_content="$json_content$current_line"
json_content="$json_content\",\n\t\t\""
current_line=""
dir_count=0
fi
}
# Iterate over the directories and populate the JSON content
while IFS= read -r -d '' dir; do
# if dir is in EXCLUSION_LIST then skip it
if [[ " ${EXCLUSION_LIST[@]} " =~ " ${dir} " ]]; then
continue
fi
add_dir_to_line "${dir}"
done < <(find "$TESTSUITE_DIR" -mindepth 1 -maxdepth 1 -type d -print0)
# Add app/code integration test directories
while IFS= read -r -d '' dir; do
relative_dir="${dir}" # Convert absolute path to relative
add_dir_to_line "$relative_dir"
done < <(find "$CODE_DIR" -mindepth 4 -maxdepth 4 -type d -name 'Integration' -print0)
# Handle exclusion list
# run over EXCLUSION_LIST, find all "*Test.php" files, and put them in array. Exclude directories.
EXCLUSION_LIST_FILES=()
for dir in "${EXCLUSION_LIST[@]}"; do
while IFS= read -r -d '' file; do
# check if file is in STANDALONE_TESTS
if [[ " ${STANDALONE_TESTS[@]} " =~ " ${file} " ]]; then
continue
fi
EXCLUSION_LIST_FILES+=("$file")
done < <(find "$dir" -mindepth 1 -type f -name '*Test.php' -print0)
done
## run over EXCLUSION_LIST_FILES and call add_dir_to_line for each file
MAX_DIRS_PER_LINE=10
dir_count=MAX_DIRS_PER_LINE-1
add_dir_to_line ""
for file in "${EXCLUSION_LIST_FILES[@]}"; do
add_dir_to_line "$file"
done
## run over STANDALONE_TESTS and call add_dir_to_line for each file
MAX_DIRS_PER_LINE=1
dir_count=MAX_DIRS_PER_LINE-1
add_dir_to_line ""
for file in "${STANDALONE_TESTS[@]}"; do
add_dir_to_line "$file"
done
# Handle the last line if it's not empty
if [ -n "$current_line" ]; then
json_content="$json_content$current_line"
fi
# Close the JSON string
json_content="$json_content\"\n\t]\n}\n"
# Write to the output file
echo -e "$json_content" > "$OUTPUT_FILE"
#######
echo "testsuite_dirs=$(jq -c .testsuites integration-testsuites.json)" >> "$GITHUB_OUTPUT"
- name: Debug output
run: |
echo "PHP Versions: ${{ steps.set-matrix.outputs.php_versions }}"
echo "database Versions: ${{ steps.set-matrix.outputs.database_versions }}"
echo "search Versions: ${{ steps.set-matrix.outputs.search_versions }}"
echo "message_queue Versions: ${{ steps.set-matrix.outputs.message_queue_versions }}"
echo "cache Versions: ${{ steps.set-matrix.outputs.cache_versions }}"
echo "http_cache Versions: ${{ steps.set-matrix.outputs.http_cache_versions }}"
echo "testsuite_dirs: ${{ steps.set-matrix-testsuite.outputs.testsuite_dirs }}"
run-integration-tests:
needs: [matrix-calculator]
strategy:
fail-fast: false
matrix:
php_version: ${{ fromJSON(needs.matrix-calculator.outputs.php_versions) }}
database_version: ${{ fromJSON(needs.matrix-calculator.outputs.database_versions) }}
search_version: ${{ fromJSON(needs.matrix-calculator.outputs.search_versions) }}
message_queue_version: ${{ fromJSON(needs.matrix-calculator.outputs.message_queue_versions) }}
cache_version: ${{ fromJSON(needs.matrix-calculator.outputs.cache_versions) }}
http_cache_version: ${{ fromJSON(needs.matrix-calculator.outputs.http_cache_versions) }}
testsuite_dirs: ${{ fromJSON(needs.matrix-calculator.outputs.testsuite_dirs) }}
runs-on: ubuntu-latest
steps:
- name: Checkout commit
uses: actions/checkout@v4
with:
repository: ${{ github.event.inputs.repository }}
ref: ${{ github.event.inputs.head }}
path: main
fetch-depth: 0
- name: Setup Warden Environment
uses: mage-os/github-actions/warden/setup-environment@main
with:
run_composer_install: 1
php_version: ${{ matrix.php_version }}
database: ${{ matrix.database_version }}
search: ${{ matrix.search_version }}
rabbitmq: ${{ matrix.message_queue_version }}
redis: ${{ matrix.cache_version }}
varnish: ${{ matrix.http_cache_version }}
base_directory: "./main"
- name: Setup configs for Integration Tests
uses: mage-os/github-actions/warden/integration-tests@main
with:
search: ${{ matrix.search_version }}
rabbitmq: ${{ matrix.message_queue_version }}
redis: ${{ matrix.cache_version }}
run_memory_test: 0
run_magento_integration_tests: 0
run_magento_integration_tests_real_suite: 0
base_directory: "./main"
- name: Create Mage-OS testsuite
working-directory: ./main/dev/tests/integration
run: |
FILE="phpunit.xml.dist"
# Remove Memory Usage Tests and Magento Integration Tests Real Suite test suites
sed -i '/<testsuite name="Memory Usage Tests">/,/<\/testsuite>/d' "$FILE"
sed -i '/<testsuite name="Magento Integration Tests Real Suite">/,/<\/testsuite>/d' "$FILE"
DIRS="${{ matrix.testsuite_dirs }}"
echo "Debug: $DIRS"
NEW_TESTSUITE_ENTRY=$(
echo "<testsuite name=\"Mage-OS Suite\">"
IFS=','; for dir in $DIRS; do echo " <directory>$dir</directory>"; done
echo " <exclude>testsuite/Magento/IntegrationTest.php</exclude>"
echo "</testsuite>"
)
echo "Debug: $NEW_TESTSUITE_ENTRY"
awk -v new_testsuite="$NEW_TESTSUITE_ENTRY" '/<\/testsuites>/ { print new_testsuite; found=1 } {print} END { if (!found) print new_testsuite }' "$FILE" > tmpfile && mv tmpfile "$FILE"
echo "\nMage-OS suite has been added to $FILE \n"
## TODO: I want to have a possibility to NOT ignore those test if I wish to - by adding additional input to github actions, for example
sed -i '/<testsuites>/i\<groups>\<exclude>\<group>integrationIgnore<\/group><\/exclude><\/groups>' "$FILE"
echo "\nIgnore group `integrationIgnore` has been added to $FILE \n"
cat $FILE;
- name: Run Integration Tests for Modules
working-directory: ./main
run: |
export WARDEN="$(dirname $(pwd))/warden/bin/warden"
# Important: Run the custom "Magento Integration Tests" test suite, which runs all other test suites
${WARDEN} env exec -T --workdir /var/www/html/dev/tests/integration php-fpm ../../../vendor/bin/phpunit --configuration phpunit.xml.dist --testsuite 'Magento Integration Tests' --log-junit=../../../phpunit-output/junit/res-log.xml --coverage-html=../../../phpunit-output/coverage-html/res.html
rum-memory-integration-tests:
needs: [ matrix-calculator ]
strategy:
fail-fast: false
matrix:
php_version: ${{ fromJSON(needs.matrix-calculator.outputs.php_versions) }}
database_version: ${{ fromJSON(needs.matrix-calculator.outputs.database_versions) }}
search_version: ${{ fromJSON(needs.matrix-calculator.outputs.search_versions) }}
message_queue_version: ${{ fromJSON(needs.matrix-calculator.outputs.message_queue_versions) }}
cache_version: ${{ fromJSON(needs.matrix-calculator.outputs.cache_versions) }}
http_cache_version: ${{ fromJSON(needs.matrix-calculator.outputs.http_cache_versions) }}
runs-on: ubuntu-latest
steps:
- name: Checkout commit
uses: actions/checkout@v4
with:
repository: ${{ github.event.inputs.repository }}
ref: ${{ github.event.inputs.head }}
path: main
fetch-depth: 0
- name: Setup Warden Environment
uses: mage-os/github-actions/warden/setup-environment@main
with:
run_composer_install: 1
php_version: ${{ matrix.php_version }}
database: ${{ matrix.database_version }}
search: ${{ matrix.search_version }}
rabbitmq: ${{ matrix.message_queue_version }}
redis: ${{ matrix.cache_version }}
varnish: ${{ matrix.http_cache_version }}
base_directory: "./main"
- name: Run Integration tests
uses: mage-os/github-actions/warden/integration-tests@main
with:
search: ${{ matrix.search_version }}
rabbitmq: ${{ matrix.message_queue_version }}
redis: ${{ matrix.cache_version }}
run_memory_test: "true"
base_directory: "./main"