Repository navigation
319 lines (292 loc) · 14 KB
/
Copy pathplaywright.yml
File metadata and controls
319 lines (292 loc) · 14 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
name: Playwright test
on:
push:
branches: [main, master]
tags: ['*']
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
has-playwright:
runs-on: ubuntu-latest
outputs:
has_tests: ${{ steps.check.outputs.has_tests }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: Test/Playwright
- name: Check for Playwright tests
id: check
shell: bash
run: |
if find "$GITHUB_WORKSPACE/Test/Playwright" -type f -name '*.spec.ts' -not -path '*/node_modules/*' -print -quit 2>/dev/null | grep -q .; then
echo "has_tests=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::No Playwright tests found in Test/Playwright, skipping"
echo "has_tests=false" >> "$GITHUB_OUTPUT"
fi
playwright:
needs: has-playwright
if: needs.has-playwright.outputs.has_tests == 'true'
runs-on: ubuntu-latest
timeout-minutes: ${{ fromJSON(vars.PLAYWRIGHT_JOB_TIMEOUT || '45') }}
container:
image: yireo/playwright:1.63.0
options: --user root
volumes:
- /var/run/docker.sock:/var/run/docker.sock
env: &magento-env
MAGENTO_BASE_URL: "https://php:8443/"
MAGENTO_BACKEND_FRONTNAME: "admin"
MAGENTO_ADMIN_FIRSTNAME: "CI"
MAGENTO_ADMIN_LASTNAME: "User"
MAGENTO_ADMIN_EMAIL: "admin@example.com"
MAGENTO_ADMIN_USER: "admin"
MAGENTO_ADMIN_PASSWORD: "Admin123!@#"
MAGENTO_LANGUAGE: "en_US"
MAGENTO_CURRENCY: "USD"
MAGENTO_TIMEZONE: "UTC"
MAGENTO_USE_REWRITES: "1"
MAGENTO_SEARCH_ENGINE: "opensearch"
COMPOSER_ALLOW_SUPERUSER: "1"
COMPOSER_MEMORY_LIMIT: "-1"
MYSQL_HOST: "mysql"
MYSQL_USER: "magento2"
MYSQL_PASSWORD: "magento2"
MYSQL_DATABASE: "magento2"
MYSQL_ROOT_PASSWORD: "root"
MYSQL_PORT: "3306"
OPENSEARCH_HOST: "opensearch"
OPENSEARCH_PORT: "9200"
OPENSEARCH_JAVA_OPTS: "-Xms128m -Xmx128m"
OPENSEARCH_INITIAL_ADMIN_PASSWORD: "admin"
MAGENTO_VERSION: ${{ vars.MAGENTO_VERSION || '2.4.8-p5' }}
DISABLE_INVENTORY: ${{ vars.DISABLE_INVENTORY || false }}
DISABLE_GRAPHQL: ${{ vars.DISABLE_GRAPHQL || false }}
DISABLE_ADOBE: ${{ vars.DISABLE_ADOBE || false }}
services:
php:
image: yireo/magento2installed:${{ vars.MAGENTO_VERSION || '2.4.8-p5' }}
credentials: ${{ secrets.DOCKERHUB_USERNAME && fromJSON(format('{{"username":"{0}","password":"{1}"}}', secrets.DOCKERHUB_USERNAME, secrets.DOCKERHUB_TOKEN)) || null }}
env: *magento-env
mysql:
image: yireo/mariadb:10
credentials: ${{ secrets.DOCKERHUB_USERNAME && fromJSON(format('{{"username":"{0}","password":"{1}"}}', secrets.DOCKERHUB_USERNAME, secrets.DOCKERHUB_TOKEN)) || null }}
env:
MYSQL_DATABASE: magento2
MYSQL_USER: magento2
MYSQL_PASSWORD: magento2
MYSQL_ROOT_PASSWORD: root
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=10
redis:
image: redis:7
credentials: ${{ secrets.DOCKERHUB_USERNAME && fromJSON(format('{{"username":"{0}","password":"{1}"}}', secrets.DOCKERHUB_USERNAME, secrets.DOCKERHUB_TOKEN)) || null }}
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
opensearch:
image: yireo/opensearch:latest
credentials: ${{ secrets.DOCKERHUB_USERNAME && fromJSON(format('{{"username":"{0}","password":"{1}"}}', secrets.DOCKERHUB_USERNAME, secrets.DOCKERHUB_TOKEN)) || null }}
env:
OPENSEARCH_JAVA_OPTS: "-Xms128m -Xmx128m"
OPENSEARCH_INITIAL_ADMIN_PASSWORD: "admin"
options: --health-cmd="curl localhost:9200/_cluster/health?wait_for_status=yellow&timeout=60s" --health-interval=10s --health-timeout=5s --health-retries=10
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
- name: Configure Git safe directory
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Setting up module variables
shell: bash
run: |
COMPOSER_NAME=$(jq -er '.name' composer.json)
MAGENTO_MODULE=$(jq -er '.module_name' MODULE.json)
[[ "$COMPOSER_NAME" =~ ^[a-z0-9_.-]+/[a-z0-9_.-]+$ ]] || { echo "::error::Invalid composer name"; exit 1; }
[[ "$MAGENTO_MODULE" =~ ^[A-Za-z0-9]+_[A-Za-z0-9]+$ ]] || { echo "::error::Invalid module name"; exit 1; }
echo "COMPOSER_NAME=$COMPOSER_NAME" >> "$GITHUB_ENV"
echo "MAGENTO_MODULE=$MAGENTO_MODULE" >> "$GITHUB_ENV"
COMPOSER_DEV_REQUIREMENTS=$(jq -r '.["require-dev"] // {} | del(."phpunit/phpunit") | to_entries | map("\(.key):\(.value|gsub("[[:space:]]+"; ""))") | join(" ")' composer.json)
echo "COMPOSER_DEV_REQUIREMENTS=$COMPOSER_DEV_REQUIREMENTS" >> "$GITHUB_ENV"
PHP_CONTAINER="${{ job.services.php.id }}"
if [ -z "$PHP_CONTAINER" ] && [ -n "$ACT" ]; then
# act does not expose service container IDs, so look it up via the job network
NETWORK=$(docker inspect -f '{{range $k, $v := .NetworkSettings.Networks}}{{$k}}{{end}}' "$(hostname)" 2>/dev/null || true)
PHP_CONTAINER=$(docker ps -q --filter "ancestor=yireo/magento2installed:$MAGENTO_VERSION" ${NETWORK:+--filter "network=$NETWORK"} | head -n1)
fi
test -n "$PHP_CONTAINER" || { echo "::error::Could not determine PHP service container"; exit 1; }
echo "PHP_CONTAINER=$PHP_CONTAINER" >> "$GITHUB_ENV"
- name: Copy module source into PHP container
run: docker cp "$GITHUB_WORKSPACE" "$PHP_CONTAINER:/tmp/magento/package-source"
- name: Configure Composer
env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
LOKI_REPO_USERNAME: ${{ secrets.LOKI_REPO_USERNAME }}
LOKI_REPO_PASSWORD: ${{ secrets.LOKI_REPO_PASSWORD }}
MAGENTO_MARKETPLACE_PUBLIC_KEY: ${{ secrets.MAGENTO_MARKETPLACE_PUBLIC_KEY }}
MAGENTO_MARKETPLACE_PRIVATE_KEY: ${{ secrets.MAGENTO_MARKETPLACE_PRIVATE_KEY }}
GITHUB_TOKEN: ${{ github.token }}
run: |
docker exec \
-u root \
-e GITLAB_TOKEN \
-e LOKI_REPO_USERNAME \
-e LOKI_REPO_PASSWORD \
-e MAGENTO_MARKETPLACE_PUBLIC_KEY \
-e MAGENTO_MARKETPLACE_PRIVATE_KEY \
-e GITHUB_TOKEN \
-e GITHUB_JOB \
-e COMPOSER_NAME \
-e MAGENTO_MODULE \
-e MAGENTO_VERSION \
-e PACKAGE_SOURCE=/tmp/magento/package-source \
-e WITH_FUNCTIONAL_TEST_REPOS=1 \
"$PHP_CONTAINER" bash -lc '
set -e
git config --global --add safe.directory /tmp/magento/package-source
bash /tmp/magento/package-source/.github/workflows/composer-setup.sh
'
- name: Restore Composer cache
if: github.event.pull_request.head.repo.fork != true && !env.ACT
uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: /tmp/composer-cache
key: composer-playwright-${{ env.MAGENTO_VERSION }}-${{ hashFiles('composer.json') }}
restore-keys: |
composer-playwright-${{ env.MAGENTO_VERSION }}-
- name: Copy Composer cache into PHP container
if: github.event.pull_request.head.repo.fork != true && !env.ACT
run: |
mkdir -p /tmp/composer-cache
COMPOSER_CACHE_DIR=$(docker exec -u root "$PHP_CONTAINER" composer config --global cache-dir)
echo "COMPOSER_CACHE_DIR=$COMPOSER_CACHE_DIR" >> "$GITHUB_ENV"
docker exec -u root "$PHP_CONTAINER" mkdir -p "$COMPOSER_CACHE_DIR"
docker cp /tmp/composer-cache/. "$PHP_CONTAINER:$COMPOSER_CACHE_DIR"
- name: Add module source
run: |
docker exec \
-u root \
-e COMPOSER_NAME \
-e COMPOSER_DEV_REQUIREMENTS \
"$PHP_CONTAINER" bash -lc '
set -e
cd /tmp/magento
composer config repositories.local-source path /tmp/magento/package-source
EXTRA_PACKAGES=""
case "${COMPOSER_NAME}" in
loki-checkout/*)
EXTRA_PACKAGES="loki-checkout/magento2-core-cli loki-checkout/magento2-csp loki-checkout/magento2-functional-tests:dev-main loki-checkout/magento2-luma loki-checkout/magento2-hyva loki-checkout/magento2-sample-data"
;;
esac
composer require -n --prefer-dist -- \
"${COMPOSER_NAME}:@dev" ${EXTRA_PACKAGES} \
loki/magento2-functional-tests:dev-main \
yireo/magento2-enable-module-sequence:@dev \
hyva-themes/magento2-default-theme-csp \
hyva-themes/magento2-theme-module \
hyva-themes/magento2-base-layout-reset \
hyva-themes/magento2-email-module \
hyva-themes/magento2-graphql-tokens \
hyva-themes/magento2-graphql-view-model \
hyva-themes/magento2-compat-module-fallback
test -z "${COMPOSER_DEV_REQUIREMENTS}" || composer require -n --dev --prefer-dist --with-all-dependencies -- ${COMPOSER_DEV_REQUIREMENTS}
'
- name: Copy Composer cache out of PHP container
if: github.event.pull_request.head.repo.fork != true && !env.ACT
run: docker cp "$PHP_CONTAINER:$COMPOSER_CACHE_DIR/." /tmp/composer-cache/
- name: Setup Magento
run: |
ENV_ARGS=""
for VAR in $(env | grep -oE '^(MAGENTO|MYSQL|OPENSEARCH|DISABLE)_[A-Z_]+'); do
ENV_ARGS="$ENV_ARGS -e $VAR"
done
docker exec \
-u root \
-e COMPOSER_NAME \
$ENV_ARGS \
"$PHP_CONTAINER" bash -lc '
set -e
cd /tmp/magento
GITHUB_WORKSPACE=/tmp/magento/package-source /tmp/magento/package-source/.github/workflows/magento-install.sh
bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth Magento_TwoFactorAuth
bin/magento module:enable Yireo_EnableModuleSequence
EXTRA_MODULES=""
case "${COMPOSER_NAME}" in
loki-checkout/*)
EXTRA_MODULES="LokiCheckout_CoreCli LokiCheckout_Csp LokiCheckout_FunctionalTests LokiCheckout_Luma LokiCheckout_Hyva LokiCheckout_SampleData"
;;
esac
bin/magento module:sequence -n Loki_FunctionalTests Hyva_Theme Hyva_BaseLayoutReset Hyva_Email Hyva_GraphqlTokens Hyva_GraphqlViewModel Hyva_OrderCancellationWebapi Hyva_CompatModuleFallback ${EXTRA_MODULES} ${MAGENTO_MODULE}
bin/magento setup:upgrade
bin/magento config:set dev/static/sign 0
bin/magento setup:static-content:deploy -f --area frontend --area adminhtml en_US
case "${COMPOSER_NAME}" in
loki-checkout/*) bin/magento loki-checkout:sample-data:install ;;
esac
bin/magento loki:functional-tests:modules:dump
bin/magento config:set loki/functional_tests/token loki
bin/magento cache:flush config
'
- name: Copy Magento into job container
run: |
mkdir -p /tmp/magento
docker cp "$PHP_CONTAINER:/tmp/magento/." /tmp/magento/
- name: Compute npm cache key
id: npm-cache-key
working-directory: /tmp/magento/vendor/loki/magento2-functional-tests/Test/Playwright/
run: |
LOCK_FILE=package-lock.json
test -f "$LOCK_FILE" || LOCK_FILE=package.json
echo "hash=$(sha256sum "$LOCK_FILE" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
- name: Restore npm cache
if: ${{ !env.ACT }}
uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: ~/.npm
key: npm-${{ steps.npm-cache-key.outputs.hash }}
restore-keys: |
npm-
- name: Wait for Magento front-end
run: |
echo "Waiting for Magento front-end at ${MAGENTO_BASE_URL}..."
for i in {1..60}; do
if curl -kfsS "${MAGENTO_BASE_URL}" >/dev/null; then
echo "OK"; exit 0
fi
echo -n "."
sleep 1
done
echo "ERROR: Magento front-end not reachable"; exit 1
- name: Install Playwright dependencies
working-directory: /tmp/magento/vendor/loki/magento2-functional-tests/Test/Playwright/
run: |
echo "Installing npm dependencies..."
if [ -f package-lock.json ]; then
npm ci --prefer-offline --ignore-scripts
else
npm install --prefer-offline --no-audit --no-fund --ignore-scripts
fi
npx playwright install --only-shell chromium
- name: Run Playwright tests
working-directory: /tmp/magento/vendor/loki/magento2-functional-tests/Test/Playwright/
env:
CI: "true"
MAGENTO_ROOT: /tmp/magento
INTEGRATION_DETAILS: ${{ secrets.INTEGRATION_DETAILS || '' }}
TEST_TIMEOUT: ${{ vars.TEST_TIMEOUT || '60000' }}
PLAYWRIGHT_RETRIES: ${{ vars.PLAYWRIGHT_RETRIES || '1' }}
PLAYWRIGHT_MAX_FAILURES: ${{ vars.PLAYWRIGHT_MAX_FAILURES || '5' }}
NODE_TLS_REJECT_UNAUTHORIZED: "0"
run: |
echo "Creating /tmp/magento/.env.playwright..."
printf "TEST_URL=%s\nTEST_TOKEN=loki\nMODULE_NAME=%s\n" "${MAGENTO_BASE_URL}" "${MAGENTO_MODULE}" > /tmp/magento/.env.playwright
echo "Running Playwright tests for project ${MAGENTO_MODULE}"
npx playwright test \
--project="${MAGENTO_MODULE}" \
--reporter=list \
--trace=off \
--retries="${PLAYWRIGHT_RETRIES}" \
--max-failures="${PLAYWRIGHT_MAX_FAILURES}"