Split shop building in independent single job for optimization #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | |
# 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 | |
# Install composer vendors | |
- name: Get Composer Cache Directory | |
id: composer-cache | |
run: | | |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
working-directory: '${{ env.PS_DIR }}' | |
- uses: actions/cache@v3 | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-composer- | |
- name: Install Composer dependencies | |
run: composer install --prefer-dist --optimize-autoloader | |
working-directory: '${{ env.PS_DIR }}' | |
# Install node dependencies | |
- uses: custom_actions/.github/workflows/actions/install-node-modules | |
with: | |
node_version: ${{ inputs.node_version }} | |
js_folder: ${{ env.PS_DIR }}/admin-dev/themes/new-theme | |
- uses: custom_actions/.github/workflows/actions/install-node-modules | |
with: | |
node_version: ${{ inputs.node_version }} | |
js_folder: ${{ env.PS_DIR }}/admin-dev/themes/default | |
- uses: custom_actions/.github/workflows/actions/install-node-modules | |
with: | |
node_version: ${{ inputs.node_version }} | |
js_folder: ${{ env.PS_DIR }}/themes/classic/_dev | |
- uses: custom_actions/.github/workflows/actions/install-node-modules | |
with: | |
node_version: ${{ inputs.node_version }} | |
js_folder: ${{ env.PS_DIR }}/themes/ | |
# Build assets | |
- run: (pushd ${{ env.PS_DIR }}/admin-dev/themes/new-theme; npm run build; popd) | |
& (pushd ${{ env.PS_DIR }}/admin-dev/themes/default; npm run build; popd) | |
& (pushd ${{ env.PS_DIR }}/themes/classic/_dev; npm run build; popd) | |
& (pushd ${{ env.PS_DIR }}/themes; npm run build; popd) | |
# Create shop with Docker build assets, and initialize database and shop content | |
- name: Build and run shop with docker | |
working-directory: ${{ env.PS_DIR }} | |
timeout-minutes: 15 | |
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: | | |
echo Build docker via docker composer | |
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 1; done' | |
# Prepare archive contents to share with following jobs | |
- name: Archive shop content | |
run: | | |
mkdir -p /tmp/shop-artifacts | |
echo Clean node_modules | |
rm -fR ${{ env.PS_DIR }}/admin-dev/themes/new-theme/node_modules | |
rm -fR ${{ env.PS_DIR }}/admin-dev/themes/default/node_modules | |
rm -fR ${{ env.PS_DIR }}/themes/classic/_dev | |
rm -fR ${{ env.PS_DIR }}/themes/_core | |
rm -fR ${{ env.PS_DIR }}/themes/node_modules | |
rm -fR ${{ env.PS_DIR }}/var/cache/* | |
rm -fR ${{ env.PS_DIR }}/.git | |
zip -q -r /tmp/shop-artifacts/sources.zip ${{ env.PS_DIR }} | |
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 | |
uses: actions/upload-artifact@v3 | |
with: | |
name: shop-artifacts | |
path: /tmp/shop-artifacts | |
- uses: actions/upload-artifact@v3 | |
if: failure() | |
with: | |
name: Build error export logs | |
path: | | |
${{ env.PS_DIR }}/var/logs |