-
-
Notifications
You must be signed in to change notification settings - Fork 25
334 lines (300 loc) · 11.3 KB
/
tests.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
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
326
327
328
329
330
331
332
333
334
#
# GitHub action executed when a PR is opened, asked for a review
# For debugging purposes, also when the assignment is modified.
#
# For now, runs only the UI tests.
#
# This action requires a secret called ARTIFACTS_PASS which is the key to upload on build-artifacts.
# This value can be found in the development keepass database.
#
name: Matomo for WordPress Tests
on:
workflow_dispatch:
push:
schedule:
- cron: "0 0 * * 0"
permissions:
actions: read
checks: none
contents: read
deployments: none
issues: read
packages: none
pull-requests: read
repository-projects: none
security-events: none
statuses: none
id-token: write # for docker gha cache
concurrency:
group: php-${{ github.ref }}
cancel-in-progress: true
jobs:
unit_tests:
runs-on: 'ubuntu-20.04'
strategy:
fail-fast: false
matrix:
wp-versions: [ 'latest' ]
php-versions: [ '7.2', '8.1' ]
multisite: [ "singlesite", "multisite" ]
include:
- wp-versions: '5.2'
php-versions: '7.2'
multisite: 'singlesite'
- wp-versions: '5.2'
php-versions: '7.2'
multisite: 'multisite'
permissions:
contents: read # <--- allows to read repo
steps:
- name: Checkout project
uses: actions/checkout@v3
with:
persist-credentials: true
lfs: true
submodules: true
- run: git lfs pull
- name: Setup PHP ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: curl, dom, exif, fileinfo, hash, imagick, json, mbstring, mysqli, openssl, pcre, sodium, xml, zip
ini-values: |
post_max_size=8M,
memory_limit=256M,
max_execution_time=30,
always_populate_raw_post_data=-1,
error_reporting=E_ALL,
log_errors=on,
display_errors=on,
allow_url_fopen=on,
zend.exception_ignore_args=Off
tools: composer:v2
coverage: none
- name: Check PHP Version
run: php -v
# note: we update the dependencies since they only exist for the unit tests, and we need to use different
# versions of phpunit/etc. for different PHP versions
- name: Update test dependencies
shell: bash
run: |
if [[ "${{ matrix.wp-versions }}" = "5.2" ]]; then
sed -i 's%"yoast/phpunit-polyfills": ".*"%"yoast/phpunit-polyfills": "^1.1"%g' composer.json
fi
composer update --with-all-dependencies
- name: Install dependencies
shell: bash
run: composer install
# TODO: redundancy w/ e2e_tests, could be moved to a script
# docker-compose up
# TODO: i can't seem to get docker layer caching to work.
- run: |
export ACTIONS_CACHE_URL=$(echo "$ACTIONS_ID_TOKEN_REQUEST_URL" | grep -Po 'https://[^/]+/[^/]+/' | sed 's/pipelines/artifactcache/')
export ACTIONS_RUNTIME_TOKEN=$ACTIONS_ID_TOKEN_REQUEST_TOKEN
docker buildx build --cache-to type=gha --cache-from type=gha --build-arg PHP_VERSION=${{ matrix.php-versions }} --build-context project="${{ github.workspace }}/scripts" --file=scripts/Dockerfile.local scripts
env:
PHP_VERSION: ${{ matrix.php-versions }}
WOOCOMMERCE: 0
WORDPRESS_FOLDER: test
RESET_DATABASE: 1
WORDPRESS_VERSION: ${{ matrix.wp-versions }}
- run: |
cat > .env <<EOF
PHP_VERSION=$PHP_VERSION
WOOCOMMERCE=0
WORDPRESS_FOLDER=test
RESET_DATABASE=1
WORDPRESS_VERSION=$WORDPRESS_VERSION
UID=$UID
WP_DEBUG=true
EOF
env:
PHP_VERSION: ${{ matrix.php-versions }}
WORDPRESS_VERSION: ${{ matrix.wp-versions }}
- run: chmod -R 777 . # required to build the release
- run: sudo chown -R $UID:1000 . # required for wordpress' filesystem direct implementation
- run: docker compose --env-file .env.default --env-file .env up -d wordpress
- run: |
# wait for docker-compose launch to finish
elapsed=0
until [ -e ./docker/wordpress/test/setup_finished ] || (( elapsed++ >= 420 )); do
sleep 1
done
if [ ! -e ./docker/wordpress/test/setup_finished ]; then
echo "did not setup local environment in time"
exit 1
fi
[ -e /tmp/file.txt ] && echo File exists || echo Timeout
- run: npm run compose logs wordpress --no-color # for debugging failures to start
if: always()
- name: Run unit tests
shell: bash
run: |
if [[ "${{ matrix.multisite }}" == "singlesite" ]]; then
echo "Running in single site context"
else
echo "Running in multisite context"
cat >> .env <<EOF
WP_MULTISITE=1
EOF
fi
npm run phpunit
e2e_tests:
runs-on: 'ubuntu-22.04'
strategy:
fail-fast: false
matrix:
wp-versions: [ 'latest', 'trunk' ]
php-versions: [ '7.2', '8.1' ]
permissions:
contents: read # <--- allows to read repo
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
lfs: true
submodules: true
- run: git lfs pull
# setup xvfb
- run: sudo apt-get update && sudo apt-get install -y xvfb x11-xserver-utils xauth
# setup firefox
- uses: browser-actions/setup-firefox@v1
- run: firefox --version
# setup node
- uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
cache-dependency-path: '**/package-lock.json'
- run: npm install
# TODO: try to remove this after prefixing
# disable deprecation notices in e2e tests. we can't control much of the code being
# tested (ie, WordPress, other WordPress plugins), and it's very easy for one of them
# to trigger a deprecation notice
- name: Disable deprecation notices
shell: bash
run: |
mkdir docker
echo '[PHP]' > docker/php-custom.ini
echo 'error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE' >> docker/php-custom.ini
echo 'upload_max_filesize = 128M' >> docker/php-custom.ini
echo 'memory_limit = 2G' >> docker/php-custom.ini
echo 'max_execution_time = 600' >> docker/php-custom.ini
echo 'post_max_size = 128M' >> docker/php-custom.ini
# docker-compose up
# TODO: i can't seem to get docker layer caching to work.
- run: |
export ACTIONS_CACHE_URL=$(echo "$ACTIONS_ID_TOKEN_REQUEST_URL" | grep -Po 'https://[^/]+/[^/]+/' | sed 's/pipelines/artifactcache/')
export ACTIONS_RUNTIME_TOKEN=$ACTIONS_ID_TOKEN_REQUEST_TOKEN
docker buildx build --cache-to type=gha --cache-from type=gha --build-arg PHP_VERSION=${{ matrix.php-versions }} --build-context project="${{ github.workspace }}/scripts" --file=scripts/Dockerfile.local scripts
env:
PHP_VERSION: ${{ matrix.php-versions }}
WOOCOMMERCE: 1
WORDPRESS_FOLDER: test
RESET_DATABASE: 1
WORDPRESS_VERSION: ${{ matrix.wp-versions }}
- run: |
cat > .env <<EOF
PHP_VERSION=$PHP_VERSION
WOOCOMMERCE=1
WORDPRESS_FOLDER=test
WORDPRESS_VERSION=$WORDPRESS_VERSION
UID=$UID
WITHOUT_MARKETPLACE=1
WP_DEBUG=true
WP_DEBUG_LOG=true
WP_DEBUG_DISPLAY=false
EOF
env:
PHP_VERSION: ${{ matrix.php-versions }}
WORDPRESS_VERSION: ${{ matrix.wp-versions }}
- run: chmod -R 777 . # required to build the release
- run: docker compose --env-file .env.default --env-file .env up -d wordpress
- run: |
# wait for docker-compose launch to finish
elapsed=0
until [ -e ./docker/wordpress/test/setup_finished ] || (( elapsed++ >= 240 )); do
sleep 1
done
if [ ! -e ./docker/wordpress/test/setup_finished ]; then
echo "did not setup local environment in time"
exit 1
fi
[ -e /tmp/file.txt ] && echo File exists || echo Timeout
- run: npm run compose logs wordpress --no-color # for debugging failures to start
if: always()
# build release from current code
- run: |
npm run matomo:console -- wordpress:build-release --name=test --zip
mv matomo-test.zip matomo.zip
# restart wordpress but with latest stable matomo
- run: |
echo 'INSTALLING_FROM_ZIP=1' >> .env
docker compose --env-file .env.default --env-file .env stop wordpress
docker compose --env-file .env.default --env-file .env up -d wordpress
sleep 20
npm run compose logs wordpress --no-color
# run tests
- run: xvfb-run --auto-servernum npm run wdio
env:
PHP_VERSION: ${{ matrix.php-versions }}
WOOCOMMERCE: 1
WORDPRESS_FOLDER: test
WORDPRESS_VERSION: ${{ matrix.wp-versions }}
RELEASE_ZIP: ${{ github.workspace }}/matomo.zip
TEST_SHOP_LICENSE: ${{ secrets.TEST_SHOP_LICENSE }}
- name: Archive test artifacts (actual)
uses: actions/upload-artifact@v4
if: always()
with:
name: actual-screenshots-${{ matrix.php-versions }}-${{ matrix.wp-versions }}
path: tests/e2e/actual
- name: Archive test artifacts (diffs)
uses: actions/upload-artifact@v4
if: always()
with:
name: diff-screenshots-${{ matrix.php-versions }}-${{ matrix.wp-versions }}
path: tests/e2e/diff
# output docker-compose logs
- run: npm run compose logs wordpress --no-color
if: always()
- run: npm run compose stop
# output debug.concat.log (created in a hook in wdio.conf.ts)
- run: cat ./docker/wordpress/test/wp-content/debug.concat.log || echo "debug.concat.log file does not exist"
if: always()
checkstyle:
runs-on: 'ubuntu-20.04'
steps:
- name: Checkout project
uses: actions/checkout@v3
with:
persist-credentials: true
path: wp-content/plugins/matomo
submodules: true
- name: Setup PHP for checkstyle
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: curl, dom, exif, fileinfo, hash, imagick, json, mbstring, mysqli, openssl, pcre, sodium, xml, zip
ini-values: |
post_max_size=8M,
memory_limit=256M,
max_execution_time=30,
always_populate_raw_post_data=-1,
error_reporting=E_ALL,
log_errors=on,
display_errors=on,
allow_url_fopen=on,
zend.exception_ignore_args=Off
tools: composer:v2
coverage: none
- name: Check PHP Version
run: php -v
- name: Install dependencies
shell: bash
run: |
cd ${{ github.workspace }}/wp-content/plugins/matomo && composer update --with-all-dependencies
cd ${{ github.workspace }}/wp-content/plugins/matomo && composer install
- name: Run checkstyle
shell: bash
run: cd ${{ github.workspace }}/wp-content/plugins/matomo && ./vendor/bin/phpcs