Skip to content

Commit b6bc772

Browse files
authored
Updated Workflows
1 parent f4a3cb5 commit b6bc772

2 files changed

Lines changed: 348 additions & 0 deletions

File tree

Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
name: WordPress Compatibility Test
2+
3+
on:
4+
# Run on pushes to main branch and on all pull requests
5+
push:
6+
branches: [ main ]
7+
pull_request:
8+
# Allow manually triggering the workflow
9+
workflow_dispatch:
10+
11+
# Cancels all previous workflow runs for the same branch that have not yet completed
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: read
18+
issues: write
19+
20+
jobs:
21+
php-compatibility-test:
22+
name: PHP ${{ matrix.php-version }} with WordPress Latest
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
27+
fail-fast: false
28+
29+
services:
30+
mysql:
31+
image: mysql:5.7
32+
env:
33+
MYSQL_ALLOW_EMPTY_PASSWORD: false
34+
MYSQL_ROOT_PASSWORD: root
35+
MYSQL_DATABASE: wordpress_test
36+
ports:
37+
- 3306:3306
38+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
39+
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v4
43+
44+
- name: Setup PHP ${{ matrix.php-version }}
45+
uses: shivammathur/setup-php@v2
46+
with:
47+
php-version: ${{ matrix.php-version }}
48+
extensions: mysqli, curl, zip, intl, gd, mbstring, fileinfo, xml
49+
coverage: none
50+
tools: composer:v2
51+
52+
- name: Install Subversion
53+
run: sudo apt-get update && sudo apt-get install -y subversion
54+
55+
- name: Remove the PHP platform requirement
56+
run: composer config --unset platform.php
57+
58+
- name: Install Composer dependencies
59+
uses: ramsey/composer-install@v3
60+
with:
61+
dependency-versions: highest
62+
composer-options: "--prefer-dist --no-progress"
63+
64+
- name: Prepare Database
65+
run: |
66+
# Make sure database doesn't exist before creating it
67+
mysql -u root --password=root --host=127.0.0.1 --port=3306 -e "DROP DATABASE IF EXISTS wordpress_test;"
68+
# Force creating a fresh database
69+
mysqladmin -u root --password=root --host=127.0.0.1 --port=3306 --force create wordpress_test
70+
71+
- name: Create tests directory structure
72+
run: |
73+
mkdir -p tests/bin
74+
mkdir -p tests/bootstrap
75+
76+
- name: Create WP tests install script
77+
run: |
78+
cat > tests/bin/install-wp-tests.sh << 'EOF'
79+
#!/usr/bin/env bash
80+
81+
if [ $# -lt 3 ]; then
82+
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
83+
exit 1
84+
fi
85+
86+
DB_NAME=$1
87+
DB_USER=$2
88+
DB_PASS=$3
89+
DB_HOST=${4-localhost}
90+
WP_VERSION=${5-latest}
91+
SKIP_DB_CREATE=${6-false}
92+
93+
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
94+
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
95+
96+
download() {
97+
if [ $(which curl) ]; then
98+
curl -s "$1" > "$2";
99+
elif [ $(which wget) ]; then
100+
wget -nv -O "$2" "$1"
101+
fi
102+
}
103+
104+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
105+
WP_TESTS_TAG="tags/$WP_VERSION"
106+
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
107+
WP_TESTS_TAG="trunk"
108+
else
109+
# http serves a single offer, whereas https serves multiple. we only want one
110+
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
111+
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
112+
if [[ -z "$LATEST_VERSION" ]]; then
113+
echo "Latest WordPress version could not be found"
114+
exit 1
115+
fi
116+
WP_TESTS_TAG="tags/$LATEST_VERSION"
117+
fi
118+
119+
set -ex
120+
121+
install_wp() {
122+
123+
if [ -d $WP_CORE_DIR ]; then
124+
return;
125+
fi
126+
127+
mkdir -p $WP_CORE_DIR
128+
129+
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
130+
mkdir -p /tmp/wordpress-nightly
131+
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
132+
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
133+
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
134+
else
135+
if [ $WP_VERSION == 'latest' ]; then
136+
local ARCHIVE_NAME='latest'
137+
else
138+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
139+
fi
140+
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
141+
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
142+
fi
143+
144+
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
145+
}
146+
147+
install_test_suite() {
148+
# portable in-place argument for both GNU sed and Mac OSX sed
149+
if [[ $(uname -s) == 'Darwin' ]]; then
150+
local ioption='-i.bak'
151+
else
152+
local ioption='-i'
153+
fi
154+
155+
# set up testing suite if it doesn't yet exist
156+
if [ ! -d $WP_TESTS_DIR ]; then
157+
# set up testing suite
158+
mkdir -p $WP_TESTS_DIR
159+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
160+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
161+
fi
162+
163+
if [ ! -f wp-tests-config.php ]; then
164+
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
165+
# remove all forward slashes in the end
166+
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
167+
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
168+
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
169+
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
170+
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
171+
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
172+
fi
173+
}
174+
175+
install_db() {
176+
if [ ${SKIP_DB_CREATE} = "true" ]; then
177+
return 0
178+
fi
179+
180+
# parse DB_HOST for port or socket references
181+
local PARTS=(${DB_HOST//\:/ })
182+
local DB_HOSTNAME=${PARTS[0]};
183+
local DB_SOCK_OR_PORT=${PARTS[1]};
184+
local EXTRA=""
185+
186+
if ! [ -z $DB_HOSTNAME ] ; then
187+
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
188+
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
189+
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
190+
EXTRA=" --socket=$DB_SOCK_OR_PORT"
191+
elif ! [ -z $DB_HOSTNAME ] ; then
192+
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
193+
fi
194+
fi
195+
196+
# First, ensure database doesn't exist (ignore errors)
197+
mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA -e "DROP DATABASE IF EXISTS $DB_NAME" || true
198+
# Now create fresh database with force flag
199+
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA --force
200+
}
201+
202+
install_wp
203+
install_test_suite
204+
install_db
205+
EOF
206+
chmod +x tests/bin/install-wp-tests.sh
207+
208+
- name: Create Bootstrap File
209+
run: |
210+
mkdir -p tests
211+
cat > tests/bootstrap.php << 'EOF'
212+
<?php
213+
/**
214+
* PHPUnit bootstrap file for plugin tests.
215+
*
216+
* @package EngineScript_Simple_Site_Exporter
217+
*/
218+
219+
// Give access to tests_add_filter() function.
220+
require_once '/tmp/wordpress-tests-lib/includes/functions.php';
221+
222+
/**
223+
* Manually load the plugin being tested.
224+
*/
225+
function _manually_load_plugin() {
226+
// Make sure widget registration won't throw errors
227+
add_filter('widgets_init', function() {
228+
// Empty the action to prevent widget registration errors
229+
return;
230+
}, 0);
231+
232+
require dirname( dirname( __FILE__ ) ) . '/simple-site-exporter.php';
233+
}
234+
235+
// Start up the WP testing environment.
236+
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
237+
238+
require '/tmp/wordpress-tests-lib/includes/bootstrap.php';
239+
EOF
240+
241+
- name: Create Test File
242+
run: |
243+
cat > tests/test-plugin.php << 'EOF'
244+
<?php
245+
/**
246+
* Class Test_EngineScript_Simple_Site_Exporter
247+
*
248+
* @package EngineScript_Simple_Site_Exporter
249+
*/
250+
251+
/**
252+
* Simple test case for EngineScript Simple Site Exporter plugin.
253+
*/
254+
class Test_EngineScript_Simple_Site_Exporter extends WP_UnitTestCase {
255+
/**
256+
* Test that the plugin can be loaded correctly.
257+
*
258+
* This test simply checks that the plugin loads in WordPress
259+
* without causing any errors.
260+
*/
261+
public function test_plugin_loaded() {
262+
// Check for at least one function to verify the plugin loaded
263+
$this->assertTrue(function_exists('sse_admin_menu'), 'Plugin was not loaded correctly');
264+
}
265+
}
266+
EOF
267+
268+
- name: Create PHPUnit Config
269+
run: |
270+
cat > phpunit.xml << 'EOF'
271+
<?xml version="1.0"?>
272+
<phpunit
273+
bootstrap="tests/bootstrap.php"
274+
backupGlobals="false"
275+
colors="true"
276+
convertErrorsToExceptions="true"
277+
convertNoticesToExceptions="true"
278+
convertWarningsToExceptions="true"
279+
>
280+
<testsuites>
281+
<testsuite name="EngineScript Simple Site Exporter">
282+
<directory prefix="test-" suffix=".php">./tests/</directory>
283+
</testsuite>
284+
</testsuites>
285+
</phpunit>
286+
EOF
287+
288+
- name: Setup WP Tests
289+
run: |
290+
bash tests/bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:3306 latest
291+
292+
- name: Run plugin test
293+
run: vendor/bin/phpunit --config phpunit.xml
294+
295+
- name: Report test status
296+
if: ${{ always() }}
297+
run: |
298+
if [ ${{ job.status }} == 'success' ]; then
299+
echo "✅ Tests passed successfully on PHP ${{ matrix.php-version }} with the latest WordPress version"
300+
else
301+
echo "❌ Tests failed on PHP ${{ matrix.php-version }} with the latest WordPress version"
302+
# Don't exit here, allow the next step to create the issue
303+
fi
304+
305+
- name: Create issue on test failure
306+
if: ${{ failure() }}
307+
uses: JasonEtco/create-an-issue@v2
308+
env:
309+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
310+
PHP_VERSION: ${{ matrix.php-version }}
311+
RUN_ID: ${{ github.run_id }}
312+
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
313+
with:
314+
filename: .github/ISSUE_TEMPLATE/compatibility-test-failure.md
315+
update_existing: false
316+
317+
- name: Mark job as failed after issue creation
318+
if: ${{ failure() }}
319+
run: |
320+
echo "::error::PHP ${{ matrix.php-version }} compatibility test failed. Created issue for tracking."
321+
exit 1

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "enginescript/simple-site-exporter",
3+
"description": "EngineScript Simple Site Exporter - Export your entire WordPress site as a ZIP archive",
4+
"type": "wordpress-plugin",
5+
"license": "GPL-3.0-or-later",
6+
"authors": [
7+
{
8+
"name": "EngineScript",
9+
"email": "support@enginescript.com"
10+
}
11+
],
12+
"minimum-stability": "stable",
13+
"require": {
14+
"php": ">=7.4"
15+
},
16+
"require-dev": {
17+
"phpunit/phpunit": "^9.5",
18+
"yoast/phpunit-polyfills": "^4.0",
19+
"wp-coding-standards/wpcs": "^2.3",
20+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0"
21+
},
22+
"config": {
23+
"allow-plugins": {
24+
"dealerdirect/phpcodesniffer-composer-installer": true
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)