Repository navigation
124 lines (109 loc) · 4.14 KB
/
Copy pathphpunit-test.yml
File metadata and controls
124 lines (109 loc) · 4.14 KB
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
name: PHPUnit Test Runner
on:
workflow_call:
inputs:
php-version:
required: false
type: string
default: '8.2'
description: 'PHP version to test against'
jobs:
phpunit-test:
name: PHPUnit tests (PHP ${{ inputs.php-version }})
runs-on: blacksmith-2vcpu-ubuntu-2404
env:
WP_CORE_DIR: /tmp/wordpress
WP_TESTS_DIR: /tmp/wordpress-tests-lib
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress_test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up PHP
uses: codesnippetspro/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
- name: Compute dependency hash
id: deps-hash
run: |
set -euo pipefail
tmpfile=$(mktemp)
if [ -f "src/composer.lock" ]; then
cat "src/composer.lock" >> "$tmpfile"
fi
if [ -f "src/composer.json" ]; then
cat "src/composer.json" >> "$tmpfile"
fi
if [ -s "$tmpfile" ]; then
deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8)
else
deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8)
fi
echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT"
- name: Get Composer cache
id: composer-cache
uses: actions/cache/restore@v4
with:
path: src/vendor
key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ steps.deps-hash.outputs.deps_hash }}
restore-keys: |
${{ runner.os }}-php-${{ inputs.php-version }}-composer-
- name: Install Composer dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install -d src --no-progress --prefer-dist --optimize-autoloader
- name: Save Composer cache
if: steps.composer-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: src/vendor
key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ steps.deps-hash.outputs.deps_hash }}
- name: Resolve WordPress version metadata
id: wp-meta
run: |
set -euo pipefail
wp_version=$(curl -s http://api.wordpress.org/core/version-check/1.7/ | grep -o '"version":"[^"]*' | head -1 | sed 's/"version":"//')
if [ -z "$wp_version" ]; then
wp_version="latest-unknown"
fi
echo "wp_version=$wp_version" >> "$GITHUB_OUTPUT"
- name: Get WordPress test suite cache
id: wp-tests-cache
uses: actions/cache/restore@v4
with:
path: |
${{ env.WP_CORE_DIR }}
${{ env.WP_TESTS_DIR }}
key: ${{ runner.os }}-php-${{ inputs.php-version }}-wp-tests-${{ hashFiles('tests/install-wp-tests.sh') }}-wp-${{ steps.wp-meta.outputs.wp_version }}
- name: Install WordPress test suite
run: |
bash scripts/install-wp-tests.sh wordpress_test root root 127.0.0.1:3306 latest true
- name: Save WordPress test suite cache
if: steps.wp-tests-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
${{ env.WP_CORE_DIR }}
${{ env.WP_TESTS_DIR }}
key: ${{ steps.wp-tests-cache.outputs.cache-primary-key }}
- name: Run PHPUnit tests
run: |
set -euo pipefail
mkdir -p test-results/phpunit
cd src
vendor/bin/phpunit -c ../phpunit.xml --testdox --log-junit ../test-results/phpunit/phpunit-${{ inputs.php-version }}.xml 2>&1 | tee ../test-results/phpunit/phpunit-${{ inputs.php-version }}.log
- uses: actions/upload-artifact@v4
if: always()
with:
name: phpunit-test-results-php-${{ inputs.php-version }}
path: |
src/.phpunit.result.cache
test-results/phpunit/
if-no-files-found: ignore
retention-days: 2