-
Notifications
You must be signed in to change notification settings - Fork 18
274 lines (239 loc) · 11.6 KB
/
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
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
name: PHP Tests
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
# Seems like we should be able to use these in the services section below
# to keep things DRY, but how?
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpressdb
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
MYSQL_PORT: 3306
MYSQL_HOST: 127.0.0.1
jobs:
build:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpressdb
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
ports:
- 3306:3306
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
wordpress: [latest]
include:
- php: '5.6'
wordpress: 5.2.5
- php: '8.3'
wordpress: trunk
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Validate composer.json and composer.lock
id: composer-lock
run: |
if [ ${{ matrix.php }} == '8.2' ]; then
composer validate
LOCK_FILE=composer.lock
COMPOSER_FILE=composer.json
else
COMPOSER=composer-php${{ matrix.php }}.json composer validate
LOCK_FILE=composer-php${{ matrix.php }}.lock
COMPOSER_FILE=composer-php${{ matrix.php }}.json
fi
echo "COMPOSER_LOCK_HASH=$(md5sum $LOCK_FILE | cut -d' ' -f1)" >> $GITHUB_OUTPUT
echo "COMPOSER_FILE=${COMPOSER_FILE}" >> $GITHUB_OUTPUT
- name: Resolve Cache Date
id: cache-date
run: echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-b-${{ steps.composer-lock.outputs.COMPOSER_LOCK_HASH }}
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: COMPOSER=${{ steps.composer-lock.outputs.COMPOSER_FILE }} composer install --prefer-dist --no-progress
- name: Cache APT Sources Daily
id: apt-sources-cache
uses: actions/cache@v3
with:
path: /tmp/apt-sources-${{ steps.cache-date.outputs.DATE }}
key: ${{ runner.os }}-apt-sources-${{ steps.cache-date.outputs.DATE }}
- name: Cache APT Packages Daily
id: apt-packages-cache
uses: actions/cache@v3
with:
path: /tmp/apt-packages-${{ steps.cache-date.outputs.DATE }}
key: ${{ runner.os }}-apt-packages-${{ steps.cache-date.outputs.DATE }}
- name: Update APT Sources
if: steps.apt-sources-cache.outputs.cache-hit != 'true'
run: |
sudo apt-get update
mkdir -p /tmp/apt-sources-${{ steps.cache-date.outputs.DATE }}
sudo cp -R /var/lib/apt/lists/* /tmp/apt-sources-${{ steps.cache-date.outputs.DATE }}
- name: Download APT Packages
if: steps.apt-packages-cache.outputs.cache-hit != 'true'
run: |
sudo cp -R /tmp/apt-sources-${{ steps.cache-date.outputs.DATE }}/* /var/lib/apt/lists
sudo apt-get install -y --download-only subversion mysql-client
sudo mkdir -p /tmp/apt-packages-${{ steps.cache-date.outputs.DATE }}
sudo cp -R /var/cache/apt/archives/*.deb /tmp/apt-packages-${{ steps.cache-date.outputs.DATE }}
- name: Install OS Packages
run: sudo dpkg -i /tmp/apt-packages-${{ steps.cache-date.outputs.DATE }}/*.deb
- name: Verify DB
run: mysql --user=root --password=${MYSQL_ROOT_PASSWORD} --host=${MYSQL_HOST} --port=${MYSQL_PORT} --protocol=tcp -e 'SHOW DATABASES;'
- name: Resolve WordPress Version
run: |
curl -s https://api.wordpress.org/core/version-check/1.7/ > /tmp/wp-latest.json
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//' | head -1)
if [ "${{ matrix.wordpress }}" == 'latest' ]; then
VERSION=$LATEST_VERSION
echo "WORDPRESS_VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "WORDPRESS_VERSION_IS_TRUNK=0" >> $GITHUB_OUTPUT
echo "WORDPRESS_CORE_DIR=/tmp/$VERSION" >> $GITHUB_OUTPUT
echo "WP_TESTS_TAG=branches/$VERSION" >> $GITHUB_OUTPUT
elif [ "${{ matrix.wordpress }}" == 'trunk' ]; then
VERSION=trunk-$(date +'%Y-%m-%d')
echo "WORDPRESS_VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "WORDPRESS_VERSION_IS_TRUNK=1" >> $GITHUB_OUTPUT
echo "WORDPRESS_CORE_DIR=/tmp/$VERSION" >> $GITHUB_OUTPUT
echo "WP_TESTS_TAG=trunk" >> $GITHUB_OUTPUT
else
VERSION=${{ matrix.wordpress }}
echo "WORDPRESS_VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "WORDPRESS_VERSION_IS_TRUNK=0" >> $GITHUB_OUTPUT
echo "WORDPRESS_CORE_DIR=/tmp/$VERSION" >> $GITHUB_OUTPUT
fi
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
WP_BRANCH=${VERSION%\-*}
echo "WP_TESTS_TAG=branches/$WP_BRANCH" >> $GITHUB_OUTPUT
elif [[ $VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
echo "WP_TESTS_TAG=branches/$VERSION" >> $GITHUB_OUTPUT
elif [[ $VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
if [[ $VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
echo "WP_TESTS_TAG=tags/${VERSION%??}" >> $GITHUB_OUTPUT
else
echo "WP_TESTS_TAG=tags/$VERSION" >> $GITHUB_OUTPUT
fi
elif [[ $VERSION == 'nightly' || $VERSION == 'trunk' ]]; then
echo "WP_TESTS_TAG=trunk" >> $GITHUB_OUTPUT
else
echo "WP_TESTS_TAG=tags/$LATEST_VERSION" >> $GITHUB_OUTPUT
fi
echo "WP_TESTS_DIR=/tmp/test/$VERSION" >> $GITHUB_OUTPUT
id: wordpress-version
- name: Show WordPress Version
run: echo "The current WordPress version is ${{ steps.wordpress-version.outputs.WORDPRESS_VERSION }}, and WP_TESTS_TAG=${{ steps.wordpress-version.outputs.WP_TESTS_TAG }}"
- name: Cache WordPress Core Installation
id: wordpress-cache
uses: actions/cache@v3
with:
path: ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }}
key: ${{ runner.os }}-wordpress-${{ steps.wordpress-version.outputs.WORDPRESS_VERSION }}') }}
- name: Install WordPress Core
if: steps.wordpress-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }}
if [ "${{ steps.wordpress-version.outputs.WORDPRESS_VERSION_IS_TRUNK }}" == "1" ]; then
mkdir -p /tmp/wordpress-nightly
curl https://wordpress.org/nightly-builds/wordpress-latest.zip > /tmp/wordpress-nightly.zip
unzip -q /tmp/wordpress-nightly.zip -d /tmp/wordpress-nightly/
mv /tmp/wordpress-nightly/wordpress/* ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }}
else
curl -s https://wordpress.org/wordpress-${{ steps.wordpress-version.outputs.WORDPRESS_VERSION }}.tar.gz > /tmp/wordpress.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }}
fi
curl https://raw.github.com/markoheijnen/wp-mysqli/master/db.php > ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }}/wp-content/db.php
- name: Cache WordPress Test Installation
id: wordpress-test-cache
uses: actions/cache@v3
with:
path: ${{ steps.wordpress-version.outputs.WP_TESTS_DIR }}
key: ${{ runner.os }}-wordpress-test-${{ steps.wordpress-version.outputs.WORDPRESS_VERSION }}') }}
- name: Install WordPress Test
if: steps.wordpress-test-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ steps.wordpress-version.outputs.WP_TESTS_DIR }}
DB_USER=${MYSQL_USER}
DB_PASS=${MYSQL_PASSWORD}
DB_NAME=${MYSQL_DATABASE}
DB_HOST=${MYSQL_HOST}:${MYSQL_PORT}
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }}
svn co --quiet https://develop.svn.wordpress.org/${{ steps.wordpress-version.outputs.WP_TESTS_TAG }}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${{ steps.wordpress-version.outputs.WP_TESTS_TAG }}/tests/phpunit/data/ $WP_TESTS_DIR/data
curl https://develop.svn.wordpress.org/${{ steps.wordpress-version.outputs.WP_TESTS_TAG }}/wp-tests-config-sample.php > $WP_TESTS_DIR/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }} | sed "s:/\+$::")
sed -i "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed -i "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed -i "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed -i "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed -i "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
- name: Run PHPUnit Main Tests
# only run the output tests on the newer versions of php and phpunit, cause
# they're trickier
run: |
if [ "8.3" == ${{ matrix.php }} ]; then
PHP_UNIT_ARGS=""
else
PHP_UNIT_ARGS="--exclude-group output"
fi
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit $PHP_UNIT_ARGS --group slow
- name: Run PHPUnit Loader Tests
run: |
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-loader.xml.dist --filter FontAwesomeLoaderTestLifecycle
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-loader.xml.dist --filter FontAwesomeLoaderTestRedundantVersions
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-loader.xml.dist --filter FontAwesomeLoaderTestBasic
- name: Run PHPUnit Multisite Tests
run: |
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-multisite.xml.dist
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-multisite-network-admin.xml.dist
- name: Run PHPUnit Multisite SLOW Tests
run: |
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-multisite.xml.dist --group slow
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-multisite-network-admin.xml.dist --group slow
- name: Maybe run phpcs
run: |
if [ ${{ matrix.php }} == '8.3' ] && [ ${{ matrix.wordpress }} == latest ]; then
composer phpcs
echo
echo "Skipping phpcs"
fi