Skip to content

Commit

Permalink
TC-47 Add cypress e2e test for GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Jan 14, 2025
1 parent c9dfe63 commit 5538da5
Show file tree
Hide file tree
Showing 10 changed files with 1,859 additions and 2 deletions.
110 changes: 110 additions & 0 deletions .github/oxid-esales/cypress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

set -e # Exit on error
echo "Current directory: $(pwd)"
# Function to check if docker-compose.yml exists
check_docker_compose_file() {
if [ ! -f docker-compose.yml ]; then
echo "Error: docker-compose.yml not found in current directory"
exit 1
fi
}

# Function to check if docker compose is installed
check_docker_compose() {
if ! command -v docker compose &> /dev/null; then
echo "Error: docker compose is not installed"
exit 1
fi
}

# Stop running containers and remove networks
echo "Stopping running containers..."
docker compose down --remove-orphans || {
echo "Error stopping containers"
exit 1
}

# Check prerequisites
check_docker_compose_file
check_docker_compose

# Create backup of original docker-compose.yml
echo "Creating backup of docker-compose.yml..."
cp docker-compose.yml docker-compose.yml.backup

# Remove selenium service from docker-compose.yml
echo "Removing selenium service..."
sed -i '/^ selenium:/,/^ [a-z]/d' docker-compose.yml

# Add cypress service to docker-compose.yml
echo "Adding cypress service..."
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
echo "Script directory: $SCRIPT_DIR"
cat <<EOF >> docker-compose.yml
cypress:
image: cypress/included:latest
working_dir: /var/www/vendor/oxid-solution-catalysts/telecash-module/tests/e2e
volumes:
- ./source/vendor/oxid-solution-catalysts/telecash-module:/var/www/vendor/oxid-solution-catalysts/telecash-module:cached
- /tmp/.X11-unix:/tmp/.X11-unix
environment:
- CYPRESS_baseUrl=http://apache
ports:
- "5900:5900" # VNC port
networks:
- default
extra_hosts:
- "oxideshop.local:172.17.0.1" # Docker host IP
command: cypress run
depends_on:
apache:
condition: service_started
mysql:
condition: service_healthy
entrypoint: [ "npx", "cypress", "run", "--config-file", "/var/www/vendor/oxid-solution-catalysts/telecash-module/tests/e2e/cypress.config.js" ]
networks:
default:
driver: bridge
EOF

# Check if port 5900 is already in use
echo "Checking if port 5900 is available..."
if lsof -i :5900 >/dev/null 2>&1; then
echo "Warning: Port 5900 is already in use. You may need to free this port before proceeding."
sudo lsof -i :5900
read -p "Do you want to continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi


# Start Docker containers
echo "Starting Docker containers..."
docker compose up -d || {
echo "Error starting containers. Checking container status..."
docker compose ps
echo "Container logs:"
docker compose logs
echo "Restoring backup..."
cp docker-compose.yml.backup docker-compose.yml
exit 1
}
EXIT_CODE=$?

# Wait for containers to be healthy
echo "Waiting for containers to be healthy..."
sleep 20

# Display Cypress logs
echo "Displaying Cypress logs..."
docker compose logs cypress


sleep 30
docker compose logs cypress

exit $EXIT_CODE
128 changes: 128 additions & 0 deletions .github/oxid-esales/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/bash
# shellcheck disable=SC2154
# Lower case environment variables are passed from the workflow and used here
# We use a validation loop in init to ensure, they're set
# shellcheck disable=SC2086
# We want install_container_options to count as multiple arguments
set -e

function error() {
echo -e "\033[0;31m${1}\033[0m"
exit 1
}

function init() {
for VAR in install_container_method install_container_options install_container_name \
install_config_idebug install_is_enterprise; do
echo -n "Checking, if $VAR is set ..."
if [ -z ${VAR+x} ]; then
error "Variable '${VAR}' not set"
fi
echo "OK, ${VAR}='${!VAR}'"
done
echo -n "Locating oe-console ... "
cd source || exit 1
if [ -f 'bin/oe-console' ]; then
OE_CONSOLE='bin/oe-console'
else
if [ -f 'vendor/bin/oe-console' ]; then
OE_CONSOLE='vendor/bin/oe-console'
else
error "Can't find oe-console in bin or vendor/bin!"
fi
fi
echo "OK, using '${OE_CONSOLE}'"
if [ -z "${OXID_BUILD_DIRECTORY}" ]; then
echo "OXID_BUILD_DIRECTORY is not set, setting it to /var/www/source/tmp"
export OXID_BUILD_DIRECTORY="/var/www/source/tmp"
else
echo "OXID_BUILD_DIRECTORY is set to '${OXID_BUILD_DIRECTORY}'"
fi
if [ ! -d "${OXID_BUILD_DIRECTORY/\/var\/www/source}" ]; then
echo "Creating '${OXID_BUILD_DIRECTORY}'"
docker compose "${install_container_method}" -T \
${install_container_options} \
"${install_container_name}" \
mkdir -p "${OXID_BUILD_DIRECTORY}"
fi
}

init
# Run Install Shop
docker compose "${install_container_method}" -T \
${install_container_options} \
"${install_container_name}" \
${OE_CONSOLE} oe:setup:shop \
--db-host mysql \
--db-port 3306 \
--db-name example \
--db-user root \
--db-password root \
--shop-url http://oxidshop.local/ \
--shop-directory /var/www/source \
--compile-directory "${OXID_BUILD_DIRECTORY}"

if [ -e vendor/oxid-esales/oxideshop-ce ]; then
# Handle copying of the config
if [ -f source/config.inc.php.dist ] && [ -f source/config.inc.php ]; then
if diff -q source/config.inc.php.dist source/config.inc.php; then
echo "source/config.inc.php has not been modified"
TARGET=source/config.inc.php
else
echo "Config file is source/config.inc.php"
CONFIG_FILE=source/config.inc.php
fi
else
echo "source/config.inc.php does not exist"
TARGET=source/config.inc.php
fi
if [ -f vendor/oxid-esales/oxideshop-ce/source/config.inc.php.dist ] && [ -f vendor/oxid-esales/oxideshop-ce/source/config.inc.php ]; then
if diff -q vendor/oxid-esales/oxideshop-ce/source/config.inc.php.dist vendor/oxid-esales/oxideshop-ce/source/config.inc.php; then
echo "vendor/oxid-esales/oxideshop-ce/source/config.inc.php has not been modified"
if [ -n "${TARGET}" ]; then
echo "ERROR: Neither source/config.inc.php nor vendor/oxid-esales/oxideshop-ce/source/config.inc.php have been updated"
exit 1
fi
TARGET=vendor/oxid-esales/oxideshop-ce/source/config.inc.php
else
if [ -n "${CONFIG_FILE}" ]; then
echo "ERROR: Both source/config.inc.php and vendor/oxid-esales/oxideshop-ce/source/config.inc.php have been updated"
exit 1
fi
echo "Config file is vendor/oxid-esales/oxideshop-ce/source/config.inc.php"
CONFIG_FILE=vendor/oxid-esales/oxideshop-ce/source/config.inc.php
fi
else
if [ -n "${TARGET}" ]; then
echo "ERROR: Neither vendor/oxid-esales/oxideshop-ce/source/config.inc.php nor source/config.inc.php have been updated"
exit 1
fi
TARGET=source/config.inc.php
fi
cp "${CONFIG_FILE}" "${TARGET}"
else
echo "vendor/oxid-esales/oxideshop-ce does not exist, assuming conventional shop install"
fi

# Activate iDebug
if [ "${install_config_idebug}" == 'true' ]; then
if [ -f source/source/config.inc.php ]; then
perl -pi -e 's#iDebug = 0;#iDebug = -1;#g;' source/source/config.inc.php
fi
if [ -f source/vendor/oxid-esales/oxideshop-ce/source/config.inc.php ]; then
perl -pi -e 's#iDebug = 0;#iDebug = -1;#g;' source/vendor/oxid-esales/oxideshop-ce/source/config.inc.php
fi
fi

# Activate theme
docker compose "${install_container_method}" -T \
${install_container_options} \
"${install_container_name}" \
${OE_CONSOLE} oe:theme:activate apex

# Output PHP error log
if [ -s data/php/logs/error_log.txt ]; then
echo -e "\033[0;35mPHP error log\033[0m"
cat data/php/logs/error_log.txt
fi
exit 0
5 changes: 5 additions & 0 deletions .github/oxid-esales/telecash_module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ runslim:
"osc_telecash:phpstan-report"
]
cypress:
osc_telecash:
path: 'vendor/oxid-solution-catalysts/telecash-module'
custom_script: '$(pwd)/source/vendor/oxid-solution-catalysts/telecash-module/.github/oxid-esales/cypress.sh'

sonarcloud:
matrix:
testplan: '["-"]'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
osc_telecash_php82_mysql_80:
uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4
uses: ./.github/workflows/universal_workflow_light.yaml
with:
testplan: '~/defaults/7.1.x.yaml,~/defaults/php8.1_mysql8.0_only.yaml,~/telecash_module.yaml'
runs_on: '"ubuntu-latest"'
Expand Down
Loading

0 comments on commit 5538da5

Please sign in to comment.