-
Notifications
You must be signed in to change notification settings - Fork 178
190 lines (164 loc) · 6.29 KB
/
tests-unit-php.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
name: PHP Unit Tests
on:
push:
# Only run if PHP-related files changed.
paths:
- '**.php'
- 'phpunit.xml.dist'
- 'phpunit-multisite.xml.dist'
- 'composer.json'
- 'composer.lock'
- 'tests/phpunit/**'
- 'includes/data/**'
- '.github/workflows/tests-unit-php.yml'
branches:
- main
- release/*
pull_request:
# Only run if PHP-related files changed.
paths:
- '**.php'
- 'phpunit.xml.dist'
- 'phpunit-multisite.xml.dist'
- 'composer.json'
- 'composer.lock'
- 'tests/phpunit/**'
- 'includes/data/**'
- '.github/workflows/tests-unit-php.yml'
permissions:
contents: read
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the (target) branch name.
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
unit-php:
name: PHP ${{ matrix.php }} - WP ${{ matrix.wp }}${{ matrix.experimental && ' (experimental)' || '' }}${{ matrix.coverage && ' (with coverage)' || '' }}${{ matrix.random && ' (in random order)' || '' }}
runs-on: ubuntu-latest
timeout-minutes: 20
services:
mysql:
image: mariadb:lts
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 }}
strategy:
matrix:
php: ['8.3', '8.2', '8.1', '8.0']
wp: ['latest']
coverage: [false]
experimental: [false]
include:
- php: '8.4'
wp: 'latest'
coverage: true
experimental: false
- php: '8.4'
wp: 'latest'
random: true
experimental: true
- php: '7.4'
wp: '6.5'
experimental: false
- php: '8.4'
wp: 'trunk'
experimental: true
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f
with:
disable-file-monitoring: true
egress-policy: audit
allowed-endpoints: >
api.github.com:443
api.wordpress.org:80
cdn.ampproject.org:443
develop.svn.wordpress.org:443
example.com:443
github.com:443
objects.githubusercontent.com:443
packagist.org:443
raw.github.com:443
repo.packagist.org:443
wordpress.org:443
getcomposer.org:443
dl.cloudsmith.io:443
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# PHP-Scoper only works on PHP 7.4+ and we need to prefix our dependencies to accurately test them.
# So we temporarily switch PHP versions, do a full install and then remove the package.
# Then switch back to the PHP version we want to test and delete the vendor directory.
- name: Setup PHP 8.0
uses: shivammathur/setup-php@e6f75134d35752277f093989e72e140eaa222f35
with:
php-version: '8.0'
tools: composer
- name: Install PHP dependencies
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a
with:
composer-options: '--prefer-dist --no-progress --no-interaction'
- name: Remove prefixed dependencies
run: rm -rf vendor/*
- name: Setup PHP
uses: shivammathur/setup-php@e6f75134d35752277f093989e72e140eaa222f35
with:
php-version: ${{ matrix.php }}
extensions: mysql
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
tools: composer, cs2pr
- name: Install PHP dependencies
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a
with:
composer-options: '--prefer-dist --no-progress --no-interaction --no-scripts'
- name: Update PHPUnit
run: |
echo "Installing latest version of PHPUnit"
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
- name: Composer dump autoload
run: composer dump-autoload --no-interaction
- 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: Install svn
run: |
sudo apt-get update
sudo apt-get install -y subversion
- name: Set up tests
run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wp }} true
- name: Set up problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Run tests
run: |
npm run test:php:unit
npm run test:php:integration:single
npm run test:php:integration:multisite
if: ${{ ! matrix.coverage && ! matrix.random }}
- name: Run tests with coverage
run: |
npm run test:php:unit -- --coverage-clover build/logs/php-coverage.xml
npm run test:php:integration:single -- --coverage-clover build/logs/php-coverage-integration.xml
npm run test:php:integration:multisite -- --coverage-clover build/logs/php-coverage-multisite.xml
if: ${{ matrix.coverage && ! matrix.random }}
- name: Run tests in random order
run: |
npm run test:php:unit -- --order-by random
npm run test:php:integration:single -- --order-by random
npm run test:php:integration:multisite -- --order-by random
if: ${{ matrix.random }}
- name: Upload code coverage report
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a
with:
file: build/logs/*.xml
token: ${{ secrets.CODECOV_TOKEN }}
if: ${{ matrix.coverage }}