-
Notifications
You must be signed in to change notification settings - Fork 167
487 lines (418 loc) · 18.6 KB
/
behat.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
name: 'Behat'
# Controls when the workflow will run
on:
# Triggers the workflow on all pull request events
pull_request: { }
# Trigger workflow for release branches.
push:
branches:
- main
- "[0-9]+.[0-9]+.x"
# We use the default concurrency grouping of allowing a single workflow per branch/PR/tag to run at the same time.
# In case of PRs we only care about the results for the last workflow run, so we cancel workflows already in progress
# when new code is pushed, in all other cases (branches/tags) we want to have a history for commits so it's easier to
# find breakages when they occur (head_ref is non-empty only when the workflow is triggered from a PR).
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.head_ref != '' }}
# github.head_ref is only set when the workflow was triggered by a pull_request and it contains the value of the source branch of the PR.
# github.ref_name will than only be used if the workflow was not triggered by a pull_request and it also just contains the branch name.
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
feature_discovery:
name: "Feature Discovery"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: sudo apt-get install jq
- name: Find feature files
id: set-matrix
run: |
echo -n "features=" >> $GITHUB_OUTPUT
cd tests/behat/features/capabilities
find * -type d -exec sh -c "ls {} | grep '\.feature$' > /dev/null" ';' -print | jq -R -s -c 'split("\n") | map(select(length > 0))' >> $GITHUB_OUTPUT
outputs:
features: ${{ steps.set-matrix.outputs.features }}
install_previous_open_social:
name: "Install previous Open Social major version"
runs-on: ubuntu-22.04
container:
image: goalgorilla/open_social_docker:ci-drupal10-php8.1-v2
volumes:
- ${{ github.workspace }}:/var/www
strategy:
matrix:
with_optional:
- ""
- "with-optional"
services:
db:
image: mariadb:10.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: social
mailcatcher:
image: schickling/mailcatcher
env:
VIRTUAL_HOST: mailcatcher.social.dev
VIRTUAL_PORT: 1080
ports:
- "1080"
redis:
image: redis:latest
solr:
image: ghcr.io/goalgorilla/ci-solr:8.11
env:
SOLR_SOLR_MEM_SIZE: 512m
PARTIAL_SEARCH_ENABLED: 0
options: --health-cmd="solr status" --health-interval=10s --health-timeout=5s --health-retries=3
defaults:
run:
shell: bash
working-directory: /var/www
steps:
- uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/tmp
# Checkout Drupal Social.
- name: Prepare composer
run: |
cp tmp/tests/composer.json composer.json
- name: Set-up the previous major version of Open Social
run: |
set -e
apt-get update
apt-get install -y jq
# This gets all version info from composer for Open Social. We then
# use jq to traverse and manipulate the JSON data to find ourselves
# the current stable major version.
PREVIOUS_MAJOR=`composer info -a --format json goalgorilla/open_social | jq '.versions | map(select(contains("-") == false)) | map(split(".")[0] | tonumber) | unique | reverse | .[0]'`
echo "Setting up update test from Open Social $PREVIOUS_MAJOR"
# Also include a hardcoded version for instaclick/php-webdriver, drupal/dynamic_entity_reference and drupal/core
# as we didnt lock the version, and the patch isn't applying on the latest, so we require it
# specifically to match the version that was installed at that moment in time.
composer require goalgorilla/open_social:~$PREVIOUS_MAJOR instaclick/php-webdriver:1.4.16
# Installation
# This is purposefully duplicated because we may change how
# installation works between major versions, so this provides us the
# flexibility to reflect that in the workflow.
cp tmp/tests/default.settings.php /var/www/html/sites/default/default.settings.php
mkdir /var/www/files_private
export OPTIONAL=""
if [[ "${{ matrix.with_optional }}" == "with-optional" ]]; then
export OPTIONAL="social_module_configure_form.select_all='TRUE'"
fi
drush site-install -y social --db-url=mysql://root:root@db:3306/social $OPTIONAL install_configure_form.update_status_module='array(FALSE,FALSE)' --site-name='Open Social' > >(tee install-output.log) 2> >(tee install-error.log >&2)
drush en flexible_permissions
# Dump the database to our test-output folder so that we can locally
# debug if the update fails.
mkdir -p behat-test-output
if [[ "${{ matrix.with_optional }}" == "with-optional" ]]; then
drush sql-dump > behat-test-output/pre-update-with-optional.sql
else
drush sql-dump > behat-test-output/pre-update.sql
fi
# Ensure there are no warnings or errors in the install-*.log.
# We do this after the database dump because drush doesn't actually
# exit, so this makes debugging easier.
if grep -E '\[warning\]' install-output.log install-error.log 1>/dev/null || grep -E '\[error\]' install-output.log install-error.log 1>/dev/null; then
# Move the install-*.log with warnings/errors and status messages to the test output. The text is viewable on
# GitHub too but some people might find it easier to just download the artifact and get digging.
if [[ "${{ matrix.with_optional }}" == "with-optional" ]]; then
mv install-output.log behat-test-output/pre-update-install-output-with-optional.log
mv install-error.log behat-test-output/pre-update-install-error-with-optional.log
else
mv install-output.log behat-test-output/pre-update-install-output.log
mv install-error.log behat-test-output/pre-update-install-error.log
fi
# Abort our testing until the warning/error is fixed and let our user know why we stopped.
echo "The drush install output should not contain any warnings or errors"
exit 1
fi
# Remove the composer files since we'll recreate this in the update.
rm composer.*
- name: Clean up checkout
run: rm -r tmp
- name: Package up previous version
uses: actions/cache@v4
with:
path: ${{ github.workspace }}
key: ${{ github.sha }}-previous-version-${{ matrix.with_optional }}
install_open_social:
needs: [install_previous_open_social]
name: "Install Open Social"
runs-on: ubuntu-22.04
container:
image: goalgorilla/open_social_docker:ci-drupal10-php8.1-v2
volumes:
- ${{ github.workspace }}:/var/www
strategy:
matrix:
update:
- ""
- "update"
with_optional:
- ""
- "with-optional"
services:
db:
image: mariadb:10.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: social
mailcatcher:
image: schickling/mailcatcher
env:
VIRTUAL_HOST: mailcatcher.social.dev
VIRTUAL_PORT: 1080
ports:
- "1080"
redis:
image: redis:latest
solr:
image: ghcr.io/goalgorilla/ci-solr:8.11
env:
SOLR_SOLR_MEM_SIZE: 512m
PARTIAL_SEARCH_ENABLED: 0
defaults:
run:
shell: bash
working-directory: /var/www
steps:
- name: Retrieve previous version
if: ${{ matrix.update == 'update' }}
uses: actions/cache@v4
with:
fail-on-cache-miss: true
path: ${{ github.workspace }}
key: ${{ github.sha }}-previous-version-${{ matrix.with_optional }}
- uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/tmp
- name: Composer install to HEAD
run: |
set -e
cp tmp/tests/composer.json composer.json
# Composer has special handling for "version-like" branch names
if [[ $BRANCH_NAME =~ [0-9]+\.[0-9]+\.x ]]; then
composer require goalgorilla/open_social:$BRANCH_NAME-dev
else
composer require goalgorilla/open_social:dev-$BRANCH_NAME
fi
composer install
cp tmp/tests/default.settings.php /var/www/html/sites/default/default.settings.php
mkdir -p /var/www/files_private
rm -r tmp/
- name: Update the previous major version to HEAD
if: ${{ matrix.update == 'update' }}
run: |
set -e
if [[ "${{ matrix.with_optional }}" == "with-optional" ]]; then
drush sqlc < behat-test-output/pre-update-with-optional.sql
else
drush sqlc < behat-test-output/pre-update.sql
fi
vendor/bin/drush updb -y 2> >(tee update.log >&2)
# Ensure there are no warnings or requirements errors in the update.log
if grep -E '^>\s+\[warning\]\s' update.log 1>/dev/null || grep 'Requirements check reports errors. Do you wish to continue?' update.log 1>/dev/null; then
# Move the update.log with warnings/errors and status messages to the test output. The text is viewable on
# GitHub too but some people might find it easier to just download the artifact and get digging.
if [[ "${{ matrix.with_optional }}" == "with-optional" ]]; then
mv update.log behat-test-output/update-with-optional.log
else
mv update.log behat-test-output/update.log
fi
# Abort our testing until the warning/error is fixed and let our user know why we stopped.
echo "The drush output should not contain any warnings or requirements errors"
exit 1
fi
- name: Set-up a new Open Social installation at HEAD
if: ${{ matrix.update == '' }}
run: |
set -e
export OPTIONAL=""
if [[ "${{ matrix.with_optional }}" == "with-optional" ]]; then
export OPTIONAL="social_module_configure_form.select_all='TRUE'"
fi
drush site-install -y social --db-url=mysql://root:root@db:3306/social $OPTIONAL install_configure_form.update_status_module='array(FALSE,FALSE)' --site-name='Open Social' > >(tee install-output.log) 2> >(tee install-error.log >&2)
- name: Dump Database
run: |
mkdir -p behat-test-output
if [[ ! -z "${{ matrix.update }}" ]] && [[ ! -z "${{ matrix.with_optional }}" ]]; then
drush sql:dump > behat-test-output/installation-update-with-optional.sql
elif [[ ! -z "${{ matrix.update }}" ]]; then
drush sql:dump > behat-test-output/installation-update.sql
elif [[ ! -z "${{ matrix.with_optional }}" ]]; then
drush sql:dump > behat-test-output/installation-with-optional.sql
else
drush sql:dump > behat-test-output/installation.sql
fi
- name: Validate install contained no errors
if: ${{ matrix.update == '' }}
run: |
# Ensure there are no warnings or errors in the install-*.log.
# We do this after database dumping to help debugging.
if grep -E '\[warning\]' install-output.log install-error.log 1>/dev/null || grep -E '\[error\]' install-output.log install-error.log 1>/dev/null; then
# Move the install-*.log with warnings/errors and status messages to the test output. The text is viewable on
# GitHub too but some people might find it easier to just download the artifact and get digging.
if [[ "${{ matrix.with_optional }}" == "with-optional" ]]; then
mv install-output.log behat-test-output/install-output-with-optional.log
mv install-error.log behat-test-output/install-error-with-optional.log
else
mv install-output.log behat-test-output/install-output.log
mv install-error.log behat-test-output/install-error.log
fi
# Abort our testing until the warning/error is fixed and let our user know why we stopped.
echo "The drush install output should not contain any warnings or errors"
exit 1
fi
- name: Fix owner of web files
run: chown -R www-data:www-data /var/www
- name: Package up site
uses: actions/cache@v4
with:
path: ${{ github.workspace }}
key: ${{ github.sha }}-test-setup-${{ matrix.update}}${{ matrix.with_optional }}
- name: Upload Installation database
if: failure()
uses: actions/upload-artifact@v3
with:
name: behat-test-output
path: behat-test-output
# This workflow contains a single job called "Running tests"
tests:
needs: [feature_discovery, install_open_social]
name: 'Tests'
runs-on: ubuntu-22.04
container:
image: goalgorilla/open_social_docker:ci-drupal10-php8.1-v2
volumes:
- ${{ github.workspace }}:/var/www
strategy:
fail-fast: false
matrix:
feature: ${{ fromJson(needs.feature_discovery.outputs.features) }}
update:
- ""
- "update"
with_optional:
- ""
- "with-optional"
services:
web:
image: goalgorilla/open_social_docker:ci-drupal10-php8.1-v2
env:
DRUPAL_SETTINGS: production
volumes:
- ${{ github.workspace }}:/var/www
ports:
- "80"
db:
image: mariadb:10.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: social
mailcatcher:
image: schickling/mailcatcher
env:
VIRTUAL_HOST: mailcatcher.social.dev
VIRTUAL_PORT: 1080
ports:
- "1080"
redis:
image: redis:latest
solr:
image: ghcr.io/goalgorilla/ci-solr:8.11
env:
SOLR_SOLR_MEM_SIZE: 512m
PARTIAL_SEARCH_ENABLED: 0
chrome:
# We use an image based on zenika/alpine-chrome:latest so we can add
# the start-up arguments that we need.
image: kingdutch/social-docker-chrome
ports:
- '9222:9222'
defaults:
run:
shell: bash
working-directory: /var/www
steps:
- name: Download Site
uses: actions/cache@v4
with:
fail-on-cache-miss: true
path: ${{ github.workspace }}
key: ${{ github.sha }}-test-setup-${{ matrix.update}}${{ matrix.with_optional }}
# We could run all tests at once by passing the folder directly to behat
# however, by doing this manually in a loop we have the ability to ensure
# each test runs against a clean database cheaply.
- name: Run Integration test
run: |
if [[ ! -z "${{ matrix.update }}" ]] && [[ ! -z "${{ matrix.with_optional }}" ]]; then
export TEST_DATABASE=`pwd`/behat-test-output/installation-update-with-optional.sql
elif [[ ! -z "${{ matrix.update }}" ]]; then
export TEST_DATABASE=`pwd`/behat-test-output/installation-update.sql
elif [[ ! -z "${{ matrix.with_optional }}" ]]; then
export TEST_DATABASE=`pwd`/behat-test-output/installation-with-optional.sql
else
export TEST_DATABASE=`pwd`/behat-test-output/installation.sql
fi
vendor/bin/behat --version
for test in html/profiles/contrib/social/tests/behat/features/capabilities/${{ matrix.feature }}/*.feature; do
if head -n1 $test | grep -q "@disabled"; then
echo "$test - Skipping disabled test"
continue
fi
# If we're testing a clean install (i.e. not updating) then ignore
# any tests that have opted out of install testing.
if [[ -z "${{ matrix.update }}" ]]; then
export TAGS="--tags=~no-install"
# Do the same when we are testing with an update.
else
export TAGS="--tags=~no-update"
fi
# Tests with the @no-database tag import their own scaffold so they
# ignore the databases provided by our test matrix, that's why we
# only run them once when all our matrix values are off.
if [[ ! -z "${{ matrix.update }}" ]] || [[ ! -z "${{ matrix.with_optional }}" ]]; then
export TAGS="$TAGS&&~no-database"
fi
echo "::group::$test"
# Run in subshell to make the test command visible and copyable.
(set -x; vendor/bin/behat -vv --config html/profiles/contrib/social/tests/behat/behat.yml --colors --allow-empty $TAGS $test)
echo "::endgroup::"
done
- name: Move test artifacts into upload folder
if: failure()
run: |
set -e
# Make the output folder
if [[ ! -z "${{ matrix.update }}" ]] && [[ ! -z "${{ matrix.with_optional }}" ]]; then
export OUTPUT_FOLDER=behat-test-output/${{ matrix.feature }}/update-with-optional
elif [[ ! -z "${{ matrix.update }}" ]]; then
export OUTPUT_FOLDER=behat-test-output/${{ matrix.feature }}/update
elif [[ ! -z "${{ matrix.with_optional }}" ]]; then
export OUTPUT_FOLDER=behat-test-output/${{ matrix.feature }}/with-optional
else
export OUTPUT_FOLDER=behat-test-output/${{ matrix.feature }}
fi
mkdir -p $OUTPUT_FOLDER
# Move test results to the output folder if they exist
if (shopt -s nullglob; f=(html/profiles/contrib/social/tests/behat/logs/*); ((${#f[@]}))); then
mv html/profiles/contrib/social/tests/behat/logs/* $OUTPUT_FOLDER/
fi
# Move files from the mail spool to the output folder if they exist
if (shopt -s nullglob; f=(html/profiles/contrib/social/tests/behat/mail-spool/*); ((${#f[@]}))); then
mv html/profiles/contrib/social/tests/behat/mail-spool/* $OUTPUT_FOLDER/
fi
# Dump the database with the state of the test failure to allow for
# local inspection.
drush sql-dump > $OUTPUT_FOLDER/at-test-failure.sql
- name: Upload Behat Test Output
if: failure()
uses: actions/upload-artifact@v3
with:
name: behat-test-output
path: behat-test-output