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

Split shop building in independent single job for optimization #44

Merged
merged 37 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
776f430
Split docker building in independent single job for optimization
jolelievre Aug 17, 2023
95cea81
Split two tasks into separated callable workflows
jolelievre Aug 22, 2023
1cedbeb
Optimize node and cache composer
jolelievre Aug 23, 2023
f176539
Add option to fast fail
jolelievre Aug 24, 2023
1802193
Add new action to install and cache node modules with better cache
jolelievre Aug 24, 2023
b99f704
Optimize early saving of node cache, cache vendor
jolelievre Sep 13, 2023
b65a4b1
Split long and short campaigns to prioritize the longer ones
jolelievre Sep 13, 2023
da49846
Make an action for run test, sanity are handled individually
jolelievre Sep 13, 2023
824693e
Reorganize long and short campaigns
jolelievre Sep 13, 2023
35c1725
Only build keycloak when running UI tests, no need for the build or s…
jolelievre Sep 13, 2023
12c4c51
Clean excludes
jolelievre Sep 13, 2023
682ade4
Improve workflo parameters order
jolelievre Sep 13, 2023
9f44619
Remove keycloak optim
jolelievre Sep 13, 2023
b4bd66a
No keycloak service in sanity and in test that are not API
jolelievre Sep 14, 2023
82cf1b8
Fix node cache saving
jolelievre Sep 14, 2023
6fbb77d
Improve jobs naming
jolelievre Sep 14, 2023
16e3af3
Handle special case for sanity campaign in single workflow
jolelievre Sep 14, 2023
dbeb135
Build and fetch images early in background
jolelievre Sep 14, 2023
0fe20ca
Make artifact a bit smaller
jolelievre Sep 14, 2023
d985c57
Add system to check build is over
jolelievre Sep 15, 2023
512c50a
Try not to build keycloak
jolelievre Sep 16, 2023
9923490
Pull and build keycloak only when necessary
jolelievre Sep 16, 2023
c779a80
Optimize build tests for sanity, move building a step up with artifact
jolelievre Sep 16, 2023
55595cf
Split composer cache process to optimize end of process
jolelievre Sep 16, 2023
0d70b83
Fix composer cache
jolelievre Sep 16, 2023
52e7547
Fix test dependencies
jolelievre Sep 16, 2023
685f365
Optimize test dependencies installation along with playwright webkit …
jolelievre Sep 16, 2023
8e7c954
Install playwright in sanity as well
jolelievre Sep 16, 2023
5ea3ff3
Last comment
jolelievre Sep 16, 2023
6644f1e
Fix install javascript actions when one path has no build but cache i…
jolelievre Sep 16, 2023
3bf6bdb
Turn composer install into an action and use it in sanity as well
jolelievre Sep 16, 2023
6a94205
Remove build javascript action along with cache for node modules
jolelievre Sep 22, 2023
16d451d
Remove vendor folder cache
jolelievre Sep 22, 2023
43fa861
Fix docker logs export when keycloak is not built
jolelievre Sep 22, 2023
a2a1f90
Improve composer cache, regular cache action waste time on post actio…
jolelievre Sep 22, 2023
3404d2e
Anticipate cache for UI tests
jolelievre Sep 23, 2023
98c93cb
No more node cache at all
jolelievre Sep 23, 2023
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
65 changes: 65 additions & 0 deletions .github/workflows/actions/checkout-prestashop/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Checkout PrestaShop and prepare config
description: Checkout PrestaShop and prepare config
inputs:
pr_number:
description: Pull request Id
required: true
base_branch:
description: Base branch to rebase the PR
required: true
rebase_or_merge:
required: true
description: Rebase or merge the pull request
backoffice_layout:
description: Backoffice layout
required: true
ps_dir:
description: Directory target
required: true

runs:
using: "composite"
steps:
# Checkout PrestaShop
- uses: actions/checkout@v3
name: Checkout PrestaShop repository
with:
fetch-depth: 0
repository: PrestaShop/PrestaShop
path: ${{ inputs.ps_dir }}

- name: Config git
run: |
git config --local user.email "$(git log --format='%ae' HEAD^!)"
git config --local user.name "$(git log --format='%an' HEAD^!)"
working-directory: ${{ inputs.ps_dir }}
shell: bash

# Get the PR
- name: Get pull request
working-directory: ${{ inputs.ps_dir }}
run: |
git fetch origin pull/${{ inputs.pr_number }}/head:pr${{ inputs.pr_number }}
git checkout pr${{ inputs.pr_number }}
shell: bash

- name: Rebase
working-directory: ${{ inputs.ps_dir }}
if: ${{ inputs.rebase_or_merge == 'rebase' }}
run: |
git fetch origin ${{ inputs.base_branch }}:${{ inputs.base_branch }}
git rebase origin/${{ inputs.base_branch }}
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')
run: cp ./${{ inputs.ps_dir }}/app/config/security_test.yml ./${{ inputs.ps_dir }}/app/config/security_prod.yml
shell: bash

- name: Adapt Back Office layout
if: inputs.backoffice_layout == 'symfony'
working-directory: ${{ inputs.ps_dir }}
run: |
echo PS_FF_SYMFONY_LAYOUT=true >> .env
shell: bash
94 changes: 94 additions & 0 deletions .github/workflows/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Run UI tests
description: Run UI tests
inputs:
base_branch:
description: Base branch to rebase the PR
required: true
ps_mode_dev:
description: Enable/Disable the developer mode
required: true
php_version:
description: PHP version
required: true
node_version:
description: Node version
required: true
test_command:
description: Test command to run
required: true
fast_fail:
description: Fast fail on first error
required: true
ps_dir:
description: Directory target
required: true

runs:
using: "composite"
steps:
- name: Run tests
run: |
export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"
npm run test:${{ inputs.test_command }}
working-directory: '${{ inputs.ps_dir }}/tests/UI'
env:
# Input values
PS_MODE_DEV: ${{ fromJson(inputs.ps_mode_dev) && '1' || '0' }}
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' }}
# 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/' }}
HEADLESS: true
ENABLE_SSL: true
TAKE_SCREENSHOT_AFTER_FAIL: true
SMTP_SERVER: '172.17.0.1'
EXTRA_TEST_PARAMS: ${{ fromJson(inputs.fast_fail) && '--bail' || '' }}
shell: bash

# UI Tests : Upload screenshots
- name: Prepare screenshot name
id: screenshot-campaign
run: echo "screenshot-campaign=$( echo -e '${{ inputs.test_command }}' | tr ':' '-' )" >> $GITHUB_OUTPUT
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
uses: actions/upload-artifact@v3
if: failure()
with:
name: 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
227 changes: 227 additions & 0 deletions .github/workflows/build-shop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
name: Build PrestaShop and export sources and SQL dump as artifacts
on:
workflow_call:
inputs:
pr_number:
type: string
description: Pull request Id
required: true
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
rebase_or_merge:
type: string
required: true
description: Rebase or merge the pull request
php_version:
type: string
description: PHP version
required: true
node_version:
type: string
description: Node version
required: true
backoffice_layout:
type: string
description: Backoffice layout
required: true

jobs:
build-shop-artifacts:
runs-on: ubuntu-latest
name: Build shop artifacts
env:
# Input values
PS_MODE_DEV: ${{ inputs.ps_mode_dev && '1' || '0' }}
PS_DEV_MODE: ${{ 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' }}
URL_FO: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }}
# 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]'
# Build assets and install shop
PS_INSTALL_AUTO: 1
DISABLE_MAKE: 0

steps:
- name: Print Inputs values
shell: bash
run: echo "${{ toJSON(inputs) }}"

# Checkout repository to use custom actions
- uses: actions/checkout@v3
with:
path: custom_actions

- name: Checkout PrestaShop
uses: ./custom_actions/.github/workflows/actions/checkout-prestashop
with:
pr_number: ${{ inputs.pr_number }}
base_branch: ${{ inputs.base_branch }}
rebase_or_merge: ${{ inputs.rebase_or_merge }}
backoffice_layout: ${{ inputs.backoffice_layout }}
ps_dir: ${{ env.PS_DIR }}

# Pre pull/build images
# For some reason keycloak must be started before the PrestaShop build or it fails
- name: Pull images in background
working-directory: ${{ env.PS_DIR }}
run: |
# Pull mysql image
USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml pull -q mysql >& /dev/null &
- name: Build PrestaShop image in background
working-directory: ${{ env.PS_DIR }}
run: |
# Build prestashop image in background
USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml build >& /dev/null &

# Run composer install before building the assets since the themes come from composer
- name: Get Composer Cache Directory
id: composer-cache-dir
run: |
echo "composer-cache-dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
working-directory: ${{ env.PS_DIR }}
shell: bash
- name: Restore composer cache dir
uses: actions/cache/restore@v3
id: composer-cache
with:
path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
# Run composer install
- name: Install Composer dependencies
run: composer install --prefer-dist --optimize-autoloader
working-directory: ${{ env.PS_DIR }}
shell: bash
# Save composer cache when it didn't exist
- name: Save composer cache dir
uses: actions/cache/save@v3
if: steps.composer-cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }}
key: ${{ steps.composer-cache.outputs.cache-primary-key }}

# Install node dependencies and build assets
- name: Setup Node ${{ inputs.node_version }}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node_version }}
- name: Build assets in parallel and in background
run: |
(pushd ${{ env.PS_DIR }}/admin-dev/themes/new-theme; touch buildLock; npm ci; npm run build; rm buildLock; popd) &
(pushd ${{ env.PS_DIR }}/admin-dev/themes/default; touch buildLock; npm ci; npm run build; rm buildLock; popd) &
(pushd ${{ env.PS_DIR }}/themes/classic/_dev; touch buildLock; npm ci; npm run build; rm buildLock; popd) &
(pushd ${{ env.PS_DIR }}/themes/; touch buildLock; npm ci; npm run build; rm buildLock; popd) &
shell: bash

# Certificate
- name: Generate a certificate
if: (inputs.base_branch == '8.1.x') || (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

# Wait for all builds to be finished (the check is required because we encountered cases where the action exited before
# everything was built, probably because of the parallelization and background processes)
- name: Check that all builds are finished
run: |
buildLocks="admin-dev/themes/new-theme/buildLock admin-dev/themes/default/buildLock themes/classic/_dev/buildLock themes/buildLock"
echo Checking for all these lock files $buildLocks
for lockFile in $buildLocks; do
lockFile="${{ env.PS_DIR }}/$lockFile"
if [ -f $lockFile ]; then
echo Wait for $lockFile to be removed
sleep 1
while [ -f $lockFile ]; do
echo $lockFile still present wait a bit more
sleep 1
done
fi
echo $lockFile is no longer present
done
shell: bash

# Create shop with Docker build assets, and initialize database and shop content
- name: Start PrestaShop docker
working-directory: ${{ env.PS_DIR }}
timeout-minutes: 5
env:
URL_FO: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }}
VERSION: ${{ (inputs.base_branch == '1.7.8.x') && inputs.php_version || env.VERSION }}
# Initial build, install shop data but assets are already built
DISABLE_MAKE: 1
PS_INSTALL_AUTO: 1
run: |
# First wait for all images to be ready
echo Check that all images are ready
until docker images | grep mysql; do echo Waiting for mysql image; sleep 1; done
until docker images | grep prestashop-git; do echo Waiting for prestashop-git image; sleep 1; done
# Then build and start the docker
echo Build docker via docker composer
USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose -f docker-compose.yml up -d --build prestashop-git
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 1; done'

# Prepare archive contents to share with following jobs
- name: Archive shop content
if: always()
run: |
mkdir -p /tmp/shop-artifacts
zip -q -r /tmp/shop-artifacts/sources.zip ${{ env.PS_DIR }} -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/**/*" \
"*/.git/**/*"
docker exec my_prestashop_mysql_1 /usr/bin/mysqldump -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }} ${{ env.DB_NAME }} > /tmp/shop-artifacts/db_dump.sql

- name: Upload shop artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: shop-artifacts
path: /tmp/shop-artifacts

- name: Save logs in case of error
uses: actions/upload-artifact@v3
if: failure()
with:
name: Build error export logs
path: |
${{ env.PS_DIR }}/var/logs
Loading