Skip to content

Commit

Permalink
Add new action responsible for setting env variables, especially it e…
Browse files Browse the repository at this point in the history
…nsures node and php versions are adapted to the PrestaSHop version
  • Loading branch information
jolelievre committed Oct 2, 2023
1 parent 961fedd commit 49c4b22
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 87 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ inputs:
php_version:
description: PHP version
required: true
node_version:
description: Node version
required: true
test_command:
description: Test command to run
required: true
Expand All @@ -35,9 +32,6 @@ runs:
# 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: ${{ (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' }}
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/actions/setup-build-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Setup env variables 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 and force them in the Github environment
inputs:
repository_ref:
description: Base branch/ref from the repository
required: true
php_version:
description: PHP version
required: true

runs:
using: "composite"
steps:
- name: Set dynamic environment variables
run: |
function version { printf "%03d%03d%03d%03d" $(echo "$1" | sed s/x/999/ | tr '.' ' '); }
if [ $(version $repository_ref) -lt $(version 1.7.7) ]; then
echo Version under 1.7.7 use Node 8
nodeVersion=8
elif [ $(version $repository_ref) -lte $(version 1.7.7.x) ]; then
echo Version 1.7.7 uses Node 10
nodeVersion=10
elif [ $(version $repository_ref) -lte $(version 1.7.8.x) ]; then
echo Version 1.7.8 uses Node 14
nodeVersion=14
else
echo Versions after 1.7.8 use Node 16
nodeVersion=16
fi
echo "NODE_VERSION=$nodeVersion" >> $GITHUB_ENV
phpVersion=${{ inputs.php_version }}
if [ $(version $repository_ref) -lte $(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 $repository_ref) -lte $(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 $repository_ref) -lte $(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 $repository_ref) -lte $(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.3
elif [ $(version $repository_ref) -lte $(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
fi
echo "PHP_VERSION=$phpVersion" >> $GITHUB_ENV
# Docker version to use based on PHP versions
echo "VERSION=$phpVersion-apache" >> $GITHUB_ENV
shell: bash
13 changes: 7 additions & 6 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ on:
type: string
description: PHP version
required: true
node_version:
type: string
description: Node version
required: true

jobs:
build-target:
Expand All @@ -31,17 +27,22 @@ jobs:
- uses: actions/checkout@v3
with:
path: custom_actions
- name: Setup PrestaShop build env variables
uses: ./custom_actions/.github/workflows/actions/setup-build-env
with:
repository_ref: ${{ inputs.target_ref }}
php_version: ${{ inputs.php_version }}

- name: Checkout PrestaShop
uses: ./custom_actions/.github/workflows/actions/checkout-prestashop
with:
repository_ref: ${{ inputs.target_ref }}
ps_dir: ${{ env.PS_TARGET }}

- name: Setup Node ${{ inputs.node_version }}
- name: Setup Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node_version }}
node-version: ${{ env.NODE_VERSION }}

- name: Build release
working-directory: ${{ env.PS_TARGET }}
Expand Down
18 changes: 8 additions & 10 deletions .github/workflows/build-shop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ on:
type: string
description: PHP version
required: true
node_version:
type: string
description: Node version
required: true
pr_number:
type: string
description: Pull request Id
Expand Down Expand Up @@ -48,9 +44,6 @@ jobs:
# 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: ${{ (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' }}
Expand Down Expand Up @@ -79,6 +72,11 @@ jobs:
- uses: actions/checkout@v3
with:
path: custom_actions
- name: Setup PrestaShop build env variables
uses: ./custom_actions/.github/workflows/actions/setup-build-env
with:
repository_ref: ${{ inputs.repository_ref }}
php_version: ${{ inputs.php_version }}

- name: Checkout PrestaShop
uses: ./custom_actions/.github/workflows/actions/checkout-prestashop
Expand Down Expand Up @@ -128,10 +126,10 @@ jobs:
key: ${{ steps.composer-cache.outputs.cache-primary-key }}

# Install node dependencies and build assets
- name: Setup Node ${{ inputs.node_version }}
- name: Setup Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node_version }}
node-version: ${{ env.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) &
Expand Down Expand Up @@ -184,7 +182,7 @@ jobs:
timeout-minutes: 5
env:
URL_FO: ${{ ((startsWith(inputs.repository_ref, '8.0')) || (startsWith(inputs.repository_ref, '1.7'))) && 'http://localhost:8001/' || 'https://localhost:8002/' }}
VERSION: ${{ (startsWith(inputs.repository_ref, '1.7')) && inputs.php_version || env.VERSION }}
VERSION: ${{ env.VERSION }}
# Initial build, install shop data but assets are already built
DISABLE_MAKE: 1
PS_INSTALL_AUTO: 1
Expand Down
12 changes: 0 additions & 12 deletions .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ on:
- '8.1'
- '8.2'
default: '8.1'
node_version:
type: choice
description: Node version
required: true
options:
- '14.21.3'
- '16.20.1'
default: '14.21.3'

jobs:
# Sanity tests are run independently because it's the only campaign that handles the installation itself, since it tests it
Expand All @@ -71,7 +63,6 @@ jobs:
ps_mode_dev: ${{ inputs.ps_mode_dev }}
rebase_or_merge: ${{ inputs.rebase_or_merge }}
php_version: ${{ inputs.php_version }}
node_version: ${{ inputs.node_version }}
backoffice_layout: ${{ inputs.backoffice_layout }}
fast_fail: ${{ inputs.fast_fail }}

Expand All @@ -85,7 +76,6 @@ jobs:
ps_mode_dev: ${{ inputs.ps_mode_dev }}
rebase_or_merge: ${{ inputs.rebase_or_merge }}
php_version: ${{ inputs.php_version }}
node_version: ${{ inputs.node_version }}
backoffice_layout: ${{ inputs.backoffice_layout }}

# These campaigns are run first because they are longer, so we try to optimize the total run However this list must not
Expand All @@ -99,7 +89,6 @@ jobs:
repository_ref: ${{ inputs.base_branch }}
ps_mode_dev: ${{ inputs.ps_mode_dev }}
php_version: ${{ inputs.php_version }}
node_version: ${{ inputs.node_version }}
test_command: ${{ matrix.TEST_COMMAND }}
fast_fail: ${{ inputs.fast_fail }}
strategy:
Expand Down Expand Up @@ -135,7 +124,6 @@ jobs:
repository_ref: ${{ inputs.base_branch }}
ps_mode_dev: ${{ inputs.ps_mode_dev }}
php_version: ${{ inputs.php_version }}
node_version: ${{ inputs.node_version }}
test_command: ${{ matrix.TEST_COMMAND }}
fast_fail: ${{ inputs.fast_fail }}
strategy:
Expand Down
11 changes: 0 additions & 11 deletions .github/workflows/pr_test_single_campaign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ on:
- '8.1'
- '8.2'
default: '8.1'
node_version:
type: choice
description: Node version
required: true
options:
- '14.21.3'
- '16.20.1'
default: '14.21.3'

jobs:
build-shop:
Expand All @@ -119,7 +111,6 @@ jobs:
ps_mode_dev: ${{ inputs.ps_mode_dev }}
rebase_or_merge: ${{ inputs.rebase_or_merge }}
php_version: ${{ inputs.php_version }}
node_version: ${{ inputs.node_version }}
backoffice_layout: ${{ inputs.backoffice_layout }}

test-pr:
Expand All @@ -131,7 +122,6 @@ jobs:
repository_ref: ${{ inputs.base_branch }}
ps_mode_dev: ${{ inputs.ps_mode_dev }}
php_version: ${{ inputs.php_version }}
node_version: ${{ inputs.node_version }}
test_command: ${{ inputs.test_command }}
fast_fail: ${{ inputs.fast_fail }}

Expand All @@ -146,6 +136,5 @@ jobs:
ps_mode_dev: ${{ inputs.ps_mode_dev }}
rebase_or_merge: ${{ inputs.rebase_or_merge }}
php_version: ${{ inputs.php_version }}
node_version: ${{ inputs.node_version }}
backoffice_layout: ${{ inputs.backoffice_layout }}
fast_fail: ${{ inputs.fast_fail }}
19 changes: 8 additions & 11 deletions .github/workflows/test-sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ on:
type: string
description: PHP version
required: true
node_version:
type: string
description: Node version
required: true
backoffice_layout:
type: string
description: Backoffice layout
Expand All @@ -44,9 +40,6 @@ jobs:
# 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: ${{ (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' }}
Expand All @@ -72,6 +65,11 @@ jobs:
- uses: actions/checkout@v3
with:
path: custom_actions
- name: Setup PrestaShop build env variables
uses: ./custom_actions/.github/workflows/actions/setup-build-env
with:
repository_ref: ${{ inputs.repository_ref }}
php_version: ${{ inputs.php_version }}

- name: Checkout PrestaShop
uses: ./custom_actions/.github/workflows/actions/checkout-prestashop
Expand Down Expand Up @@ -145,7 +143,7 @@ jobs:
timeout-minutes: 15
env:
URL_FO: ${{ (startsWith(inputs.repository_ref, '8.0') || startsWith(inputs.repository_ref, '1.7')) && 'http://localhost:8001/' || 'https://localhost:8002/' }}
VERSION: ${{ startsWith(inputs.repository_ref, '1.7') && inputs.php_version || env.VERSION }}
VERSION: ${{ env.VERSION }}
# No assets built, already done and no install since the campaign handles it
DISABLE_MAKE: 1
PS_INSTALL_AUTO: 0
Expand All @@ -159,10 +157,10 @@ jobs:
USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose -f docker-compose.yml up -d --build prestashop-git mysql
# Install node dependencies and build assets
- name: Setup Node ${{ inputs.node_version }}
- name: Setup Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node_version }}
node-version: ${{ env.NODE_VERSION }}
- name: Build assets in parallel and in background
run: |
(pushd ${{ env.PS_DIR }}/tests/UI; touch buildLock; npm ci; npm run build; rm buildLock; popd) &
Expand Down Expand Up @@ -202,7 +200,6 @@ jobs:
repository_ref: ${{ inputs.repository_ref }}
ps_mode_dev: ${{ inputs.ps_mode_dev }}
php_version: ${{ inputs.php_version }}
node_version: ${{ inputs.node_version }}
test_command: sanity
fast_fail: ${{ inputs.fast_fail }}
ps_dir: ${{ env.PS_DIR }}
Expand Down
19 changes: 8 additions & 11 deletions .github/workflows/test-with-prebuilt-shop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ on:
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
Expand All @@ -41,9 +37,6 @@ jobs:
# 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: ${{ (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' }}
Expand All @@ -69,6 +62,11 @@ jobs:
- uses: actions/checkout@v3
with:
path: custom_actions
- name: Setup PrestaShop build env variables
uses: ./custom_actions/.github/workflows/actions/setup-build-env
with:
repository_ref: ${{ inputs.repository_ref }}
php_version: ${{ inputs.php_version }}

- name: Download docker artifacts
id: download-shop
Expand Down Expand Up @@ -143,7 +141,7 @@ jobs:
working-directory: ${{ env.PS_DIR }}
timeout-minutes: 5
env:
VERSION: ${{ startsWith(inputs.repository_ref, '1.7') && inputs.php_version || env.VERSION }}
VERSION: ${{ env.VERSION }}
URL_FO: ${{ (startsWith(inputs.repository_ref, '8.0') || startsWith(inputs.repository_ref, '1.7')) && 'http://localhost:8001/' || 'https://localhost:8002/' }}
# No install we force the sources and load the SQL dump
PS_INSTALL_AUTO: 0
Expand All @@ -163,10 +161,10 @@ jobs:
# Test dependencies are installed manually in each sub job that test the build, it could have been integrated inside the archive to reduce time here
# but it turns out the archive is much bigger with all this code and it makes upload/download phase so much longer that it is more efficient to install
# this here
- name: Setup Node ${{ inputs.node_version }}
- name: Setup Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node_version }}
node-version: ${{ env.NODE_VERSION }}
- name: Build test dependencies
working-directory: ${{ env.PS_DIR }}/tests/UI
run: |
Expand All @@ -183,7 +181,6 @@ jobs:
repository_ref: ${{ inputs.repository_ref }}
ps_mode_dev: ${{ inputs.ps_mode_dev }}
php_version: ${{ inputs.php_version }}
node_version: ${{ inputs.node_version }}
test_command: ${{ inputs.test_command }}
fast_fail: ${{ inputs.fast_fail }}
ps_dir: ${{ env.PS_DIR }}
Expand Down
Loading

0 comments on commit 49c4b22

Please sign in to comment.