diff --git a/warden/integration-tests/action.yml b/warden/integration-tests/action.yml new file mode 100644 index 0000000..5673d57 --- /dev/null +++ b/warden/integration-tests/action.yml @@ -0,0 +1,182 @@ +name: "Integration Tests Mage-OS in Warden" +author: "Mage-OS" +description: "A Github Action that run Integration Tests of Mage-OS in Warden." + +inputs: + search: + required: true + default: "opensearch:2.5" + description: "The search engine to use." + + rabbitmq: + required: true + default: "rabbitmq:3.11" + description: "Rabbit MQ version to use." + + redis: + required: true + default: "redis:7.0" + description: "Redis version to use." + + run_memory_test: + required: true + default: "0" + description: "Run Memory Test." + + run_magento_integration_tests: + required: true + default: "1" + description: "Run Magento Integration Tests." + + run_magento_integration_tests_real_suite: + required: true + default: "1" + description: "Run Magento Integration Tests Real Suite." + + base_directory: + required: true + default: "./" + description: "Base directory for the Mage-OS codebase." + +runs: + using: composite + steps: + + - name: Prepare config for Integration tests + working-directory: ${{ inputs.base_directory }} + shell: bash + env: + SEARCH: ${{ inputs.search }} + RABBITMQ: ${{ inputs.rabbitmq }} + REDIS: ${{ inputs.redis }} + run: | + CONFIG_FILE=dev/tests/integration/etc/install-config-mysql.php + + SEARCH_ENGINE_TYPE=${SEARCH%%:*} + SEARCH_ENGINE_VERSION=${SEARCH##:*} + + case "$SEARCH" in + elasticsearch:*) + SEARCH_HOST="elasticsearch" + ;;& + elasticsearch:5*) + SEARCH_ENGINE="elasticsearch5" + SEARCH_PARAMS="'search-engine' => '$SEARCH_ENGINE', 'elasticsearch-host' => '$SEARCH_HOST', 'elasticsearch-port' => 9200," + ;; + elasticsearch:6*) + SEARCH_ENGINE="elasticsearch6" + SEARCH_PARAMS="'search-engine' => '$SEARCH_ENGINE', 'elasticsearch-host' => '$SEARCH_HOST', 'elasticsearch-port' => 9200," + ;; + elasticsearch:7* | elasticsearch:8*) + SEARCH_ENGINE="elasticsearch7" + SEARCH_PARAMS="'search-engine' => '$SEARCH_ENGINE', 'elasticsearch-host' => '$SEARCH_HOST', 'elasticsearch-port' => 9200," + ;; + opensearch:*) + SEARCH_ENGINE="opensearch" + SEARCH_HOST="opensearch" + SEARCH_PARAMS="'search-engine' => '$SEARCH_ENGINE', 'opensearch-host' => '$SEARCH_HOST', 'opensearch-port' => 9200, 'opensearch-index-prefix' => 'magento2', 'opensearch-enable-auth' => 0, 'opensearch-timeout' => 15," + ;; + *) + SEARCH_ENGINE="elasticsearch7" + SEARCH_HOST="UKNOWN" + SEARCH_PARAMS="'search-engine' => '$SEARCH_ENGINE', 'elasticsearch-host' => '$SEARCH_HOST', 'elasticsearch-port' => 9200," + ;; + esac + + cat << EOL > ${CONFIG_FILE} + 'tmp-mysql', + 'db-user' => 'root', + 'db-password' => 'magento', + 'db-name' => 'magento_integration_tests', + 'backend-frontname' => 'backend', + $SEARCH_PARAMS + 'admin-user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME, + 'admin-password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD, + 'admin-email' => \Magento\TestFramework\Bootstrap::ADMIN_EMAIL, + 'admin-firstname' => \Magento\TestFramework\Bootstrap::ADMIN_FIRSTNAME, + 'admin-lastname' => \Magento\TestFramework\Bootstrap::ADMIN_LASTNAME, + EOL + + if [[ -n $RABBITMQ ]]; then + cat << EOL >> ${CONFIG_FILE} + 'amqp-host' => 'rabbitmq', + 'amqp-port' => '5672', + 'amqp-user' => 'guest', + 'amqp-password' => 'guest', + EOL + fi + + if [[ -n $REDIS ]]; then + cat << EOL >> ${CONFIG_FILE} + 'session-save' => 'redis', + 'session-save-redis-host' => 'redis', + 'session-save-redis-port' => 6379, + 'session-save-redis-db' => 2, + 'session-save-redis-max-concurrency' => 20, + 'cache-backend' => 'redis', + 'cache-backend-redis-server' => 'redis', + 'cache-backend-redis-db' => 0, + 'cache-backend-redis-port' => 6379, + 'page-cache' => 'redis', + 'page-cache-redis-server' => 'redis', + 'page-cache-redis-db' => 1, + 'page-cache-redis-port' => 6379, + EOL + fi + + cat << EOL >> ${CONFIG_FILE} + ]; + EOL + + echo "configuration" + cat ${CONFIG_FILE} + + - name: Run Memory Test + if: ${{ inputs.run_memory_test == 1 }} + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm /bin/bash -c "cd ./dev/tests/integration + echo -e '\033[32mRun Memory Tests\033[0m' + php ../../../vendor/bin/phpunit + --configuration phpunit.xml.dist + --coverage-clover=coverage.xml + --log-junit=test-results.xml + --coverage-html=coverage + --testsuite 'Memory Usage Tests' + " + + - name: Run Magento Integration Tests + if: ${{ inputs.run_magento_integration_tests == 1 }} + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm /bin/bash -c "cd ./dev/tests/integration + echo -e '\033[32mRun Magento Integration Tests\033[0m' + php ../../../vendor/bin/phpunit + --configuration phpunit.xml.dist + --coverage-clover=coverage.xml + --log-junit=test-results.xml + --coverage-html=coverage + --testsuite 'Magento Integration Tests' + " + + - name: Run Magento Integration Tests Real Suite + if: ${{ inputs.run_magento_integration_tests_real_suite == 1 }} + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm /bin/bash -c "cd ./dev/tests/integration + echo -e '\033[32mRun Magento Integration Tests Real Suite\033[0m' + php ../../../vendor/bin/phpunit + --configuration phpunit.xml.dist + --coverage-clover=coverage.xml + --log-junit=test-results.xml + --coverage-html=coverage + --testsuite 'Magento Integration Tests Real Suite' + " diff --git a/warden/setup-environment/action.yml b/warden/setup-environment/action.yml new file mode 100644 index 0000000..712de6d --- /dev/null +++ b/warden/setup-environment/action.yml @@ -0,0 +1,397 @@ +name: "Setup Mage-OS in Warden" +author: "Mage-OS" +description: "A Github Action that pull and set-up Mage-OS in Warden env." + +inputs: + warden_version: + required: true + default: "0.14.1" + description: "The version of Warden to use." + + php_version: + required: true + default: "8.2" + description: "PHP version used in Warden container." + + composer_version: + required: true + default: "2.2.22" + description: "The version of Composer to use." + + database: + required: true + default: "mariadb:10.6" + description: "The distribution : version of the database to use." + + search: + required: true + default: "opensearch:2.5" + description: "The search engine to use." + + varnish: + required: true + default: "varnish:7.3" + description: "Varnish version to use." + + rabbitmq: + required: true + default: "rabbitmq:3.11" + description: "Rabbit MQ version to use." + + redis: + required: true + default: "redis:7.0" + description: "Redis version to use." + + run_composer_install: + required: true + default: "0" + description: "Whether to run composer install or not." + + run_setup_install: + required: true + default: "0" + description: "Whether to run setup:install or not." + + run_setup_upgrade: + required: true + default: "0" + description: "Whether to run setup:upgrade or not." + + run_reindex: + required: true + default: "0" + description: "Whether to run indexer:reindex or not." + + run_production_deploy_mode: + required: true + default: "0" + description: "Whether to run deploy:mode:set production or not." + + run_magento_config_preset: + required: true + default: "0" + description: "Whether to run magento config preset or not." + + run_admin_user_creation: + required: true + default: "0" + description: "Whether to run admin user creation or not." + + base_directory: + required: true + default: "./" + description: "Base directory for the Mage-OS codebase." + +runs: + using: composite + steps: + - name: Checkout Warden Repo + uses: actions/checkout@v4 + with: + repository: wardenenv/warden + path: warden + ref: refs/tags/${{ inputs.warden_version }} + + - name: Init / Configure Warden + working-directory: ${{ inputs.base_directory }} + shell: bash + env: + PHP_VERSION: ${{ inputs.php_version }} + COMPOSER_VERSION: ${{ inputs.composer_version }} + DATABASE: ${{ inputs.database }} + SEARCH: ${{ inputs.search }} + VARNISH: ${{ inputs.varnish }} + RABBITMQ: ${{ inputs.rabbitmq }} + REDIS: ${{ inputs.redis }} + run: | + # Splitting database input to distribution and version + DB_DISTRIBUTION=${DATABASE%%:*} + DB_DISTRIBUTION_VERSION=${DATABASE##*:} + + # Splitting search input and setting corresponding flags and versions + if [[ $SEARCH == elasticsearch* ]]; then + WARDEN_ELASTICSEARCH=1 + WARDEN_OPENSEARCH=0 + ELASTICSEARCH_VERSION=${SEARCH##*:} + OPENSEARCH_VERSION="" + else + WARDEN_ELASTICSEARCH=0 + WARDEN_OPENSEARCH=1 + ELASTICSEARCH_VERSION="" + OPENSEARCH_VERSION=${SEARCH##*:} + fi + + # Setting version variables based on the usage flags + RABBITMQ_VERSION="" + if [[ $RABBITMQ != null ]]; then + RABBITMQ_VERSION=${RABBITMQ##*:} + RABBITMQ=1 + else + RABBITMQ=0 + fi + + REDIS_VERSION="" + if [[ $REDIS != null ]]; then + REDIS_VERSION=${REDIS##*:} + REDIS=1 + else + REDIS=0 + fi + + VARNISH_VERSION="" + if [[ $VARNISH != null ]]; then + VARNISH_VERSION=${VARNISH##*:} + VARNISH=1 + else + VARNISH=0 + fi + + # Creating .env file by substituting variables directly in the template + cat << EOF > .env + WARDEN_ENV_NAME=mageos + WARDEN_ENV_TYPE=magento2 + WARDEN_WEB_ROOT=/ + + TRAEFIK_DOMAIN=mageos.test + TRAEFIK_SUBDOMAIN=app + + WARDEN_DB=1 + WARDEN_ELASTICSEARCH=${WARDEN_ELASTICSEARCH} + WARDEN_OPENSEARCH=${WARDEN_OPENSEARCH} + WARDEN_ELASTICHQ=0 + WARDEN_VARNISH=${VARNISH} + WARDEN_RABBITMQ=${RABBITMQ} + WARDEN_REDIS=${REDIS} + + ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION} + OPENSEARCH_VERSION=${OPENSEARCH_VERSION} + DB_DISTRIBUTION=${DB_DISTRIBUTION} + DB_DISTRIBUTION_VERSION=${DB_DISTRIBUTION_VERSION} + NODE_VERSION=12 + COMPOSER_VERSION=${COMPOSER_VERSION} + PHP_VERSION=${PHP_VERSION} + PHP_XDEBUG_3=1 + RABBITMQ_VERSION=${RABBITMQ_VERSION} + REDIS_VERSION=${REDIS_VERSION} + VARNISH_VERSION=${VARNISH_VERSION} + + WARDEN_SYNC_IGNORE= + + WARDEN_ALLURE=0 + WARDEN_SELENIUM=0 + WARDEN_SELENIUM_DEBUG=0 + WARDEN_BLACKFIRE=0 + WARDEN_SPLIT_SALES=0 + WARDEN_SPLIT_CHECKOUT=0 + WARDEN_TEST_DB=1 + WARDEN_MAGEPACK=0 + + BLACKFIRE_CLIENT_ID= + BLACKFIRE_CLIENT_TOKEN= + BLACKFIRE_SERVER_ID= + BLACKFIRE_SERVER_TOKEN= + EOF + + echo ".env created" + cat .env + + - name: Warden svc up && Warden env up + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} svc up + ${WARDEN} env up + + - name: Change Directory Permissions + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm sudo chmod -R 777 . + + - name: Wait for environment to be ready + working-directory: ${{ inputs.base_directory }} + shell: bash + env: + SEARCH: ${{ inputs.search }} + run: | + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + case "${SEARCH}" in + elasticsearch:*) + SEARCH_HOST="elasticsearch" + ;; + *) + SEARCH_HOST="opensearch" + ;; + esac + HEALTHY=1 + for ((i=1; i<=24; i++)); do + SEARCH_STATUS=$(${WARDEN} env exec -T php-fpm bash -c "curl --write-out %{http_code} --silent --output /dev/null http://${SEARCH_HOST}:9200/_cat/health?h=st; exit 0") + echo "search status: ${SEARCH_STATUS}" + if [ ${SEARCH_STATUS} -eq "200" ]; then + HEALTHY=0 + break + fi + sleep 5 + done + echo "HEALTHY: ${HEALTHY}" + exit ${HEALTHY} + + - name: composer install run + working-directory: ${{ inputs.base_directory }} + shell: bash + env: + RUN_INSTALL: ${{ inputs.run_composer_install }} + run: | + if [ $RUN_INSTALL == "1" ]; then + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + wget https://getcomposer.org/download/${{ inputs.composer_version }}/composer.phar -O composer.phar 1>/dev/null 2>&1 && chmod +x composer.phar + ${WARDEN} env exec -T php-fpm php composer.phar -v + ${WARDEN} env exec -T php-fpm php composer.phar install --no-interaction --no-progress + else + echo "Skipping composer install" + fi + + - name: Install Magento + working-directory: ${{ inputs.base_directory }} + shell: bash + env: + SEARCH: ${{ inputs.search }} + REDIS: ${{ inputs.redis }} + RABBITMQ: ${{ inputs.rabbitmq }} + VARNISH: ${{ inputs.varnish }} + RUN_SETUP_INSTALL: ${{ inputs.run_setup_install }} + run: | + if [ $RUN_SETUP_INSTALL == "1" ]; then + SEARCH_ENGINE_VERSION=${SEARCH##*:} + case "$SEARCH" in + elasticsearch:*) + SEARCH_HOST="elasticsearch" + ;;& + elasticsearch:5*) + SEARCH_TYPE="elasticsearch5" + ;; + elasticsearch:6*) + SEARCH_TYPE="elasticsearch6" + ;; + elasticsearch:7* | elasticsearch:8*) + SEARCH_TYPE="elasticsearch7" + ;; + opensearch:*) + SEARCH_TYPE="opensearch" + SEARCH_HOST="opensearch" + ;; + *) + # Default values + SEARCH_TYPE="elasticsearch7" + SEARCH_HOST="elasticsearch" + ;; + esac + + declare -a PARAMETERS + PARAMETERS+=(--backend-frontname=admin --db-host=db --db-name=magento --db-user=magento --db-password=magento) + + if [[ -n $REDIS ]]; then + PARAMETERS+=(--session-save=redis --session-save-redis-host=redis --session-save-redis-port=6379 --session-save-redis-db=2 --cache-backend=redis --cache-backend-redis-server=redis --cache-backend-redis-db=0 --cache-backend-redis-port=6379 --page-cache=redis --page-cache-redis-server=redis --page-cache-redis-db=1 --page-cache-redis-port=6379) + fi + + if [[ -n $VARNISH ]]; then + PARAMETERS+=(--http-cache-hosts=varnish:80) + fi + + if [[ -n $RABBITMQ ]]; then + PARAMETERS+=(--amqp-host=rabbitmq --amqp-port=5672 --amqp-user=guest --amqp-password=guest) + fi + + if [[ $SEARCH_TYPE == "opensearch" ]]; then + PARAMETERS+=(--opensearch-host=$SEARCH_HOST --opensearch-port=9200 --opensearch-index-prefix=magento2 --opensearch-enable-auth=0 --opensearch-timeout=15) + else + PARAMETERS+=(--search-engine=$SEARCH_TYPE --elasticsearch-host=$SEARCH_HOST --elasticsearch-port=9200 --elasticsearch-enable-auth=0 --elasticsearch-index-prefix=magento2) + fi + + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm bin/magento setup:install "${PARAMETERS[@]}" + + else + echo "Skipping setup:install" + fi + + - name: Create Admin User + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + if [ ${{ inputs.run_admin_user_creation }} == "1" ]; then + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm php bin/magento admin:user:create \ + --admin-user=admin \ + --admin-password=abcABC123 \ + --admin-email=user-email-dummy@mage-os-awesome.com \ + --admin-firstname=Admin \ + --admin-lastname=User + else + echo "Skipping admin user creation" + fi + + - name: Set All Magento Configs + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + if [ ${{ inputs.run_magento_config_preset }} == "1" ]; then + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm bin/magento config:set --lock-env web/secure/use_in_adminhtml 1 + ${WARDEN} env exec -T php-fpm bin/magento config:set --lock-env web/secure/use_in_frontend 1 + ${WARDEN} env exec -T php-fpm bin/magento config:set --lock-env web/secure/use_in_frontend 1 + ${WARDEN} env exec -T php-fpm bin/magento config:set cms/wysiwyg/enabled disabled + ${WARDEN} env exec -T php-fpm bin/magento config:set admin/security/admin_account_sharing 1 + ${WARDEN} env exec -T php-fpm bin/magento config:set admin/security/use_form_key 0 + ${WARDEN} env exec -T php-fpm bin/magento config:set web/seo/use_rewrites 1 + else + echo "Skipping magento config preset" + fi + + - name: Run Magento Setup Upgrade + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + if [ ${{ inputs.run_setup_upgrade }} == "1" ]; then + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm bin/magento setup:upgrade + ${WARDEN} env exec -T php-fpm bin/magento setup:db:status + else + echo "Skipping setup:upgrade" + fi + + - name: Set to production mode + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + if [ ${{ inputs.run_production_deploy_mode }} == "1" ]; then + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm bin/magento deploy:mode:set production + else + echo "Skipping deploy:mode:set production" + fi + + - name: Run Magento Re-indexation + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + if [ ${{ inputs.run_reindex }} == "1" ]; then + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm bin/magento indexer:reindex + else + echo "Skipping indexer:reindex" + fi + + - name: Run PHP BIN/MAGENTO + working-directory: ${{ inputs.base_directory }} + shell: bash + run: | + if [ ${{ inputs.run_setup_install }} == "1" ]; then + export WARDEN="$(dirname $(pwd))/warden/bin/warden" + ${WARDEN} env exec -T php-fpm php bin/magento + else + echo "Skipping php bin/magento test command" + fi