Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade auto tests #51

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/actions/archive-shop/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Archive shop
description: Archive shop to share with future jobs, the action exports sources sql and xml checksum (optional)
inputs:
ps_dir:
description: Directory target
required: true
db_user:
description: DB user
required: true
db_password:
description: DB password
required: true
db_name:
description: DB name
required: true
artifact_name:
description: Artifact name, used later for download
required: false
default: shop-artifacts

runs:
using: "composite"
steps:
- name: Archive shop content
env:
DOCKER_PREFIX: ${{ inputs.ps_dir }}
run: |
mkdir -p /tmp/${{ inputs.artifact_name }}
pushd ${{ inputs.ps_dir }}; zip -q -r /tmp/${{ inputs.artifact_name }}/sources.zip . -x \
"admin-dev/themes/new-theme/node_modules/**/*" \
"admin-dev/themes/default/node_modules/**/*" \
"themes/classic/_dev/**/*" \
"themes/_core/**/*" \
"themes/node_modules/**/*" \
"install-dev/**/*" \
"translations/*.zip" \
"var/cache/**/*" \
"tests/Integration/**/*" \
"tests/Resources/**/*" \
"tests/Unit/**/*" \
"modules/autoupgrade/download/*" \
".git/**/*"; popd
docker exec ${{ env.DOCKER_PREFIX }}_mysql_1 /usr/bin/mysqldump -u ${{ inputs.db_user }} -p${{ inputs.db_password }} ${{ inputs.db_name }} > /tmp/${{ inputs.artifact_name }}/db_dump.sql
shell: bash

- name: Upload shop artifacts "${{ inputs.artifact_name }}"
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.artifact_name }}
path: /tmp/${{ inputs.artifact_name }}
31 changes: 31 additions & 0 deletions .github/workflows/actions/archive-shop/download/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Download archive shop
description: Download archive shop and extracts it to the specified folder
inputs:
target_folder:
description: Target folder for extraction
required: true
artifact_name:
description: Artifact name, used later for download
required: false
default: shop-artifacts
outputs:
source-path:
description: Path to the sources zip file
value: /tmp/${{ inputs.artifact_name }}/sources.zip
db-dump-path:
description: Path to the sources zip file
value: /tmp/${{ inputs.artifact_name }}/db_dump.sql

runs:
using: "composite"
steps:
- name: Download docker artifacts
uses: actions/download-artifact@v3
with:
name: ${{ inputs.artifact_name }}
path: /tmp/${{ inputs.artifact_name }}

- name: Extract PrestaShop sources
run: |
unzip /tmp/${{ inputs.artifact_name }}/sources.zip -d ${{ inputs.target_folder }}
shell: bash
50 changes: 34 additions & 16 deletions .github/workflows/actions/checkout-prestashop/action.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: Checkout PrestaShop and prepare config
description: Checkout PrestaShop and prepare config
inputs:
pr_number:
description: Pull request Id
repository_ref:
description: Base branch/ref from the repository
required: true
base_branch:
description: Base branch to rebase the PR
ps_dir:
description: Directory target
required: true
pr_number:
description: Pull request Id
required: false
rebase_or_merge:
required: true
required: false
description: Rebase or merge the pull request
backoffice_layout:
description: Backoffice layout
required: true
ps_dir:
description: Directory target
required: true
required: false

runs:
using: "composite"
Expand All @@ -37,6 +37,7 @@ runs:

# Get the PR
- name: Get pull request
if: inputs.pr_number != ''
working-directory: ${{ inputs.ps_dir }}
run: |
git fetch origin pull/${{ inputs.pr_number }}/head:pr${{ inputs.pr_number }}
Expand All @@ -45,23 +46,32 @@ runs:

- name: Rebase
working-directory: ${{ inputs.ps_dir }}
if: ${{ inputs.rebase_or_merge == 'rebase' }}
if: inputs.pr_number != '' && inputs.rebase_or_merge == 'rebase'
run: |
git fetch origin ${{ inputs.base_branch }}:${{ inputs.base_branch }}
git rebase origin/${{ inputs.base_branch }}
git fetch origin ${{ inputs.repository_ref }}:${{ inputs.repository_ref }}
git rebase origin/${{ inputs.repository_ref }}
shell: bash

- name: Merge
working-directory: ${{ inputs.ps_dir }}
if: ${{ inputs.rebase_or_merge == 'merge' }}
if: inputs.pr_number != '' && inputs.rebase_or_merge == 'merge'
run: |
git fetch origin ${{ inputs.base_branch }}:${{ inputs.base_branch }}
git merge origin/${{ inputs.base_branch }}
git fetch origin ${{ inputs.repository_ref }}:${{ inputs.repository_ref }}
git merge origin/${{ inputs.repository_ref }}
shell: bash

# Or simply get the branch/tag
- name: Get ref from repository ${{ inputs.repository_ref }}
if: inputs.pr_number == '' && inputs.repository_ref != 'develop'
working-directory: ${{ inputs.ps_dir }}
run: |
git fetch origin ${{ inputs.repository_ref }}:${{ inputs.repository_ref }}
git checkout ${{ inputs.repository_ref }}
shell: bash

# Workaround until https://github.com/PrestaShop/PrestaShop/issues/29813 is fixed
- name: PrestaShop Configuration (Copy of Config API)
if: (inputs.base_branch == '8.1.x') || (inputs.base_branch == 'develop')
if: startsWith(inputs.repository_ref, '8.1') || (inputs.repository_ref == 'develop')
run: cp ./${{ inputs.ps_dir }}/app/config/security_test.yml ./${{ inputs.ps_dir }}/app/config/security_prod.yml
shell: bash

Expand All @@ -71,3 +81,11 @@ runs:
run: |
echo PS_FF_SYMFONY_LAYOUT=true >> .env
shell: bash

# In old versions the docker configuration is not adapted to our test workflow, it may even not exist So it is forcefully overridden
- name: Override Docker configuration
if: startsWith(inputs.repository_ref, '1.7') || startsWith(inputs.repository_ref, '8.0')
run: |
cp -R ./custom_actions/docker-reference/.docker ${{ inputs.ps_dir }}
cp ./custom_actions/docker-reference/docker-compose.yml ${{ inputs.ps_dir }}
shell: bash
41 changes: 41 additions & 0 deletions .github/workflows/actions/export-docker-logs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Export docker logs
description: Export docker logs
inputs:
ps_dir:
description: Directory target
required: true
artifact_name:
description: Artifact name, used later for download
required: false
default: export-error-logs

runs:
using: "composite"
steps:
- name: Export docker logs
env:
DOCKER_PREFIX: ${{ inputs.ps_dir }}
working-directory: ${{ inputs.ps_dir }}
run: |
mkdir -p ./var/docker-logs
docker-compose logs --tail="all" &> ./var/docker-logs/docker-compose.log
if docker ps | grep ${{ env.DOCKER_PREFIX }}_prestashop-git_1; then
echo Export prestashop logs
docker logs ${{ env.DOCKER_PREFIX }}_prestashop-git_1 &> ./var/docker-logs/prestashop.log
fi
if docker ps | grep ${{ env.DOCKER_PREFIX }}_mysql_1; then
echo Export mysql logs
docker logs ${{ env.DOCKER_PREFIX }}_mysql_1 &> ./var/docker-logs/mysql.log
fi
if docker images | grep ${{ env.DOCKER_PREFIX }}_keycloak_1; then
echo Export keycloak logs
docker logs ${{ env.DOCKER_PREFIX }}_keycloak_1 &> ./var/docker-logs/keycloak.log
fi
shell: bash
- name: Save logs in case of error
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.artifact_name }}-errors-log
path: |
${{ inputs.ps_dir }}/var/logs
${{ inputs.ps_dir }}/var/docker-logs
62 changes: 62 additions & 0 deletions .github/workflows/actions/prepare-build-settings/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Prepare build settings dynamically
description: Some environment variables are a bit complex to specify and can not be set with simple native functions from GA so we use this action to define them
inputs:
repository_ref:
description: Base branch/ref from the repository
required: true
php_version:
description: PHP version
required: true
outputs:
php-version:
description: PHP version to use
value: ${{ steps.build-settings.outputs.php-version }}
node-version:
description: Node version to use
value: ${{ steps.build-settings.outputs.node-version }}

runs:
using: "composite"
steps:
- name: Prepare build settings
id: build-settings
run: |
function version { printf "%03d%03d%03d%03d" $(echo "$1" | sed s/x/999/ | tr '.' ' '); }
repositoryRef=${{ inputs.repository_ref == 'develop' && 9.0 || inputs.repository_ref }}
if [ $(version $repositoryRef) -lt $(version 1.7.7) ]; then
echo Version under 1.7.7 use Node 8
nodeVersion=8
elif [ $(version $repositoryRef) -le $(version 1.7.7.x) ]; then
echo Version 1.7.7 uses Node 10
nodeVersion=10
elif [ $(version $repositoryRef) -le $(version 8.0.x) ]; then
echo Version 1.7.8 and 8.0 use Node 14
nodeVersion=14
else
echo Versions after 8.0 use Node 16
nodeVersion=16
fi
echo "node-version=$nodeVersion" >> $GITHUB_OUTPUT

phpVersion=${{ inputs.php_version }}
if [ $(version $repositoryRef) -le $(version 1.7.4.x) ] && [ $(version $phpVersion) -gt $(version 7.1.x) ]; then
echo Max PHP version for PrestaShop lower than 1.7.4 is 7.1
phpVersion=7.1
elif [ $(version $repositoryRef) -le $(version 1.7.6.x) ] && [ $(version $phpVersion) -gt $(version 7.2.x) ]; then
echo Max PHP version for PrestaShop 1.7.5 and 1.7.6 is 7.2
phpVersion=7.2
elif [ $(version $repositoryRef) -le $(version 1.7.7.x) ] && [ $(version $phpVersion) -gt $(version 7.3.x) ]; then
echo Max PHP version for PrestaShop 1.7.7 is 7.3
phpVersion=7.3
elif [ $(version $repositoryRef) -le $(version 1.7.8.x) ] && [ $(version $phpVersion) -gt $(version 7.4.x) ]; then
echo Max PHP version for PrestaShop 1.7.8 is 7.4
phpVersion=7.4
elif [ $(version $repositoryRef) -le $(version 8.1.x) ] && [ $(version $phpVersion) -gt $(version 8.1.x) ]; then
echo Max PHP version for PrestaShop 8.0 and 8.1 is 8.1
phpVersion=8.1
else
echo Using PHP $phpVersion for PrestaShop $repositoryRef
fi

echo "php-version=$phpVersion" >> $GITHUB_OUTPUT
shell: bash
36 changes: 10 additions & 26 deletions .github/workflows/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Run UI tests
description: Run UI tests
inputs:
base_branch:
description: Base branch to rebase the PR
repository_ref:
description: Base branch/ref from the repository
required: true
ps_mode_dev:
description: Enable/Disable the developer mode
Expand Down Expand Up @@ -37,24 +37,23 @@ runs:
PS_DEV_MODE: ${{ fromJson(inputs.ps_mode_dev) && '1' || '0' }}
PHP_VERSION: ${{ inputs.php_version }}
NODE_VERSION: ${{ inputs.node_version }}
VERSION: ${{ inputs.php_version }}-apache
PS_DOMAIN: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'localhost:8001' || 'localhost:8002' }}
PS_ENABLE_SSL: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && '0' || '1' }}
ADMIN_PASSWD: ${{ (inputs.base_branch == '1.7.8.x') && 'prestashop_demo' || 'Correct Horse Battery Staple' }}
VERSION: ${{ format('{0}{1}', inputs.php_version, '-apache') }}
PS_DOMAIN: ${{ (startsWith(inputs.repository_ref, '8.0') || startsWith(inputs.repository_ref, '1.7')) && 'localhost:8001' || 'localhost:8002' }}
PS_ENABLE_SSL: ${{ (startsWith(inputs.repository_ref, '8.0') || startsWith(inputs.repository_ref, '1.7')) && '0' || '1' }}
ADMIN_PASSWD: ${{ startsWith(inputs.repository_ref, '1.7') && 'prestashop_demo' || 'Correct Horse Battery Staple' }}
# Fixed values
DB_USER: root
DB_PASSWD: prestashop
DB_NAME: prestashop
DB_PREFIX: tst_
DB_SERVER: mysql
PS_DIR: 'my_prestashop'
PS_FOLDER_INSTALL: install-dev
PS_FOLDER_ADMIN: admin-dev
PS_COUNTRY: fr
PS_LANGUAGE: en
ADMIN_MAIL: '[email protected]'
# Test variables
URL_FO: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }}
URL_FO: ${{ (startsWith(inputs.repository_ref, '8.0') || startsWith(inputs.repository_ref, '1.7')) && 'http://localhost:8001/' || 'https://localhost:8002/' }}
HEADLESS: true
ENABLE_SSL: true
TAKE_SCREENSHOT_AFTER_FAIL: true
Expand All @@ -69,26 +68,11 @@ runs:
if: failure()
shell: bash

- name: Export docker logs
run: |
mkdir -p ${{ inputs.ps_dir }}/var/docker-logs
docker logs my_prestashop_mysql_1 > ${{ inputs.ps_dir }}/var/docker-logs/mysql.log
docker logs my_prestashop_prestashop-git_1 > ${{ inputs.ps_dir }}/var/docker-logs/prestashop.log
if: failure()
shell: bash

- name: Export docker keycloak logs
run: |
docker logs my_prestashop_keycloak_1 > ${{ inputs.ps_dir }}/var/docker-logs/keycloak.log
if: failure() && inputs.test_command == 'functional:API'
shell: bash

- name: Export logs and screenshots as artifacts
# Export screenshots in case of failure
- name: Export screenshots as artifacts
uses: actions/upload-artifact@v3
if: failure()
with:
name: campaign-${{ steps.screenshot-campaign.outputs.screenshot-campaign }}
name: screenshots-campaign-${{ steps.screenshot-campaign.outputs.screenshot-campaign }}
path: |
${{ inputs.ps_dir }}/tests/UI/screenshots/
${{ inputs.ps_dir }}/var/logs
${{ inputs.ps_dir }}/var/docker-logs
Loading