-
Notifications
You must be signed in to change notification settings - Fork 69
218 lines (207 loc) · 9.73 KB
/
test-sanity.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: Install shop and run sanity tests
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
fast_fail:
type: boolean
description: Fast fail on first error
required: true
default: false
take_screenshot_after_each_step:
type: boolean
description: Take a screenshot after each step
required: true
default: false
DB_SERVER:
type: string
description: Database Type
required: true
jobs:
test-sanity:
runs-on: ubuntu-latest
name: Test ${{ inputs.test_command }}
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' }}
PS_USE_DOCKER_MAILDEV: 0
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: ${{ inputs.DB_SERVER }}
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(inputs) }}"
# Checkout repository to use custom actions
- uses: actions/checkout@v4
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 }}
ps_dir: ${{ env.PS_DIR }}
- name: Pull database image in background
working-directory: ${{ env.PS_DIR }}
run: |
# Pull ${{ inputs.DB_SERVER }} image
USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker compose -f ${{ (inputs.DB_SERVER == 'mysql') && 'docker-compose.yml' || 'docker-compose.mariadb.yml' }} pull -q ${{ inputs.DB_SERVER }} >& /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 ${{ (inputs.DB_SERVER == 'mysql') && 'docker-compose.yml' || 'docker-compose.mariadb.yml' }} build prestashop-git >& /dev/null &
# Certificate
- name: Generate a certificate
if: (inputs.base_branch == '8.1.x') || (inputs.base_branch == '8.2.x') || (inputs.base_branch == '9.0.x') || (inputs.base_branch == 'develop')
run: |
## Install MkCert
sudo apt-get update
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
# 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@v4
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@v4
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 }}
# Create shop with Docker without building assets, and initialize database and shop content
# No need to wait for install-dev ready it should be nearly automatic and just in case we build the assets after to leave
# a bit more time for the docker to fully init
- 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 }}
# No assets built, already done and no install since the campaign handles it
DISABLE_MAKE: 1
PS_INSTALL_AUTO: 0
run: |
# First wait for all images to be ready
echo Check that all images are ready
until docker images | grep ${{ inputs.DB_SERVER }} ; do echo Waiting for ${{ inputs.DB_SERVER }} 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, no need to wait the install page is accessible right away
echo Build docker via docker compose
USER_ID=$(id -u) GROUP_ID=$(id -g) docker compose -f ${{ (inputs.DB_SERVER == 'mysql') && 'docker-compose.yml' || 'docker-compose.mariadb.yml' }} up -d --build prestashop-git
# Install node dependencies and build assets
- name: Setup Node ${{ inputs.node_version }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.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) &
(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
# 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="tests/UI 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
timeout-minutes: 10
# Playwright must be installed all the time, we only install chromium since it's the only browser used
- name: Install browsers
working-directory: ${{ env.PS_DIR }}/tests/UI
if: ${{ inputs.base_branch == '8.0.x' || inputs.base_branch == '8.1.x' || inputs.base_branch == '8.2.x' || inputs.base_branch == '9.0.x' || inputs.base_branch == 'develop' }}
run: npx playwright install chromium
- name: Run sanity campaign
uses: ./custom_actions/.github/workflows/actions/run-tests
with:
base_branch: ${{ inputs.base_branch }}
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 }}
take_screenshot_after_each_step: ${{ inputs.take_screenshot_after_each_step }}
ps_dir: ${{ env.PS_DIR }}
DB_SERVER: ${{ inputs.DB_SERVER }}