Skip to content

Split shop building in independent single job for optimization #1

Split shop building in independent single job for optimization

Split shop building in independent single job for optimization #1

Workflow file for this run

name: Run UI tests with pre-built shop
on:
workflow_call:
inputs:
base_branch:
type: string
description: Base branch to rebase the PR
required: true
ps_mode_dev:
type: boolean
description: Enable/Disable the developer mode
required: true
php_version:
type: string
description: PHP version
required: true
node_version:
type: string
description: Node version
required: true
test_command:
type: string
description: Test command to run
required: true
testing-pr:
runs-on: ubuntu-latest
name: Run UI Tests ${{ github.event.inputs.test_command }}
env:
# Input values
BASE_BRANCH: ${{ github.event.inputs.base_branch }}
PS_MODE_DEV: ${{ github.event.inputs.ps_mode_dev }}
PHP_VERSION: ${{ github.event.inputs.php_version }}
NODE_VERSION: ${{ github.event.inputs.node_version }}
VERSION: ${{ github.event.inputs.php_version }}-apache
PS_DOMAIN: ${{ ((github.event.inputs.base_branch == '8.0.x') || (github.event.inputs.base_branch == '1.7.8.x')) && 'localhost:8001' || 'localhost:8002' }}
PS_DEV_MODE: ${{ github.event.inputs.ps_mode_dev == 'true' && '1' || '0' }}
PS_ENABLE_SSL: ${{ ((github.event.inputs.base_branch == '8.0.x') || (github.event.inputs.base_branch == '1.7.8.x')) && '0' || '1' }}
ADMIN_PASSWD: ${{ (github.event.inputs.base_branch == '1.7.8.x') && 'prestashop_demo' || 'Correct Horse Battery Staple' }}
# Fixed values
DB_USER: root
DB_PASSWD: prestashop
DB_NAME: prestashop
DB_PREFIX: tst_
PS_DIR: 'my_prestashop'
PS_FOLDER_INSTALL: install-dev
PS_FOLDER_ADMIN: admin-dev
PS_COUNTRY: fr
PS_LANGUAGE: en
ADMIN_MAIL: '[email protected]'
steps:
- name: Print Inputs values
shell: bash
run: echo "${{ toJSON(github.event.inputs) }}"
- name: Download docker artifacts
uses: actions/download-artifact@v3
with:
name: shop-artifacts
path: /tmp/shop-artifacts
- name: Extract PrestaShop sources
run: |
unzip -q /tmp/shop-artifacts/sources.zip -d .
# Certificate
- name: Generate a certificate
if: (github.event.inputs.base_branch == '8.1.x') || (github.event.inputs.base_branch == 'develop')
run: |
## Install MkCert
sudo apt install libnss3-tools
curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64"
chmod +x mkcert-v*-linux-amd64
sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert
## Generate certificate
mkcert -key-file ./${{ env.PS_DIR }}/.docker/ssl.key -cert-file ./${{ env.PS_DIR }}/.docker/ssl.crt localhost
## Link certificate to Chrome Trust Store
mkdir -p $HOME/.pki/nssdb
certutil -d $HOME/.pki/nssdb -N
certutil -d sql:$HOME/.pki/nssdb -n localhost -A -t "TCu,Cu,Tu" -i ./${{ env.PS_DIR }}/.docker/ssl.crt
## Add self-signed certificate to Chrome Trust Store
mkcert -install
- name: Setup database
working-directory: ${{ env.PS_DIR }}
timeout-minutes: 5
run: |
echo Starting mysql docker alone
USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose -f docker-compose.yml up -d --build mysql
echo Wait until mysql is accessible
until docker exec my_prestashop_mysql_1 /usr/bin/mysql -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }}; do echo "Sleep and retry to check"; sleep 5; done
echo Copying dump into docker
docker cp /tmp/shop-artifacts/db_dump.sql my_prestashop_mysql_1:/tmp/db_dump.sql
echo Creating ${{ env.DB_NAME }} database
docker exec my_prestashop_mysql_1 /usr/bin/mysql -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }} -e "CREATE DATABASE IF NOT EXISTS ${{ env.DB_NAME }};"
echo Load dump into DB
docker exec my_prestashop_mysql_1 /usr/bin/mysql -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }} ${{ env.DB_NAME }} -e "source /tmp/db_dump.sql;"
- name: Start up shop docker
working-directory: ${{ env.PS_DIR }}
timeout-minutes: 5
env:
VERSION: ${{ (github.event.inputs.base_branch == '1.7.8.x') && github.event.inputs.php_version || env.VERSION }}
URL_FO: ${{ ((github.event.inputs.base_branch == '8.0.x') || (github.event.inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }}
# No install we force the sources and load the SQL dump
PS_INSTALL_AUTO: 0
DISABLE_MAKE: 1
run: |
echo Build the remaining dockers
USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose -f docker-compose.yml up -d --build
echo Waiting for response from the FO
bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} ${{ env.URL_FO }}en/)" != "200" ]]; do sleep 5; done'
# UI Tests : Setup, Install & Execute
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '${{ env.PS_DIR }}/tests/UI/package-lock.json'
- name: Setup NPM
run: npm install -g npm@7
- name: Install tests dependencies
run: npm install
working-directory: '${{ env.PS_DIR }}/tests/UI'
- name: Run tests
id: runTests
run: |
export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"
npm run test:${{ github.event.inputs.test_command }}
working-directory: '${{ env.PS_DIR }}/tests/UI'
env:
URL_FO: ${{ ((github.event.inputs.base_branch == '8.0.x') || (github.event.inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }}
DB_NAME: prestashop
DB_PASSWD: prestashop
HEADLESS: true
ENABLE_SSL: true
TAKE_SCREENSHOT_AFTER_FAIL: true
SMTP_SERVER: '172.17.0.1'
# UI Tests : Upload screenshots
- run: echo "SCREENSHOT_CAMPAIGN=$( echo -e '${{ github.event.inputs.test_command }}' | tr ':' '-' )" >> $GITHUB_ENV
if: failure()
- name: Export docker logs
run: |
mkdir -p ${{ env.PS_DIR }}/var/docker-logs
docker logs my_prestashop_mysql_1 > ${{ env.PS_DIR }}/var/docker-logs/mysql.log
docker logs my_prestashop_prestashop-git_1 > ${{ env.PS_DIR }}/var/docker-logs/prestashop.log
docker logs my_prestashop_keycloak_1 > ${{ env.PS_DIR }}/var/docker-logs/keycloak.log
if: failure()
- name: Export logs and screenshots as artifacts
uses: actions/upload-artifact@v3
if: failure()
with:
name: campaign-${{ env.SCREENSHOT_CAMPAIGN }}
path: |
${{ env.PS_DIR }}/tests/UI/screenshots/
${{ env.PS_DIR }}/var/logs
${{ env.PS_DIR }}/var/docker-logs