-
Notifications
You must be signed in to change notification settings - Fork 143
213 lines (204 loc) · 8.4 KB
/
php-test-plugins.yml
File metadata and controls
213 lines (204 loc) · 8.4 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
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
name: Unit Testing for Plugins
on:
push:
branches:
- trunk
- 'release/**'
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test-plugins.yml'
- 'plugins/**.php'
- '.wp-env.json'
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tools/phpunit/bootstrap.php'
- 'composer.json'
- 'composer.lock'
pull_request:
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test-plugins.yml'
- 'plugins/**.php'
- '.wp-env.json'
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tools/phpunit/bootstrap.php'
- 'composer.json'
- 'composer.lock'
types:
- opened
- reopened
- synchronize
jobs:
php-test-plugins:
name: 'PHP ${{ matrix.php }} / WP ${{ matrix.wp }}'
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.0', '7.4', '7.3', '7.2']
wp: ['latest']
coverage: [false]
include:
- php: '7.4'
wp: '6.6'
- php: '8.3'
wp: 'trunk'
- php: '8.4'
wp: 'trunk'
- php: '8.5'
wp: 'trunk'
- php: '8.2'
phpunit: '9.6'
wp: 'latest'
coverage: ${{ !startsWith(github.actor, 'dependabot') }}
env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }}
steps:
- uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # 0.12.1
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
with:
dir_names: true # Output unique changed directories.
dir_names_max_depth: 2
files_yaml: |
plugins:
- 'plugins/**'
config:
- '.github/workflows/php-test-plugins.yml'
- '.wp-env.json'
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tools/phpunit/bootstrap.php'
- 'composer.json'
- 'composer.lock'
- name: Get changed plugins
id: changed-plugins
run: |
if [[ "${{ github.event_name }}" == "push" || "${{ steps.changed-files.outputs.config_any_changed }}" == "true" ]]; then
ALL_CHANGED_PLUGINS=($(ls plugins))
echo "all_changed_plugins=${ALL_CHANGED_PLUGINS[*]}" >> $GITHUB_OUTPUT
exit 0
fi
declare -a ALL_CHANGED_PLUGINS=()
for DIR in ${{ steps.changed-files.outputs.plugins_all_changed_files }}; do
PLUGIN_NAME=$(basename "$DIR")
ALL_CHANGED_PLUGINS+=("$PLUGIN_NAME")
done
# Define and add plugin dependents (e.g., changes to Optimization Detective should trigger its dependents).
declare -A PLUGIN_DEPENDENTS=(
["optimization-detective"]="embed-optimizer image-prioritizer"
)
for PLUGIN in "${ALL_CHANGED_PLUGINS[@]}"; do
if [[ -n "${PLUGIN_DEPENDENTS[$PLUGIN]}" ]]; then
for DEP in ${PLUGIN_DEPENDENTS[$PLUGIN]}; do
if [[ ! " ${ALL_CHANGED_PLUGINS[*]} " =~ " ${DEP} " ]]; then
ALL_CHANGED_PLUGINS+=("$DEP")
fi
done
fi
done
ALL_CHANGED_PLUGINS=($(echo "${ALL_CHANGED_PLUGINS[@]}" | tr ' ' '\n' | sort | tr '\n' ' '))
echo "all_changed_plugins=${ALL_CHANGED_PLUGINS[*]}" >> $GITHUB_OUTPUT
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
with:
node-version-file: '.nvmrc'
cache: npm
- name: npm install
run: npm ci
- name: Build assets
run: npm run build
- name: Install WordPress
run: |
if [ "${{ matrix.coverage }}" == "true" ]; then
npm run wp-env start -- --xdebug=coverage
else
npm run wp-env start
fi
- name: Composer Install
run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress
- name: Update Composer Dependencies
run: composer update --with-all-dependencies --no-interaction --no-progress
- name: Install PHPUnit
run: |
if [ "${{ matrix.php }}" == "8.2" ]; then
# Version 2.1.0 of doctrine/instantiator started requiring PHP 8.4: <https://github.com/doctrine/instantiator/pull/148>.
composer require phpunit/phpunit:${{ matrix.phpunit }} "doctrine/instantiator:<2.1" --with-all-dependencies --ignore-platform-reqs
else
composer require --dev phpunit/phpunit:${{ matrix.phpunit }}
fi
if: matrix.phpunit != ''
- name: Running single site unit tests
run: |
if [ "${{ matrix.coverage }}" == "true" ]; then
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
npm run test-php:$PLUGIN -- -- -- --coverage-clover=./single-site-reports/coverage-$PLUGIN.xml
done
else
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
npm run test-php:$PLUGIN
done
fi
- name: Running multisite unit tests
run: |
if [ "${{ matrix.coverage }}" == "true" ]; then
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
npm run test-php-multisite:$PLUGIN -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-$PLUGIN.xml
done
else
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
npm run test-php-multisite:$PLUGIN
done
fi
- name: Download Codecov CLI
if: ${{ matrix.coverage == true }}
run: |
# Create a temporary directory for GPG operations
mkdir -p .gpg
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --homedir .gpg --no-default-keyring --keyring trustedkeys.gpg --import
curl -Os https://cli.codecov.io/latest/linux/codecov
curl -Os https://cli.codecov.io/latest/linux/codecov.SHA256SUM
curl -Os https://cli.codecov.io/latest/linux/codecov.SHA256SUM.sig
gpg --homedir .gpg --no-default-keyring --keyring trustedkeys.gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM
shasum -a 256 -c codecov.SHA256SUM
chmod +x codecov
- name: Upload coverage reports to Codecov
if: ${{ matrix.coverage == true }}
run: |
# Build common arguments for all uploads
cc_args=()
cc_args+=(--fail-on-error)
cc_args+=(--disable-search)
cc_args+=(--git-service github)
cc_args+=(--gcov-executable "gcov")
# Add SHA for PRs
if [ -n "${{ github.event.pull_request.head.sha }}" ]; then
cc_args+=(--sha "${{ github.event.pull_request.head.sha }}")
fi
# Handle authentication differently for forks vs. internal PRs
if [ -n "${{ github.event.pull_request.head.repo.full_name }}" ] && \
[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
echo "::notice::Processing PR from fork - using tokenless upload with branch override."
cc_args+=(--branch "${{ github.event.pull_request.head.label }}")
else
echo "::notice::Processing internal PR or push - using token."
cc_args+=(--token "${{ secrets.CODECOV_TOKEN }}")
fi
# Upload reports for each changed plugin
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
echo "::group::Uploading coverage for plugin: $PLUGIN"
./codecov upload-coverage "${cc_args[@]}" \
--file ./single-site-reports/coverage-$PLUGIN.xml \
--file ./multisite-reports/coverage-multisite-$PLUGIN.xml \
--flag $PLUGIN \
--name $PLUGIN-coverage
echo "::endgroup::"
done