-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
325 lines (306 loc) · 12.8 KB
/
.gitlab-ci.yml
File metadata and controls
325 lines (306 loc) · 12.8 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
stages:
- create
- test
- deploy
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# ======= UTILITIES =======
.ssh-client:
image: alpine:latest
before_script:
- apk add openssh openssl && mkdir ~/.ssh/
- echo "$SSH_PRIVATE_KEY" | openssl base64 -A -d > ~/.ssh/id_rsa && chmod 0400 ~/.ssh/id_rsa
- echo -e "Host $SSH_HOST\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
# ======= LINTERS [PHP] =======
php:lint:
stage: create
image: php:8.2-cli-alpine
variables:
PHP_CS_FIXER_IGNORE_ENV: 1
before_script:
- apk add --no-cache bash coreutils git make
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
script:
- mkdir src && ls -A | grep -v src | xargs mv -t src
- git clone https://github.com/magento/magento-coding-standard.git && cd magento-coding-standard
- composer install --ignore-platform-reqs
- vendor/bin/phpcs -s -p --colors --extensions=php --standard=Magento2 ../src/
- composer require friendsofphp/php-cs-fixer:3.4.0
- vendor/bin/php-cs-fixer fix --config=../src/.php-cs-fixer.dist.php --dry-run --diff ../src/
php:compat:
stage: create
image: registry.gitlab.com/pipeline-components/php-codesniffer:latest
variables:
PHP_CS_FIXER_IGNORE_ENV: 1
parallel:
matrix:
- PHP_VERSION: ["7.4", "8.1", "8.2"]
script:
- phpcs -s -p --colors --extensions=php --standard=PHPCompatibility --runtime-set testVersion $PHP_VERSION .
# ======= REVIEW INSTANCES =======
.review:
extends: .ssh-client
stage: create
variables:
REVIEW_INSTANCE: magento_$CI_MERGE_REQUEST_IID
SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY_DEV
SSH_HOST: $SSH_HOST_DEV
SSH_PATH: /var/www/$REVIEW_INSTANCE
environment:
name: review/$CI_MERGE_REQUEST_IID
rules:
- if: $CI_MERGE_REQUEST_ID
resource_group: review
# Magento 2.4.5
review:create:
extends: .review
needs:
- php:lint
- php:compat
variables:
PHP_VERSION: "8.1"
COMPOSER_VERSION: ""
MAGENTO_VERSION: "2.4.5"
PHP_CLI: php$PHP_VERSION
COMPOSER_CLI: composer$COMPOSER_VERSION
RABBITMQ_CTL: rabbitmqctl
environment:
url: https://qa${CI_MERGE_REQUEST_IID}.${DEPLOY_HOST_DEV}
on_stop: review:detach
script:
- ssh "magento@$SSH_HOST"
"[ ! -f '$SSH_PATH/app/etc/config.php' ] && {
rm -rf $SSH_PATH && mkdir $SSH_PATH &&
$PHP_CLI /usr/local/bin/$COMPOSER_CLI global config http-basic.repo.magento.com '$MAGENTO_REPOSITORY_USER' '$MAGENTO_REPOSITORY_PASSWORD' &&
$PHP_CLI /usr/local/bin/$COMPOSER_CLI create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=$MAGENTO_VERSION $SSH_PATH &&
mysql -umagento -pmagento -e 'DROP DATABASE IF EXISTS $REVIEW_INSTANCE; CREATE DATABASE $REVIEW_INSTANCE' &&
mkdir -p $SSH_PATH/app/code/Hokodo/BNPL/ ;
} || echo 'Magento project exists in $SSH_PATH, skipping prerequisites.'"
- scp -r * "magento@$SSH_HOST:$SSH_PATH/app/code/Hokodo/BNPL/"
- ssh "ubuntu@$SSH_HOST" "rvhost=\$(sudo $RABBITMQ_CTL list_vhosts | grep -w $REVIEW_INSTANCE'$') && [ \$rvhost ] && echo 'The vhost is already set up' || (sudo $RABBITMQ_CTL add_vhost $REVIEW_INSTANCE && sudo $RABBITMQ_CTL set_permissions -p $REVIEW_INSTANCE guest '.*' '.*' '.*')"
- ssh "magento@$SSH_HOST"
"cd $SSH_PATH;
[ ! -f '$SSH_PATH/app/etc/env.php' ] && {
$PHP_CLI bin/magento setup:install --no-interaction
--use-rewrites=1
--base-url='$CI_ENVIRONMENT_URL'
--backend-frontname=admin
--language=en_GB
--currency=GBP
--timezone=Europe/London
--db-name=$REVIEW_INSTANCE
--db-user=magento
--db-password=magento
--admin-firstname='Hokodo'
--admin-lastname='BNPL'
--admin-email='tech@hokodo.co'
--admin-user='$MAGENTO_ADMIN_USER'
--admin-password='$MAGENTO_ADMIN_PASSWORD'
--amqp-host='127.0.0.1'
--amqp-port='5672'
--amqp-user='guest'
--amqp-password='guest'
--amqp-virtualhost='$REVIEW_INSTANCE' &&
$PHP_CLI bin/magento deploy:mode:set developer &&
$PHP_CLI bin/magento config:set catalog/search/elasticsearch7_index_prefix '${REVIEW_INSTANCE}_' &&
$PHP_CLI bin/magento config:set payment/hokodo_bnpl/active 1 &&
$PHP_CLI bin/magento config:set payment/hokodo_bnpl/environment dev &&
$PHP_CLI bin/magento config:set payment/hokodo_bnpl/dev_api_key '$HOKODO_API_KEY_DEV' &&
$PHP_CLI bin/magento config:set payment/hokodo_bnpl/dev_sdk_key '$HOKODO_SDK_KEY_DEV' &&
$PHP_CLI bin/magento config:set payment/hokodo_bnpl/create_invoice_on_payment_accepted 1 &&
$PHP_CLI bin/magento config:set payment/hokodo_bnpl/capture_online 1;
echo '{}' > ./auth.json &&
$PHP_CLI /usr/local/bin/$COMPOSER_CLI config --file=./auth.json http-basic.repo.magento.com '$MAGENTO_REPOSITORY_USER' '$MAGENTO_REPOSITORY_PASSWORD' &&
$PHP_CLI bin/magento sampledata:deploy;
} || echo 'Magento project was installed with sample data, skipping configuration.'"
# Magento commands: setup:upgrade => setup:di:compile => cache:flush
- ssh "magento@$SSH_HOST" "cd $SSH_PATH && $PHP_CLI bin/magento se:up"
- ssh "magento@$SSH_HOST" "cd $SSH_PATH && m2fa=\$(cat $SSH_PATH/app/etc/config.php | grep -wc Magento_AdminAdobeImsTwoFactorAuth) && [ \$m2fa ] && $PHP_CLI bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth || echo 'No 2fa_admin module was found'"
- ssh "magento@$SSH_HOST" "cd $SSH_PATH && m2fa=\$(cat $SSH_PATH/app/etc/config.php | grep -wc Magento_TwoFactorAuth) && [ \$m2fa ] && $PHP_CLI bin/magento module:disable Magento_TwoFactorAuth || echo 'No 2fa module was found'"
- ssh "magento@$SSH_HOST" "cd $SSH_PATH && $PHP_CLI bin/magento se:up && $PHP_CLI bin/magento se:d:c && $PHP_CLI bin/magento cache:flush && $PHP_CLI app/code/Hokodo/BNPL/Test/Fixtures/create-customers.php '$HOKODO_TEST_CUSTOMER_PASSWORD'"
- ssh "magento@$SSH_HOST" "task=\$(cat /home/magento/magento_cron_script/queue.sh | grep -c /$REVIEW_INSTANCE/) && [ \$task ] && echo 'Cron task is already exists' || echo '$PHP_CLI $SSH_PATH/bin/magento cron:run --group=consumers' >> /home/magento/magento_cron_script/queue.sh"
review:detach:
extends: .review
needs:
- review:create
variables:
GIT_STRATEGY: none # no git checkout!
environment:
action: stop
when: manual
script:
- ssh "magento@$SSH_HOST"
"rm -rf $SSH_PATH &&
mysql -umagento -pmagento -e 'DROP DATABASE IF EXISTS $REVIEW_INSTANCE' &&
curl -XDELETE 'http://localhost:9200/${REVIEW_INSTANCE}_*' &&
sed -i '/php.*$REVIEW_INSTANCE\/.*consumers/d' /home/magento/magento_cron_script/queue.sh"
- ssh "ubuntu@$SSH_HOST"
"sudo rabbitmqctl delete_vhost $REVIEW_INSTANCE"
## Magento 2.4.6
review:create [2.4.7]:
extends: review:create
variables:
PHP_VERSION: "8.1"
MAGENTO_VERSION: "2.4.7"
REVIEW_INSTANCE: magento_${CI_MERGE_REQUEST_IID}_m247
environment:
name: review/$CI_MERGE_REQUEST_IID-m247
url: https://qa${CI_MERGE_REQUEST_IID}-m247.${DEPLOY_HOST_DEV}
on_stop: review:detach [2.4.7]
resource_group: review-2.4.7
review:detach [2.4.7]:
extends: review:detach
needs:
- review:create [2.4.7]
variables:
REVIEW_INSTANCE: magento_${CI_MERGE_REQUEST_IID}_m247
environment:
name: review/$CI_MERGE_REQUEST_IID-m247
resource_group: review-2.4.7
## ======= Magento Integration Tests =====
.integration-tests: &integration-tests
stage: test
Magento Integration Tests:
<<: *integration-tests
extends: .ssh-client
variables:
REVIEW_INSTANCE: magento_${CI_MERGE_REQUEST_IID}
SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY_DEV
SSH_HOST: $SSH_HOST_DEV
SSH_PATH: /var/www/$REVIEW_INSTANCE
PHP_VERSION: "8.1"
COMPOSER_VERSION: ""
PHP_CLI: php$PHP_VERSION
COMPOSER_CLI: composer$COMPOSER_VERSION
environment:
name: review/$CI_MERGE_REQUEST_IID
rules:
- if: $CI_MERGE_REQUEST_ID
resource_group: review
needs:
- review:create
when: always
script:
- ssh "magento@$SSH_HOST" "cd $SSH_PATH && [ -f 'dev/tests/integration/phpunit.xml' ] && {
rm dev/tests/integration/phpunit.xml; } || echo 'Skipping phpunit.xml removal.'"
- ssh "magento@$SSH_HOST" "cd $SSH_PATH && [ -f 'dev/tests/integration/etc/install-config-mysql.php' ] && {
rm dev/tests/integration/etc/install-config-mysql.php; } || echo 'Skipping install-config removal.'"
- ssh "magento@$SSH_HOST" "cd $SSH_PATH && cp app/code/Hokodo/BNPL/Test/phpunit.xml.dist dev/tests/integration/phpunit.xml &&
cp app/code/Hokodo/BNPL/Test/install-config-mysql.php.dist dev/tests/integration/etc/install-config-mysql.php &&
sed -i 's/%CI_ID%/$CI_MERGE_REQUEST_IID/' dev/tests/integration/etc/install-config-mysql.php &&
rm -rf dev/tests/integration/tmp/*"
- ssh "magento@$SSH_HOST" "mysql -umagento -pmagento -e 'DROP DATABASE IF EXISTS magento_tests_$CI_MERGE_REQUEST_IID; CREATE DATABASE magento_tests_$CI_MERGE_REQUEST_IID'"
- ssh "magento@$SSH_HOST" "cd $SSH_PATH && $PHP_CLI bin/magento mo:en Magento_TwoFactorAuth && $PHP_CLI bin/magento dev:tests:run integration && $PHP_CLI bin/magento mo:dis Magento_TwoFactorAuth"
- ssh "magento@$SSH_HOST" "mysql -umagento -pmagento -e 'DROP DATABASE IF EXISTS magento_tests_$CI_MERGE_REQUEST_IID;'"
## ======= E2E TESTS =======
.end-to-end-tests: &end-to-end-tests
image: mcr.microsoft.com/playwright:v1.26.0-focal
stage: test
rules:
- if: $CI_MERGE_REQUEST_ID
All Playwright:
<<: *end-to-end-tests
needs:
- Playwright Smoke Test
variables:
BASE_URL: https://qa${CI_MERGE_REQUEST_IID}.${DEPLOY_HOST_DEV}
allow_failure: false
when: manual
artifacts:
when: always
paths:
- playwright-report/
expire_in: 1 week
script:
- npm install
- npx playwright install --with-deps
- >
HOKODO_API_KEY=$HOKODO_API_KEY_DEV
HOKODO_API_BASE_URL=https://api-dev.hokodo.co
MAGENTO_ADMIN_USER=$MAGENTO_ADMIN_USER
BASE_URL=$BASE_URL
npx playwright test
--config ./tests/playwright/playwright.config.ts
Playwright Smoke Test:
<<: *end-to-end-tests
needs:
- Magento Integration Tests
allow_failure: false
artifacts:
when: always
paths:
- playwright-report/
expire_in: 1 week
variables:
BASE_URL: https://qa${CI_MERGE_REQUEST_IID}.${DEPLOY_HOST_DEV}
script:
- npm install
- npx playwright install --with-deps
- >
HOKODO_API_KEY=$HOKODO_API_KEY_DEV
HOKODO_API_BASE_URL=https://api-dev.hokodo.co
MAGENTO_ADMIN_USER=$MAGENTO_ADMIN_USER
BASE_URL=$BASE_URL
npx playwright test -g "Placing and fulfilling a Registered Company's first Order"
--config ./tests/playwright/playwright.config.ts
All Playwright v2.4.7:
<<: *end-to-end-tests
needs:
- review:create [2.4.7]
when: manual
allow_failure: false
artifacts:
when: always
paths:
- playwright-report/
expire_in: 1 week
variables:
BASE_URL: https://qa${CI_MERGE_REQUEST_IID}-m247.${DEPLOY_HOST_DEV}
script:
- npm install
- npx playwright install --with-deps
- >
HOKODO_API_KEY=$HOKODO_API_KEY_DEV
HOKODO_API_BASE_URL=https://api-dev.hokodo.co
MAGENTO_ADMIN_USER=$MAGENTO_ADMIN_USER
BASE_URL=$BASE_URL
npx playwright test
--config ./tests/playwright/playwright.config.ts
# ======= DEPLOYMENT =======
.deploy:
extends: .ssh-client
stage: deploy
variables:
PHP_VERSION: "7.4"
PHP_CLI: php$PHP_VERSION
script:
- ssh "magento@$SSH_HOST" "cd $SSH_PATH/app/code/ && rm -rf * && mkdir -p Hokodo/BNPL/"
- scp -r * "magento@$SSH_HOST:$SSH_PATH/app/code/Hokodo/BNPL/"
- ssh "magento@$SSH_HOST"
"cd $SSH_PATH &&
$PHP_CLI bin/magento config:set --lock-env payment/hokodo_bnpl/active 1 &&
$PHP_CLI bin/magento config:set --lock-env payment/hokodo_bnpl/environment '$HOKODO_ENV'&&
$PHP_CLI bin/magento config:set --lock-env payment/hokodo_bnpl/${HOKODO_ENV}_api_key '$HOKODO_API_KEY_SANDBOX' &&
$PHP_CLI bin/magento config:set --lock-env payment/hokodo_bnpl/${HOKODO_ENV}_sdk_key '$HOKODO_SDK_KEY_SANDBOX'"
# Magento commands: setup:upgrade => setup:di:compile => setup:static-content:deploy => cache:flush
- ssh "magento@$SSH_HOST" "cd $SSH_PATH && $PHP_CLI bin/magento se:up && $PHP_CLI bin/magento se:d:c && $PHP_CLI bin/magento se:s:d && $PHP_CLI bin/magento c:f"
.deploy-dev:
extends: .deploy
variables:
SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY_DEV
SSH_HOST: $SSH_HOST_DEV
SSH_PATH: ~/public_html
HOKODO_ENV: sandbox
HOKODO_API_KEY: $HOKODO_API_KEY_SANDBOX
resource_group: deploy-dev
deploy:dev:
extends: .deploy-dev
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
deploy:dev:manual:
extends: .deploy-dev
rules:
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: manual