diff --git a/.github/actions/e2e/action.yml b/.github/actions/e2e/action.yml new file mode 100644 index 00000000..0fa83b59 --- /dev/null +++ b/.github/actions/e2e/action.yml @@ -0,0 +1,84 @@ +--- +name: 'e2e tests' + +description: '' +inputs: + ps-version: + description: Prestashop version + required: true + php-version: + description: Php version + required: true + node-builder-version: + description: Node builder version + required: true + docker-compose-version: + description: Docker compose version + required: true + +runs: + using: composite + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + + - uses: pnpm/action-setup@v3 + with: + version: latest + + - uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-builder-version }} + cache: "pnpm" + cache-dependency-path: e2e/pnpm-lock.yaml + + - name: Cache vendor folder + uses: actions/cache@v3 + with: + path: vendor + key: php-${{ hashFiles('composer.lock') }} + + - name: Install docker compose + shell: bash + run: | + DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} + mkdir -p $DOCKER_CONFIG/cli-plugins + rm -f $DOCKER_CONFIG/cli-plugins/docker-compose + curl -SL https://github.com/docker/compose/releases/download/${{ inputs.docker-compose-version }}/docker-compose-linux-x86_64 \ + -o $DOCKER_CONFIG/cli-plugins/docker-compose + chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose + + - name: Install dependencies and setup e2e + shell: bash + run: pnpm install --no-optional --force + working-directory: e2e + + - name: Setup e2e-env with Prestashop ${{ inputs.ps-version }} & Php ${{ inputs.php-version }} + shell: bash + run: | + FLASHLIGHT_BASE_IMAGE="prestashop/prestashop-flashlight" + if [[ "${{ inputs.ps-version }}" != "latest" ]]; then + sed -i 's+${FLASHLIGHT_BASE_IMAGE}:latest/${FLASHLIGHT_BASE_IMAGE}:${{inputs.ps-version}}-${{inputs.php-version}}/g' .env.dist + fi; + cp .env.dist .env + docker compose build + docker compose up --detach --wait + working-directory: e2e-env + + - name: Run e2e:tests with Prestashop ${{ inputs.ps-version }} & Php ${{ inputs.php-version }} + shell: bash + run: pnpm test:e2e + working-directory: e2e + + - name: More logs on failure + shell: bash + if: failure() + run: | + echo "========= Shop healthcheck ==============" + curl -s -L 'http://localhost:8000/index.php?fc=module&module=ps_eventbus&controller=apiHealthCheck' | jq . + echo "========= Containers logs ==========" + docker compose logs cloudsync-mock prestashop + docker compose down -v + working-directory: e2e-env diff --git a/.github/workflows/e2e-pr.yml b/.github/workflows/e2e-pr.yml new file mode 100644 index 00000000..b9adf6d9 --- /dev/null +++ b/.github/workflows/e2e-pr.yml @@ -0,0 +1,116 @@ +name: E2e PR + +on: + workflow_call: + inputs: + ps-version: + description: 'Prestashop version (if latest no Php version needed).' + type: string + required: false + default: latest + php-version: + description: 'Php version' + type: string + required: false + default: 8.1 + workflow_dispatch: + inputs: + ps-version: + description: 'Prestashop version (if latest no Php version needed) \n + Compatibility: \n + ps8.x.x with php 8.1, 8.0, 7.4, 7.3, 7.2, 7.1 \n + ps1.7.8.x with 7.4, 7.3, 7.2, 7.1 \n + ps1.7.7.x with 7.3, 7.2, 7.1 \n + ps1.7.5.x & ps1.7.6.x with php 7.2, 7.1, 7.0 \n + ps1.7.0.x to ps1.7.4.x with php 7.1, 7.0 + ps1.6.1.x with php 7.1, 7.0, 5.6, 5.5, 5.4, 5.3, 5.2' + default: 'latest' + type: choice + options: + - latest + - 8.1.7 + - 8.0.5 + - 1.7.8.11 + - 1.7.7.8 + - 1.7.6.9 + - 1.7.5.2 + - 1.7.4.4 + - 1.7.3.4 + - 1.7.2.5 + - 1.7.1.2 + - 1.7.0.6 + - 1.6.1.24 + php-version: + description: 'Php version' + default: '8.1' + type: choice + options: + - 8.1 + - 8.0 + - 7.4 + - 7.3 + - 7.2 + - 7.1 + - 7.0 + - 5.6 + - 5.5 + - 5.4 + - 5.3 + - 5.2 + +env: + DOCKER_COMPOSE_VERSION: v2.27.0 + NODE_BUILDER_VERSION: "20" + +jobs: + e2e-tests: + name: E2E Tests + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v3 + with: + version: latest + + - name: Auth Docker GCP + uses: ./.github/actions/auth-docker-gcp + with: + workload-identity-provider: ${{ secrets.WI_PROVIDER_INTEGRATION }} + service-account: ${{ secrets.WI_SA_INTEGRATION }} + + - name: e2e tests + uses: ./.github/actions/e2e + with: + ps-version: ${{ inputs.ps-version }} + php-version: ${{ inputs.php-version }} + docker-compose-version: ${{ env.DOCKER_COMPOSE_VERSION }} + node-builder-version: ${{ env.NODE_BUILDER_VERSION }} + + - name: Slack notification on failures + if: github.event_name == 'schedule' && failure() + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_COLOR: EC1111 + SLACK_TITLE: E2E Capture tests PS$${{ inputs.ps-version }} & Php${{ inputs.php-version }} + SLACK_MESSAGE: The latest E2E Capture tests failed :( + SLACK_FOOTER: 'Review the last github actions here: https://github.com/PrestaShopCorp/cloudsync/actions/workflows/e2e.yml' + SLACK_USERNAME: QABot + SLACK_CHANNEL: squad-cloudsync-qa + SLACK_ICON: https://avatars.githubusercontent.com/u/56089550?s=48&v=4 + + - name: Slack notification on success + if: github.event_name == 'schedule' && success() + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_COLOR: 0CAD34 + SLACK_TITLE: E2E Capture tests PS${{ matrix.ps-version }} & Php${{ matrix.php-version }} + SLACK_MESSAGE: ✓ The latest E2E Capture tests just passed! + SLACK_FOOTER: '' + SLACK_USERNAME: QABot + SLACK_CHANNEL: squad-cloudsync-qa + SLACK_ICON: https://avatars.githubusercontent.com/u/56089550?s=48&v=4 diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 00000000..d6d6b649 --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,87 @@ +name: E2e + +env: + DOCKER_COMPOSE_VERSION: v2.27.0 + NODE_BUILDER_VERSION: "20" + +jobs: + e2e-tests: + name: E2E Tests + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + include: + - ps-version: 8.1.7 + php-version: 8.2 + - ps-version: 8.0.5 + php-version: 8.2 + - ps-version: 1.7.8.11 + php-version: 7.4 + - ps-version: 1.7.7.8 + php-version: 7.3 + - ps-version: 1.7.6.9 + php-version: 7.2 + - ps-version: 1.7.5.2 + php-version: 7.2 + - ps-version: 1.7.4.4 + php-version: 7.1 + - ps-version: 1.7.3.4 + php-version: 7.1 + - ps-version: 1.7.2.5 + php-version: 7.1 + - ps-version: 1.7.1.2 + php-version: 7.1 + - ps-version: 1.7.0.6 + php-version: 7.1 + - ps-version: 1.6.1.24 + php-version: 7.1 + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v3 + with: + version: latest + + - name: Auth Docker GCP + uses: ./.github/actions/auth-docker-gcp + with: + workload-identity-provider: ${{ secrets.WI_PROVIDER_INTEGRATION }} + service-account: ${{ secrets.WI_SA_INTEGRATION }} + + - name: e2e tests + uses: ./.github/actions/e2e + with: + ps-version: ${{ matrix.ps-version }} + php-version: ${{ matrix.php-version }} + docker-compose-version: ${{ env.DOCKER_COMPOSE_VERSION }} + node-builder-version: ${{ env.NODE_BUILDER_VERSION }} + + - name: Slack notification on failures + if: github.event_name == 'schedule' && failure() + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_COLOR: EC1111 + SLACK_TITLE: E2E Capture tests PS${{ matrix.ps-version }} & Php${{ matrix.php-version }} + SLACK_MESSAGE: The latest E2E Capture tests failed :( + SLACK_FOOTER: 'Review the last github actions here: https://github.com/PrestaShopCorp/cloudsync/actions/workflows/e2e.yml' + SLACK_USERNAME: QABot + SLACK_CHANNEL: squad-cloudsync-qa + SLACK_ICON: https://avatars.githubusercontent.com/u/56089550?s=48&v=4 + + - name: Slack notification on success + if: github.event_name == 'schedule' && success() + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_COLOR: 0CAD34 + SLACK_TITLE: E2E Capture tests PS${{ matrix.ps-version }} & Php${{ matrix.php-version }} + SLACK_MESSAGE: ✓ The latest E2E Capture tests just passed! + SLACK_FOOTER: '' + SLACK_USERNAME: QABot + SLACK_CHANNEL: squad-cloudsync-qa + SLACK_ICON: https://avatars.githubusercontent.com/u/56089550?s=48&v=4 diff --git a/e2e-env/.env.dist b/e2e-env/.env.dist index b99b0ede..116f0bfe 100644 --- a/e2e-env/.env.dist +++ b/e2e-env/.env.dist @@ -4,6 +4,10 @@ COMPOSE_PROJECT_NAME=ps_eventbus DOCKER_IMAGE_PRESTASHOP=prestashop/prestashop-flashlight:latest DOCKER_VERSION_MARIADB=lts +# e2e test dataset : default uses dataset from prestashop flashlight docker image, uses dataset from dataset +# folder otherwise +TEST_DATASET=default + # Infrastructure port binding on the host HOST_PORT_BIND_PRESTASHOP=8000 HOST_PORT_BIND_MYSQL=3306 @@ -14,3 +18,6 @@ SYNC_API_PORT=3232 COLLECTOR_API_PORT=3333 LIVE_SYNC_API_PORT=3434 WS_PORT=8080 + +PS_EVENTBUS_VERSION=v3.0.12 +PS_ACCOUNTS_MOCK_VERSION=v1.0.4 diff --git a/e2e-env/docker-compose.yml b/e2e-env/docker-compose.yml index 32721fdd..f8148674 100644 --- a/e2e-env/docker-compose.yml +++ b/e2e-env/docker-compose.yml @@ -1,6 +1,7 @@ services: prestashop: image: ${DOCKER_IMAGE_PRESTASHOP:?See e2e-env/.env.dist} + container_name: prestashop depends_on: mysql: condition: service_healthy @@ -33,8 +34,9 @@ services: mysql: image: mariadb:${DOCKER_VERSION_MARIADB:?See e2e-env/.env.dist} + container_name: mysql healthcheck: - test: ["CMD", "healthcheck.sh", "--connect"] + test: [ "CMD", "healthcheck.sh", "--connect" ] environment: - MYSQL_HOST=mysql - MYSQL_USER=prestashop @@ -49,6 +51,7 @@ services: phpmyadmin: image: phpmyadmin:latest + container_name: phpmyadmin depends_on: mysql: condition: service_healthy @@ -67,10 +70,11 @@ services: build: context: ./cloudsync-mock dockerfile: Dockerfile + container_name: cloudsync-mock environment: - RUN_IN_DOCKER=1 healthcheck: - test: ["CMD", "curl", "-sI", "http://localhost:8080"] + test: [ "CMD", "curl", "-sI", "http://localhost:8080" ] volumes: - ./cloudsync-mock/src:/home/node/src:ro ports: @@ -83,11 +87,12 @@ services: reverse-proxy: image: nginx:stable-alpine + container_name: reverse-proxy healthcheck: - test: ["CMD", "curl", "-sI", "http://localhost:80/nginx_status"] + test: [ "CMD", "curl", "-sI", "http://localhost:80/nginx_status" ] volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro,cached - command: [nginx-debug, "-g", "daemon off;"] + command: [ nginx-debug, "-g", "daemon off;" ] networks: - prestashop ports: diff --git a/e2e-env/init-scripts/1-install_ps_eventbus.sh b/e2e-env/init-scripts/1-install_ps_eventbus.sh new file mode 100755 index 00000000..e90cd166 --- /dev/null +++ b/e2e-env/init-scripts/1-install_ps_eventbus.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -eu +cd "$(dirname $0)" || exit 1 + +# Download and install the module's zip +echo "* [ps_eventbus] downloading..." +wget -q -O /tmp/ps_eventbus.zip "https://github.com/PrestaShopCorp/ps_eventbus/releases/download/${PS_EVENTBUS_VERSION}/ps_eventbus-${PS_EVENTBUS_VERSION}.zip" +echo "* [ps_eventbus] unziping..." +unzip -qq /tmp/ps_eventbus.zip -d /var/www/html/modules +echo "* [ps_eventbus] installing the module..." +cd "$PS_FOLDER" +php -d memory_limit=-1 bin/console prestashop:module --no-interaction install "ps_eventbus" + +# Override the default parameters with the E2E settings +wget -O "/var/www/html/modules/ps_eventbus/config/parameters.yml" \ + "https://raw.githubusercontent.com/PrestaShopCorp/ps_eventbus/main/config/parameters.yml" diff --git a/e2e-env/init-scripts/2-install_ps_accounts.sh b/e2e-env/init-scripts/2-install_ps_accounts.sh new file mode 100755 index 00000000..2b1180f6 --- /dev/null +++ b/e2e-env/init-scripts/2-install_ps_accounts.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -eu +cd "$(dirname $0)" || exit 1 + +echo "* [ps_accounts_mock] downloading..." +echo "https://github.com/PrestaShopCorp/ps_accounts_mock/releases/download/${PS_ACCOUNTS_MOCK_VERSION}/ps_accounts_mock-${PS_ACCOUNTS_MOCK_VERSION}.zip" +wget -q -O /tmp/ps_accounts.zip "https://github.com/PrestaShopCorp/ps_accounts_mock/releases/download/${PS_ACCOUNTS_MOCK_VERSION}/ps_accounts_mock-${PS_ACCOUNTS_MOCK_VERSION}.zip" +echo "* [ps_accounts_mock] unziping..." +unzip -qq /tmp/ps_accounts.zip -d /var/www/html/modules +echo "* [ps_accounts_mock] installing the module..." +cd "$PS_FOLDER" +php -d memory_limit=-1 bin/console prestashop:module --no-interaction install "ps_accounts"