Skip to content

Commit 51478f1

Browse files
committed
Let's see if we can collate skipped test info and fail the workflow run if all test configurations cause any tests to be skipped.
1 parent 413b7ea commit 51478f1

File tree

4 files changed

+121
-4
lines changed

4 files changed

+121
-4
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Analyze skipped tests across all PHPUnit configurations
4+
# Fails if any tests are skipped in ALL configurations (never run)
5+
6+
# Count total test runs
7+
TOTAL_TEST_RUNS=$(ls -1 skipped-tests-*.txt 2>/dev/null | wc -l)
8+
9+
if [ "$TOTAL_TEST_RUNS" -eq 0 ]; then
10+
echo "ERROR: No skipped test artifacts found"
11+
exit 1
12+
fi
13+
14+
# Collect all skipped tests from all runs
15+
grep -E '^[A-Za-z0-9_\\]+::[A-Za-z0-9_]+$' skipped-tests-*.txt 2>/dev/null | cut -d: -f2- | sort | uniq > unique-skipped-tests.txt
16+
17+
# Find tests that are skipped in ALL runs
18+
ALWAYS_SKIPPED_TESTS=""
19+
while IFS= read -r test; do
20+
if [ -n "$test" ]; then
21+
# Count how many files contain this test
22+
count=$(grep -l "^${test}$" skipped-tests-*.txt | wc -l)
23+
24+
# If skipped in all runs, add to list
25+
if [ "$count" -eq "$TOTAL_TEST_RUNS" ]; then
26+
ALWAYS_SKIPPED_TESTS="${ALWAYS_SKIPPED_TESTS}${test}\n"
27+
fi
28+
fi
29+
done < unique-skipped-tests.txt
30+
31+
if [ -n "$ALWAYS_SKIPPED_TESTS" ]; then
32+
echo "ERROR: Found tests that are never run in any configuration:"
33+
echo -e "$ALWAYS_SKIPPED_TESTS"
34+
exit 1
35+
fi
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Extract skipped tests from PHPUnit JUnit XML output
4+
# Usage: extract-skipped-tests.sh <php> <db-type> <db-version> <multisite> <memcached> <test-groups>
5+
6+
# Create config ID from parameters
7+
CONFIG_ID="php${1}_${2}${3}_${4}_${5}_${6}"
8+
CONFIG_ID="${CONFIG_ID//[^a-zA-Z0-9_-]/_}"
9+
10+
echo "Extracting skipped tests for configuration: ${CONFIG_ID}"
11+
12+
# Extract skipped tests from XML files using xmllint
13+
touch "skipped-tests-${CONFIG_ID}.txt"
14+
15+
for file in phpunit-results-*.xml; do
16+
if [ -f "$file" ]; then
17+
# Extract skipped tests in class::method format
18+
xmllint --format "$file" 2>/dev/null | grep -B1 "<skipped" | grep "testcase" | sed -n 's/.*name="\([^"]*\)".*classname="\([^"]*\)".*/\2::\1/p' >> "skipped-tests-${CONFIG_ID}.txt" || true
19+
fi
20+
done
21+
22+
echo "Skipped tests saved to skipped-tests-${CONFIG_ID}.txt"
23+
echo "CONFIG_ID=${CONFIG_ID}"

.github/workflows/phpunit-tests.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,29 @@ jobs:
311311
memcached: ${{ matrix.memcached || false }}
312312
phpunit-test-groups: ${{ matrix.phpunit-test-groups || '' }}
313313

314+
analyze-skipped-tests:
315+
name: Analyze Skipped Tests
316+
runs-on: ubuntu-24.04
317+
needs:
318+
- test-with-mysql
319+
- test-with-mariadb
320+
- test-innovation-releases
321+
- html-api-test-groups
322+
permissions:
323+
contents: read
324+
steps:
325+
- name: Download skipped test artifacts
326+
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
327+
with:
328+
pattern: skipped-tests-*
329+
path: skipped-tests-artifacts
330+
merge-multiple: true
331+
332+
- name: Analyze skipped tests
333+
run: |
334+
cd skipped-tests-artifacts
335+
../.github/scripts/analyze-skipped-tests.sh
336+
314337
slack-notifications:
315338
name: Slack Notifications
316339
uses: ./.github/workflows/slack-notifications.yml

.github/workflows/reusable-phpunit-tests-v3.yml

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ jobs:
211211
php ./vendor/bin/phpunit \
212212
--verbose \
213213
-c "${PHPUNIT_CONFIG}" \
214+
--log-junit "phpunit-results-${MULTISITE_FLAG}.xml" \
214215
${{ inputs.phpunit-test-groups && '--group "${TEST_GROUPS}"' || '' }} \
215216
${{ inputs.coverage-report && '--coverage-clover "wp-code-coverage-${MULTISITE_FLAG}-${GITHUB_SHA}.xml" --coverage-html "wp-code-coverage-${MULTISITE_FLAG}-${GITHUB_SHA}"' || '' }}
216217
env:
@@ -220,23 +221,58 @@ jobs:
220221
- name: Run AJAX tests
221222
if: ${{ ! inputs.phpunit-test-groups && ! inputs.coverage-report }}
222223
continue-on-error: ${{ inputs.allow-errors }}
223-
run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c "${PHPUNIT_CONFIG}" --group ajax
224+
run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c "${PHPUNIT_CONFIG}" --group ajax --log-junit "phpunit-results-ajax-${MULTISITE_FLAG}.xml"
225+
env:
226+
MULTISITE_FLAG: ${{ inputs.multisite && 'multisite' || 'single' }}
224227

225228
- name: Run ms-files tests as a multisite install
226229
if: ${{ inputs.multisite && ! inputs.phpunit-test-groups && ! inputs.coverage-report }}
227230
continue-on-error: ${{ inputs.allow-errors }}
228-
run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c "${PHPUNIT_CONFIG}" --group ms-files
231+
run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c "${PHPUNIT_CONFIG}" --group ms-files --log-junit "phpunit-results-ms-files.xml"
229232

230233
- name: Run external HTTP tests
231234
if: ${{ ! inputs.multisite && ! inputs.phpunit-test-groups && ! inputs.coverage-report }}
232235
continue-on-error: ${{ inputs.allow-errors }}
233-
run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c "${PHPUNIT_CONFIG}" --group external-http
236+
run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c "${PHPUNIT_CONFIG}" --group external-http --log-junit "phpunit-results-external-http.xml"
234237

235238
# __fakegroup__ is excluded to force PHPUnit to ignore the <exclude> settings in phpunit.xml.dist.
236239
- name: Run (Xdebug) tests
237240
if: ${{ inputs.php != '8.4' && ! inputs.phpunit-test-groups && ! inputs.coverage-report }}
238241
continue-on-error: ${{ inputs.allow-errors }}
239-
run: LOCAL_PHP_XDEBUG=true node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit -v --group xdebug --exclude-group __fakegroup__
242+
run: LOCAL_PHP_XDEBUG=true node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit -v --group xdebug --exclude-group __fakegroup__ --log-junit "phpunit-results-xdebug.xml"
243+
244+
- name: Extract skipped tests from JUnit XML
245+
id: extract-skipped
246+
env:
247+
PHP_VERSION: ${{ inputs.php }}
248+
DB_TYPE: ${{ inputs.db-type }}
249+
DB_VERSION: ${{ inputs.db-version }}
250+
MULTISITE: ${{ inputs.multisite && 'multisite' || 'single' }}
251+
MEMCACHED: ${{ inputs.memcached && 'memcached' || 'no-memcached' }}
252+
TEST_GROUPS: ${{ inputs.phpunit-test-groups && inputs.phpunit-test-groups || 'all-groups' }}
253+
run: |
254+
CONFIG_OUTPUT=$(./.github/scripts/extract-skipped-tests.sh \
255+
"${PHP_VERSION}" \
256+
"${DB_TYPE}" \
257+
"${DB_VERSION}" \
258+
"${MULTISITE}" \
259+
"${MEMCACHED}" \
260+
"${TEST_GROUPS}")
261+
262+
# Extract CONFIG_ID from the script output
263+
CONFIG_ID=$(echo "$CONFIG_OUTPUT" | grep "CONFIG_ID=" | cut -d= -f2)
264+
echo "CONFIG_ID=${CONFIG_ID}" >> $GITHUB_OUTPUT
265+
266+
- name: Upload skipped tests summary
267+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
268+
with:
269+
name: skipped-tests-${{ steps.extract-skipped.outputs.CONFIG_ID }}
270+
path: skipped-tests-*.txt
271+
retention-days: 1
272+
if-no-files-found: ignore
273+
274+
- name: Clean up test artifacts
275+
run: rm -f phpunit-results-*.xml skipped-tests-*.txt
240276

241277
- name: Upload test coverage report to Codecov
242278
if: ${{ inputs.coverage-report }}

0 commit comments

Comments
 (0)