-
Notifications
You must be signed in to change notification settings - Fork 100
352 lines (293 loc) · 12.1 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
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-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@v4
with:
fetch-depth: 2
- name: Checkout
# Do usual checkout if it's a PR.
if: ${{ github.base_ref != null }}
uses: actions/checkout@v4
- 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)|phpstan\.neon\.dist|phpunit\.xml" "$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 JS file count: $JS_FILE_COUNT"
echo "count=$FILE_COUNT" >> $GITHUB_OUTPUT
echo "php-count=$PHP_FILE_COUNT" >> $GITHUB_OUTPUT
echo "js-count=$JS_FILE_COUNT" >> $GITHUB_OUTPUT
env:
# Ignore Paths:
# - .github/
# - !.github/workflows
# - .wordpress-org/
IGNORE_PATH_REGEX: \.github\/(?!workflows)|\.wordpress-org\/
#-----------------------------------------------------------------------------------------------------------------------
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@v4
- name: Setup Node
uses: actions/setup-node@v4.0.3
with:
node-version-file: '.nvmrc'
cache: 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@2.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@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: cs2pr
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Configure Composer cache
uses: actions/cache@v4
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: vendor/bin/composer-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@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
# phpstan requires PHP 7.1+.
php-version: '8.0'
extensions: dom, iconv, json, libxml, zip
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Configure Composer cache
uses: actions/cache@v4
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 --version
vendor/bin/phpstan
#-----------------------------------------------------------------------------------------------------------------------
# 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
WP_TESTS_DIR: /tmp/wordpress-tests-lib
WP_ENVIRONMENT_TYPE: local
services:
mysql:
image: mariadb:latest
env:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
MARIADB_DATABASE: wordpress_test
MARIADB_MYSQL_LOCALHOST_USER: 1
MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE
ports:
- 3306
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --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']
phpunit: ['7']
include:
- php: '8.3'
wp: 'trunk'
coverage: false
phpunit: '9.6'
- php: '8.2'
wp: 'trunk'
coverage: false
phpunit: '9.6'
- php: '8.1'
wp: 'latest'
coverage: false
phpunit: '9.6'
- php: '8.0'
wp: 'latest'
coverage: false
phpunit: '9.3'
- php: '7.4'
wp: 'latest'
coverage: false
phpunit: '9.3'
- php: '7.4'
wp: 'latest'
coverage: true
phpunit: '9.3'
- php: '7.0'
wp: '6.3'
coverage: false
phpunit: '6'
steps:
- name: Checkout
uses: actions/checkout@v4
- 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 && 'xdebug' || 'none' }}
tools: phpunit:${{ matrix.phpunit }}
- 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: Setup Node
uses: actions/setup-node@v4.0.3
with:
node-version-file: '.nvmrc'
cache: npm
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Configure Composer cache
uses: actions/cache@v4
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: Install Node dependencies
run: npm ci
env:
CI: true
- name: Build plugin
run: npm run build
# Avoid conflicts with globally installed PHPUnit.
- name: Remove locally installed PHPUnit
if: needs.pre-run.outputs.changed-php-count > 0
run: |
rm -rf vendor/phpunit
composer dump-autoload -o
# 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: Copy plugin to WP plugins directory
run: cp -r "$PWD" "$WP_CORE_DIR/src/wp-content/plugins/pwa"
- name: Run tests
if: ${{ matrix.coverage == false }}
run: phpunit --verbose
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/pwa
- name: Run tests with coverage
if: ${{ matrix.coverage == true }}
run: phpunit --verbose --coverage-clover build/logs/clover.xml
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/pwa
- name: Upload code coverage report
if: ${{ matrix.coverage == true }}
uses: codecov/codecov-action@v3
with:
file: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/pwa/build/logs/clover.xml
flags: php,unit
fail_ci_if_error: true