896 lines (740 loc) · 30.2 KB
/
build-test-measure.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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
name: Build, test & measure
on:
push:
branches:
- develop
# Include all release branches.
- '[0-9]+.[0-9]+'
pull_request:
# Run workflow whenever a PR is opened, updated (synchronized), or marked ready for review.
types: [opened, synchronize, ready_for_review]
jobs:
pre-run:
name: 'Pre run'
runs-on: ubuntu-latest
outputs:
changed-file-count: ${{ steps.determine-file-counts.outputs.count }}
changed-php-count: ${{ steps.determine-file-counts.outputs.php-count }}
changed-css-count: ${{ steps.determine-file-counts.outputs.css-count }}
changed-js-count: ${{ steps.determine-file-counts.outputs.js-count }}
steps:
- name: Checkout including last 2 commits
# Fetch last 2 commits if it's not a PR, so that we can determine the list of modified files.
if: ${{ github.base_ref == null }}
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Checkout
# Do usual checkout if it's a PR.
if: ${{ github.base_ref != null }}
uses: actions/checkout@v2
- name: Fetch base branch
# Only fetch base ref if it's a PR.
if: ${{ github.base_ref != null }}
run: git fetch --depth=1 --no-tags origin ${{ github.base_ref }}
- name: Determine modified files for PR
if: ${{ github.base_ref != null }}
run: echo "MODIFIED_FILES=$(git diff --name-only FETCH_HEAD HEAD | base64 -w 0)" >> $GITHUB_ENV
- name: Determine modified files for commit
if: ${{ github.base_ref == null }}
run: echo "MODIFIED_FILES=$(git diff --name-only HEAD~1 HEAD | base64 -w 0)" >> $GITHUB_ENV
- id: determine-file-counts
name: Determine if modified files should make the workflow run continue
run: |
MODIFIED_FILES=$(echo "$MODIFIED_FILES" | base64 -d)
echo -e "Modified files:\n$MODIFIED_FILES\n"
FILE_COUNT=$(php -f bin/determine-modified-files-count.php "$IGNORE_PATH_REGEX" "$MODIFIED_FILES" --invert)
PHP_FILE_COUNT=$(php -f bin/determine-modified-files-count.php ".+\.php|composer\.(json|lock)" "$MODIFIED_FILES")
CSS_FILE_COUNT=$(php -f bin/determine-modified-files-count.php ".+\.s?css" "$MODIFIED_FILES")
JS_FILE_COUNT=$(php -f bin/determine-modified-files-count.php ".+\.(js|snap)|package\.(json|lock)" "$MODIFIED_FILES")
echo "Changed file count: $FILE_COUNT"
echo "Changed PHP file count: $PHP_FILE_COUNT"
echo "Changed CSS file count: $CSS_FILE_COUNT"
echo "Changed JS file count: $JS_FILE_COUNT"
echo "::set-output name=count::$FILE_COUNT"
echo "::set-output name=php-count::$PHP_FILE_COUNT"
echo "::set-output name=css-count::$CSS_FILE_COUNT"
echo "::set-output name=js-count::$JS_FILE_COUNT"
env:
# Ignore Paths:
# - .github/
# - !.github/workflows
# - .wordpress-org/
# - docs/
IGNORE_PATH_REGEX: \.github\/(?!workflows)|\.wordpress-org\/|docs\/
lint-css:
needs: pre-run
if: needs.pre-run.outputs.changed-css-count > 0
name: 'Lint: CSS'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
- name: Get npm cache directory
id: npm-cache
run: echo "::set-output name=dir::$(npm config get cache)"
- name: Configure npm cache
uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install Node dependencies
run: npm ci
env:
CI: true
- name: Detect coding standard violations (stylelint)
run: npm run lint:css
#-----------------------------------------------------------------------------------------------------------------------
lint-js:
name: 'Lint: JS'
needs: pre-run
if: needs.pre-run.outputs.changed-js-count > 0
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
- name: Get npm cache directory
id: npm-cache
run: echo "::set-output name=dir::$(npm config get cache)"
- name: Configure npm cache
uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install Node dependencies
run: npm ci
env:
CI: true
- name: Validate package.json
run: npm run lint:pkg-json
- name: Detect ESLint coding standard violations
if: >
github.event.pull_request.head.repo.fork == true ||
github.event.pull_request.user.login == 'dependabot[bot]'
run: npm run lint:js
- name: Generate ESLint coding standard violations report
# Prevent generating the ESLint report if PR is from a fork or authored by Dependabot.
if: >
! ( github.event.pull_request.head.repo.fork == true ||
github.event.pull_request.user.login == 'dependabot[bot]' )
run: npm run lint:js:report
continue-on-error: true
- name: Annotate code linting results
# The action cannot annotate the PR when run from a PR fork or was authored by Dependabot.
if: >
! ( github.event.pull_request.head.repo.fork == true ||
github.event.pull_request.user.login == 'dependabot[bot]' )
uses: ataylorme/eslint-annotate-action@1.2.0
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
report-json: 'lint-js-report.json'
#-----------------------------------------------------------------------------------------------------------------------
lint-php:
name: 'Lint: PHP'
needs: pre-run
if: needs.pre-run.outputs.changed-php-count > 0
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: cs2pr
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Configure Composer cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction
- name: Validate composer.json
run: composer --no-interaction validate --no-check-all
- name: Detect coding standard violations (PHPCS)
run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings
- name: Normalize composer.json
run: |
composer require --no-interaction --dev ergebnis/composer-normalize --ignore-platform-reqs
composer --no-interaction normalize --dry-run
#-----------------------------------------------------------------------------------------------------------------------
static-analysis-php:
name: 'Static Analysis: PHP'
runs-on: ubuntu-latest
needs: pre-run
if: needs.pre-run.outputs.changed-php-count > 0
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
# phpstan requires PHP 7.1+.
php-version: 7.4
extensions: dom, iconv, json, libxml, zip
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Configure Composer cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install
- name: Static Analysis (PHPStan)
run: vendor/bin/phpstan analyse
#-----------------------------------------------------------------------------------------------------------------------
unit-test-js:
name: 'Unit test: JS'
runs-on: ubuntu-latest
needs: pre-run
if: needs.pre-run.outputs.changed-js-count > 0
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
- name: Get npm cache directory
id: npm-cache
run: echo "::set-output name=dir::$(npm config get cache)"
- name: Configure npm cache
uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Setup Jest cache
uses: actions/cache@v2
with:
path: ~/.jest-cache
key: ${{ runner.os }}-jest
- name: Install Node dependencies
run: npm ci
env:
CI: true
- name: Run unit tests (with coverage)
run: npm run test:js -- --ci --cacheDirectory="$HOME/.jest-cache" --collectCoverage
- name: Upload code coverage report
uses: codecov/codecov-action@v1.5.2
with:
file: build/logs/lcov.info
flags: javascript
fail_ci_if_error: true
#-----------------------------------------------------------------------------------------------------------------------
e2e-test-js:
name: 'E2E test: JS'
needs: pre-run
if: needs.pre-run.outputs.changed-file-count > 0
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Configure Composer cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Get npm cache directory
id: npm-cache
run: echo "::set-output name=dir::$(npm config get cache)"
- name: Configure npm cache
uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install Node dependencies
run: npm ci
env:
CI: true
- name: Install Composer dependencies
run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction
- name: Build plugin
run: npm run build:js
- name: Start Docker environment
run: npm run env:start
env:
COMPOSE_INTERACTIVE_NO_CLI: true
- name: Run E2E tests
run: npm run test:e2e:ci
- name: Stop Docker environment
run: npm run env:stop
if: always()
env:
COMPOSE_INTERACTIVE_NO_CLI: true
#-----------------------------------------------------------------------------------------------------------------------
# Adapted from workflow for running PHP unit tests on google/web-stories-wp.
# See https://github.com/google/web-stories-wp/blob/cb2ebada48039171e25c279bdb27d3712dd70b22/.github/workflows/continuous-integration-unit-php.yml
unit-test-php:
name: "Unit test${{ matrix.coverage && ' (with coverage)' || '' }}: PHP ${{ matrix.php }}, WP ${{ matrix.wp }}"
runs-on: ubuntu-latest
needs: pre-run
if: needs.pre-run.outputs.changed-file-count > 0
env:
WP_CORE_DIR: /tmp/wordpress
services:
mysql:
image: mariadb:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE: wordpress_test
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
continue-on-error: ${{ matrix.experimental == true }}
strategy:
fail-fast: false
matrix:
coverage: [false]
external-http: [false]
install-pwa-plugin: [true]
php: ['7.3', '7.2', '7.1']
wp: ['latest']
include:
- php: '8.0'
wp: 'trunk'
experimental: true
coverage: false
install-pwa-plugin: true
- php: '7.4'
wp: 'latest'
external-http: true
coverage: false
install-pwa-plugin: true
- php: '7.4'
wp: 'latest'
install-pwa-plugin: true
coverage: true
- php: '7.0'
wp: '5.1'
coverage: false
install-pwa-plugin: true
- php: '5.6'
wp: '5.0'
coverage: false
install-pwa-plugin: true
- php: '5.6'
wp: '4.9'
external-http: true
install-pwa-plugin: false
coverage: false
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, date, dom, gd, iconv, json, libxml, mysql, spl
coverage: ${{ matrix.coverage && 'pcov' || 'none' }}
ini-values: pcov.directory=.
- name: Shutdown default MySQL service
run: sudo service mysql stop
- name: Verify MariaDB connection
run: |
while ! mysqladmin ping -h"127.0.0.1" -P"${{ job.services.mysql.ports[3306] }}" --silent; do
sleep 1
done
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Configure Composer cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --prefer-dist --ignore-platform-reqs --no-progress --no-interaction
- name: Get npm cache directory
id: npm-cache
run: echo "::set-output name=dir::$(npm config get cache)"
- name: Configure npm cache
uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install Node dependencies
run: npm ci
env:
CI: true
- name: Build plugin
run: npm run build:js
# Scan the logs for failing tests and surface that information by creating annotations and log file decorations.
- name: Setup problem matcher to provide annotations for PHPUnit
# The JSON file is provided by the `shivammathur/setup-php` action. See https://github.com/shivammathur/setup-php#problem-matchers.
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install WP tests
run: bash bin/ci/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wp }} true
- name: Post install of WP tests
run: bash bin/ci/after-wp-install.sh ${{ matrix.wp }} ${{ matrix.install-pwa-plugin == true }} /tmp/wordpress-tests
- name: Setup PCOV
if: ${{ matrix.coverage == true }}
# phpdocumentor/reflection has to be removed as it makes use of an outdated dependency, making pcov/clobber
# unable to be installed.
run: |
composer remove --dev phpdocumentor/reflection
composer require --dev --ignore-platform-reqs pcov/clobber
vendor/bin/pcov clobber
- name: Copy plugin to WP plugins directory
run: cp -r "$PWD" "$WP_CORE_DIR/src/wp-content/plugins/amp"
- name: Run tests
if: ${{ matrix.coverage == false }}
run: vendor/bin/phpunit
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp
- name: Run tests with coverage
if: ${{ matrix.coverage == true }}
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp
- name: Run external HTTP tests
if: ${{ matrix.external-http == true }}
run: vendor/bin/phpunit --testsuite external-http
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp
- name: Upload code coverage report
if: ${{ matrix.coverage == true }}
uses: codecov/codecov-action@v1.5.2
with:
file: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp/build/logs/clover.xml
flags: php,unit
fail_ci_if_error: true
#-----------------------------------------------------------------------------------------------------------------------
feature-test-php:
name: "Feature test${{ matrix.coverage && ' (with coverage)' || '' }}: PHP ${{ matrix.php }}, WP ${{ matrix.wp }}"
needs: pre-run
if: needs.pre-run.outputs.changed-file-count > 0
runs-on: ubuntu-latest
env:
WP_VERSION: ${{ matrix.wp }}
services:
mysql:
image: mariadb:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE: wordpress_test
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
continue-on-error: ${{ matrix.experimental == true }}
strategy:
fail-fast: false
matrix:
coverage: [false]
php: ['7.3', '7.2', '7.1']
wp: ['latest']
include:
- php: '8.0'
wp: 'trunk'
experimental: true
coverage: false
- php: '7.4'
wp: 'latest'
coverage: false
# TODO: Enable this once codecov upload merging works as expected.
# - php: '7.4'
# wp: 'latest'
# coverage: true
- php: '7.0'
wp: '5.1'
coverage: false
- php: '5.6'
wp: '5.0'
coverage: false
- php: '5.6'
wp: '4.9'
coverage: false
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, date, dom, gd, iconv, json, libxml, mysql, spl
coverage: ${{ matrix.coverage && 'pcov' || 'none' }}
ini-values: pcov.directory=.
- name: Shutdown default MySQL service
run: sudo service mysql stop
- name: Verify MariaDB connection
run: |
while ! mysqladmin ping -h"127.0.0.1" -P"${{ job.services.mysql.ports[3306] }}" --silent; do
sleep 1
done
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Configure Composer cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --prefer-dist --ignore-platform-reqs --no-progress --no-interaction
- name: Get npm cache directory
id: npm-cache
run: echo "::set-output name=dir::$(npm config get cache)"
- name: Configure npm cache
uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install Node dependencies
run: npm ci
env:
CI: true
- name: Build plugin
run: npm run build:js
- name: Update PHPUnit to get latest php-code-coverage library
if: ${{ matrix.coverage == true }}
# phpdocumentor/reflection has to be removed as it makes use of an outdated dependency.
# phpunit/phpunit has to be updated as the one in use provides an older version of phpunit/php-code-coverage,
# but we need the v9.x branch.
# It cannot be removed, as it is a requirement of wp-cli/wp-cli-tests as well.
run: |
composer remove --dev phpdocumentor/reflection
composer require --dev --ignore-platform-reqs --update-with-all-dependencies phpunit/phpunit
- name: Configure DB environment
run: |
export MYSQL_HOST=127.0.0.1
export MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}
echo "WP_CLI_TEST_DBROOTUSER=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBROOTPASS=" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBUSER=wp_cli_test" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBPASS=password1" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBHOST=$MYSQL_HOST:$MYSQL_TCP_PORT" >> $GITHUB_ENV
- name: Prepare test database
run: composer prepare-tests
- name: Run tests
env:
BEHAT_CODE_COVERAGE: ${{ matrix.coverage }}
run: vendor/bin/behat
- name: Retrieve list of coverage files
if: ${{ matrix.coverage == true }}
run: |
FILES=$(ls -d -1 "$GITHUB_WORKSPACE/build/logs/clover-behat/"*.* | xargs echo | sed 's/ /,/g')
echo $FILES
echo "COVERAGE_FILES=$FILES" >> $GITHUB_ENV
- name: Upload code coverage report
if: ${{ matrix.coverage == true }}
uses: codecov/codecov-action@v1.5.2
with:
files: ${{ env.COVERAGE_FILES }}
flags: php,feature
fail_ci_if_error: true
#-----------------------------------------------------------------------------------------------------------------------
build-zip:
name: 'Build: ${{ matrix.build }} build ZIP'
# Only run if the PR was not authored by Dependabot and it is not a draft or not from a fork.
if: >
needs.pre-run.outputs.changed-file-count > 0 &&
github.event.pull_request.draft == false &&
github.event.pull_request.head.repo.fork == false &&
github.event.pull_request.user.login != 'dependabot[bot]'
needs: pre-run
runs-on: ubuntu-latest
outputs:
branch-name: ${{ steps.retrieve-branch-name.outputs.branch_name }}
git-sha-8: ${{ steps.retrieve-git-sha-8.outputs.sha8 }}
strategy:
matrix:
build: ['dev', 'prod']
steps:
- name: Check out source files
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Configure Composer cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
# Scripts are not ignored as they are needed to apply patches for the
# `sabberworm/php-css-parser` dependency.
run: composer install --prefer-dist --optimize-autoloader
- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- name: Configure npm cache
uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install Node dependencies
run: npm ci
env:
CI: true
- name: Create destination directories
run: mkdir -p builds/${{ matrix.build }}
- name: Build plugin
run: |
npm run build:${{ matrix.build }}
mv amp.zip builds/${{ matrix.build }}/amp.zip
env:
LAST_PR_COMMIT_HASH: ${{ github.event.pull_request.head.sha }}
- name: Retrieve branch name
id: retrieve-branch-name
run: echo "::set-output name=branch_name::$(REF=${GITHUB_HEAD_REF:-$GITHUB_REF} && echo ${REF#refs/heads/} | sed 's/\//-/g')"
- name: Retrieve git SHA-8 string
id: retrieve-git-sha-8
run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)"
- name: Upload build as artifact
uses: actions/upload-artifact@v2
with:
name: amp-${{ steps.retrieve-branch-name.outputs.branch_name }}-${{ steps.retrieve-git-sha-8.outputs.sha8 }}-${{ matrix.build }}
path: builds/${{ matrix.build }}
#-----------------------------------------------------------------------------------------------------------------------
upload-to-gcs:
name: Upload plugin ZIPs to Google Cloud Storage
runs-on: ubuntu-latest
needs:
- build-zip
steps:
- name: Download dev build
uses: actions/download-artifact@v2
with:
name: amp-${{ needs.build-zip.outputs.branch-name }}-${{ needs.build-zip.outputs.git-sha-8 }}-dev
path: builds/dev
- name: Download prod build
uses: actions/download-artifact@v2
with:
name: amp-${{ needs.build-zip.outputs.branch-name }}-${{ needs.build-zip.outputs.git-sha-8 }}-prod
path: builds/prod
- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@master
with:
project_id: ${{ secrets.GCS_PROJECT_ID }}
service_account_key: ${{ secrets.GCS_APPLICATION_CREDENTIALS }}
- name: Upload dev build to bucket
run: gsutil cp -r builds/dev/amp.zip gs://ampwp_github_artifacts/${{ github.ref }}/dev/amp.zip
- name: Upload prod build to bucket
run: gsutil cp -r builds/prod/amp.zip gs://ampwp_github_artifacts/${{ github.ref }}/prod/amp.zip
#-----------------------------------------------------------------------------------------------------------------------
comment-on-pr:
name: Comment on PR with links to plugin ZIPs
# Only run this job if it's a PR. One way to check for that is if `github.head_ref` is not empty.
if: ${{ github.head_ref && github.head_ref != null }}
runs-on: ubuntu-latest
needs: upload-to-gcs
outputs:
comment_body: ${{ steps.get-comment-body.outputs.body }}
steps:
- name: Check if a comment was already made
id: find-comment
uses: peter-evans/find-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: github-actions[bot]
body-includes: Plugin builds for
- name: Get comment body
id: get-comment-body
# Setting a multi-line output requires escaping line-feeds. See <https://github.community/t/set-output-truncates-multiline-strings/16852/3>.
run: |
body="Plugin builds for ${{ github.event.pull_request.head.sha }} are ready :bellhop_bell:!
- Download [development build](https://storage.googleapis.com/ampwp_github_artifacts/${{ github.ref }}/dev/amp.zip?${{ github.sha }})
- Download [production build](https://storage.googleapis.com/ampwp_github_artifacts/${{ github.ref }}/prod/amp.zip?${{ github.sha }})"
body="${body//$'\n'/'%0A'}"
echo "::set-output name=body::$body"
- name: Create comment on PR with links to plugin builds
if: ${{ steps.find-comment.outputs.comment-id == '' }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.get-comment-body.outputs.body }}
- name: Update comment on PR with links to plugin builds
if: ${{ steps.find-comment.outputs.comment-id != '' }}
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: ${{ steps.get-comment-body.outputs.body }}