## 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>/d' "$FILE" sed -i '//,/<\/testsuite>/d' "$FILE" DIRS="${{ matrix.testsuite_dirs }}" echo "Debug: $DIRS" NEW_TESTSUITE_ENTRY=$( echo "" IFS=','; for dir in $DIRS; do echo " $dir"; done echo " testsuite/Magento/IntegrationTest.php" echo "" ) 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 '//i\\\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"