|
10 | 10 | schedule: |
11 | 11 | - cron: '17 1 * * *' # Run every day on a seemly random time. |
12 | 12 |
|
13 | | -# Cancels all previous workflow runs for the same branch that have not yet completed. |
14 | | -concurrency: |
15 | | - # The concurrency group contains the workflow name and the branch name. |
16 | | - group: ${{ github.workflow }}-${{ github.ref }} |
17 | | - cancel-in-progress: true |
18 | | - |
19 | 13 | jobs: |
20 | | - get-matrix: |
21 | | - name: Get base test matrix |
22 | | - runs-on: ubuntu-22.04 |
23 | | - outputs: |
24 | | - matrix: ${{ steps.base-matrix.outputs.matrix }} |
25 | | - steps: |
26 | | - - name: Set matrix |
27 | | - id: base-matrix |
28 | | - run: | |
29 | | - MATRIX=$(cat << EOF |
30 | | - { |
31 | | - "include": [ |
32 | | - { |
33 | | - "php": "8.4", |
34 | | - "wp": "latest", |
35 | | - "mysql": "mysql-8.0" |
36 | | - }, |
37 | | - { |
38 | | - "php": "8.4", |
39 | | - "wp": "latest", |
40 | | - "dbtype": "sqlite" |
41 | | - }, |
42 | | - { |
43 | | - "php": "8.4", |
44 | | - "wp": "latest", |
45 | | - "mysql": "mysql-8.0", |
46 | | - "os": "macos-15" |
47 | | - }, |
48 | | - { |
49 | | - "php": "8.4", |
50 | | - "wp": "latest", |
51 | | - "dbtype": "sqlite", |
52 | | - "os": "macos-15" |
53 | | - }, |
54 | | - { |
55 | | - "php": "8.4", |
56 | | - "wp": "latest", |
57 | | - "mysql": "mysql-8.0", |
58 | | - "os": "windows-2025" |
59 | | - }, |
60 | | - { |
61 | | - "php": "8.4", |
62 | | - "wp": "latest", |
63 | | - "dbtype": "sqlite", |
64 | | - "os": "windows-2025" |
65 | | - } |
66 | | - ] |
67 | | - } |
68 | | - EOF |
69 | | - ) |
70 | | - echo matrix=$MATRIX >> $GITHUB_OUTPUT |
71 | | -
|
72 | | - prepare-unit: |
73 | | - name: Prepare matrix for unit tests |
74 | | - needs: get-matrix |
75 | | - runs-on: ubuntu-22.04 |
76 | | - outputs: |
77 | | - matrix: ${{ steps.set-matrix.outputs.matrix }} |
78 | | - steps: |
79 | | - - name: Check out source code |
80 | | - uses: actions/checkout@v5 |
81 | | - |
82 | | - - name: Check existence of composer.json & phpunit.xml.dist files |
83 | | - id: check_files |
84 | | - uses: andstor/file-existence-action@v3 |
85 | | - with: |
86 | | - files: "composer.json, phpunit.xml.dist" |
87 | | - |
88 | | - - name: Set matrix |
89 | | - id: set-matrix |
90 | | - run: | |
91 | | - if [[ $FILE_EXISTS == 'true' ]]; then |
92 | | - echo "matrix=$(jq -c \ |
93 | | - --argjson with_coverage_flag "true" \ |
94 | | - --arg minimum_php "7.2" \ |
95 | | - --arg minimum_wp "4.9" \ |
96 | | - ' |
97 | | - .include |= ( |
98 | | - map( |
99 | | - # First, select only the versions that meet all minimum requirements |
100 | | - select( |
101 | | - (.php >= $minimum_php) and |
102 | | - (.wp == "latest" or .wp >= $minimum_wp) |
103 | | - ) | |
104 | | -
|
105 | | - # Next, update the coverage flag on the remaining items |
106 | | - if $with_coverage_flag == false and .coverage == true then |
107 | | - .coverage = false |
108 | | - else |
109 | | - . |
110 | | - end |
111 | | - ) | |
112 | | -
|
113 | | - # Finally, get the unique entries |
114 | | - unique_by([.php, .os]) |
115 | | - ) |
116 | | - ' <<< "$BASE_MATRIX")" >> $GITHUB_OUTPUT |
117 | | - else |
118 | | - echo "matrix=" >> $GITHUB_OUTPUT |
119 | | - fi |
120 | | - env: |
121 | | - BASE_MATRIX: ${{ needs.get-matrix.outputs.matrix }} |
122 | | - FILE_EXISTS: ${{ steps.check_files.outputs.files_exists == 'true' }} |
123 | | - |
124 | | - unit: #----------------------------------------------------------------------- |
125 | | - needs: prepare-unit |
126 | | - if: ${{ needs.prepare-unit.outputs.matrix != '' }} |
127 | | - name: Unit test / PHP ${{ matrix.php }}${{ matrix.coverage && ' (with coverage)' || '' }} (${{ matrix.os || 'ubuntu-22.04' }}) |
128 | | - strategy: |
129 | | - fail-fast: false |
130 | | - matrix: ${{ fromJson(needs.prepare-unit.outputs.matrix) }} |
131 | | - runs-on: ${{ matrix.os || 'ubuntu-22.04' }} |
132 | | - |
133 | | - continue-on-error: ${{ matrix.php == 'nightly' }} |
134 | | - |
135 | | - steps: |
136 | | - - name: Check out source code |
137 | | - uses: actions/checkout@v5 |
138 | | - |
139 | | - - name: Set up PHP environment |
140 | | - uses: shivammathur/setup-php@v2 |
141 | | - with: |
142 | | - php-version: '${{ matrix.php }}' |
143 | | - ini-values: zend.assertions=1, error_reporting=-1, display_errors=On |
144 | | - coverage: ${{ matrix.coverage && 'xdebug' || 'none' }} |
145 | | - tools: composer,cs2pr |
146 | | - env: |
147 | | - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
148 | | - |
149 | | - - name: Install Composer dependencies & cache dependencies |
150 | | - uses: "ramsey/composer-install@v3" |
151 | | - env: |
152 | | - COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} |
153 | | - with: |
154 | | - # Bust the cache at least once a month - output format: YYYY-MM. |
155 | | - custom-cache-suffix: $(date -u "+%Y-%m") |
156 | | - |
157 | | - # PHPUnit 10+ may fail a test run when the "old" configuration format is used. |
158 | | - # Luckily, there is a build-in migration tool since PHPUnit 9.3. |
159 | | - - name: Migrate PHPUnit configuration for PHPUnit 10+ |
160 | | - if: ${{ matrix.php >= 8.2 || matrix.php == 'nightly' }} |
161 | | - continue-on-error: true |
162 | | - run: composer phpunit -- --migrate-configuration |
163 | | - |
164 | | - - name: Setup problem matcher to provide annotations for PHPUnit |
165 | | - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" |
166 | | - |
167 | | - - name: Run PHPUnit with coverage |
168 | | - if: ${{ matrix.coverage }} |
169 | | - run: | |
170 | | - composer phpunit -- --coverage-clover build/logs/unit-coverage.xml |
171 | | -
|
172 | | - - name: Run PHPUnit |
173 | | - if: ${{ ! matrix.coverage }} |
174 | | - # For example TestBehatTags.php in wp-cli-tests depends on the db type. |
175 | | - env: |
176 | | - WP_CLI_TEST_DBTYPE: 'sqlite' |
177 | | - run: | |
178 | | - composer phpunit |
179 | | -
|
180 | | - - name: Upload code coverage report |
181 | | - if: ${{ matrix.coverage }} |
182 | | - |
183 | | - with: |
184 | | - directory: build/logs |
185 | | - flags: unit |
186 | | - token: ${{ secrets.CODECOV_TOKEN }} |
187 | | - |
188 | | - prepare-functional: #--------------------------------------------------------- |
189 | | - name: Prepare matrix for functional tests |
190 | | - needs: get-matrix |
191 | | - runs-on: ubuntu-22.04 |
192 | | - outputs: |
193 | | - matrix: ${{ steps.set-matrix.outputs.matrix }} |
194 | | - steps: |
195 | | - - name: Check out source code |
196 | | - uses: actions/checkout@v5 |
197 | | - |
198 | | - - name: Check existence of composer.json & behat.yml files |
199 | | - id: check_files |
200 | | - uses: andstor/file-existence-action@v3 |
201 | | - with: |
202 | | - files: "composer.json, behat.yml" |
203 | | - |
204 | | - - name: Set matrix |
205 | | - id: set-matrix |
206 | | - run: | |
207 | | - if [[ $FILE_EXISTS == 'true' ]]; then |
208 | | - echo "matrix=$(jq -c \ |
209 | | - --argjson with_coverage_flag "true" \ |
210 | | - --arg minimum_php "7.2" \ |
211 | | - --arg minimum_wp "4.9" \ |
212 | | - ' |
213 | | - # First, select only the versions that meet all minimum requirements |
214 | | - .include |= ( |
215 | | - map( |
216 | | - select( |
217 | | - .php >= $minimum_php |
218 | | - ) | |
219 | | - # Next, update the coverage flag on the remaining items |
220 | | - if $with_coverage_flag == false and .coverage == true then |
221 | | - .coverage = false |
222 | | - else |
223 | | - . |
224 | | - end |
225 | | - ) |
226 | | - ) | |
227 | | -
|
228 | | - # Reassign WP4.9 to minimum_wp |
229 | | - .include |= ( |
230 | | - map( |
231 | | - select( |
232 | | - .wp == "4.9" |
233 | | - ).wp |= $minimum_wp |
234 | | - ) |
235 | | - ) |
236 | | - ' <<< "$BASE_MATRIX" )" >> $GITHUB_OUTPUT |
237 | | - else |
238 | | - echo "matrix=" >> $GITHUB_OUTPUT |
239 | | - fi |
240 | | - env: |
241 | | - BASE_MATRIX: ${{ needs.get-matrix.outputs.matrix }} |
242 | | - FILE_EXISTS: ${{ steps.check_files.outputs.files_exists == 'true' }} |
243 | | - |
244 | | - functional: #----------------------------------------------------------------- |
245 | | - needs: prepare-functional |
246 | | - if: ${{ needs.prepare-functional.outputs.matrix != '' }} |
247 | | - name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with ${{ matrix.dbtype != 'sqlite' && matrix.mysql || 'SQLite' }}${{ matrix.coverage && ' (with coverage)' || '' }} (${{ matrix.os || 'ubuntu-22.04' }}) |
248 | | - strategy: |
249 | | - fail-fast: false |
250 | | - matrix: ${{ fromJson(needs.prepare-functional.outputs.matrix) }} |
251 | | - runs-on: ${{ matrix.os || 'ubuntu-22.04' }} |
252 | | - |
253 | | - continue-on-error: ${{ matrix.dbtype == 'sqlite' || matrix.dbtype == 'mariadb' || matrix.php == 'nightly' }} |
254 | | - |
255 | | - env: |
256 | | - MYSQL_HOST: 127.0.0.1 |
257 | | - MYSQL_TCP_PORT: 3306 |
258 | | - WP_CLI_TEST_DBROOTUSER: root |
259 | | - WP_CLI_TEST_DBROOTPASS: root |
260 | | - WP_CLI_TEST_DBNAME: wp_cli_test |
261 | | - WP_CLI_TEST_DBUSER: wp_cli_test |
262 | | - WP_CLI_TEST_DBPASS: password1 |
263 | | - WP_CLI_TEST_DBHOST: 127.0.0.1:3306 |
264 | | - |
265 | | - steps: |
266 | | - - name: Check out source code |
267 | | - uses: actions/checkout@v5 |
268 | | - |
269 | | - - name: Install Ghostscript |
270 | | - if: ${{ matrix.os == 'ubuntu-22.04' || matrix.os == '' }} |
271 | | - run: | |
272 | | - sudo apt-get update |
273 | | - sudo apt-get install ghostscript -y |
274 | | -
|
275 | | - - name: Set up PHP environment |
276 | | - uses: shivammathur/setup-php@v2 |
277 | | - with: |
278 | | - php-version: '${{ matrix.php }}' |
279 | | - ini-values: zend.assertions=1, error_reporting=-1, display_errors=On |
280 | | - extensions: gd, imagick, mysql, zip |
281 | | - coverage: ${{ matrix.coverage && 'xdebug' || 'none' }} |
282 | | - tools: composer |
283 | | - env: |
284 | | - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
285 | | - |
286 | | - - name: Change ImageMagick policy to allow pdf->png conversion. |
287 | | - if: ${{ matrix.os == 'ubuntu-22.04' || matrix.os == '' }} |
288 | | - run: | |
289 | | - sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml |
290 | | -
|
291 | | - - name: Install Composer dependencies & cache dependencies |
292 | | - uses: "ramsey/composer-install@v3" |
293 | | - env: |
294 | | - COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} |
295 | | - with: |
296 | | - # Bust the cache at least once a month - output format: YYYY-MM. |
297 | | - custom-cache-suffix: $(date -u "+%Y-%m") |
298 | | - |
299 | | - - name: Setup MySQL Server |
300 | | - id: setup-mysql |
301 | | - if: ${{ matrix.dbtype != 'sqlite' }} |
302 | | - uses: shogo82148/actions-setup-mysql@v1 |
303 | | - with: |
304 | | - mysql-version: ${{ matrix.mysql }} |
305 | | - auto-start: true |
306 | | - root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }} |
307 | | - user: ${{ env.WP_CLI_TEST_DBUSER}} |
308 | | - password: ${{ env.WP_CLI_TEST_DBPASS}} |
309 | | - my-cnf: | |
310 | | - default_authentication_plugin=mysql_native_password |
311 | | -
|
312 | | - - name: Prepare test database |
313 | | - if: ${{ matrix.dbtype != 'sqlite' }} |
314 | | - run: composer prepare-tests |
315 | | - |
316 | | - - name: Check Behat environment |
317 | | - env: |
318 | | - WP_VERSION: '${{ matrix.wp }}' |
319 | | - WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }} |
320 | | - WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock' |
321 | | - WP_CLI_TEST_DEBUG_BEHAT_ENV: 1 |
322 | | - run: composer behat |
323 | | - |
324 | | - - name: Run Behat |
325 | | - env: |
326 | | - WP_VERSION: '${{ matrix.wp }}' |
327 | | - WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }} |
328 | | - WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock' |
329 | | - WP_CLI_TEST_COVERAGE: ${{ matrix.coverage }} |
330 | | - # BEHAT_ARGS: ${{ matrix.coverage && runner.debug && '--debug --format=pretty' || matrix.coverage && '--debug' || runner.debug && '--format=pretty' || '' }} |
331 | | - BEHAT_ARGS: '--format=pretty' |
332 | | - run: | |
333 | | - composer behat -- $BEHAT_ARGS || composer behat-rerun -- $BEHAT_ARGS |
334 | | -
|
335 | | - - name: Retrieve list of coverage files |
336 | | - id: coverage_files |
337 | | - if: ${{ matrix.coverage }} |
338 | | - run: | |
339 | | - FILES=$(find "$GITHUB_WORKSPACE/build/logs" -path '*.*' | paste -s -d "," -) |
340 | | - echo "files=$FILES" >> $GITHUB_OUTPUT |
341 | | -
|
342 | | - - name: Upload code coverage report |
343 | | - if: ${{ matrix.coverage }} |
344 | | - |
345 | | - with: |
346 | | - # Because somehow providing `directory: build/logs` doesn't work for these files |
347 | | - files: ${{ steps.coverage_files.outputs.files }} |
348 | | - flags: feature |
349 | | - token: ${{ secrets.CODECOV_TOKEN }} |
| 14 | + test: |
| 15 | + uses: wp-cli/.github/.github/workflows/reusable-testing.yml@main |
0 commit comments