Skip to content

Commit 5b61fa3

Browse files
authored
Workflows
1 parent 437fd6d commit 5b61fa3

File tree

3 files changed

+138
-6
lines changed

3 files changed

+138
-6
lines changed

.github/workflows/wordpress-tests.yml

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,22 @@ jobs:
185185
186186
# Create and fix permissions for /tmp directory
187187
sudo mkdir -p /tmp/wordpress-tests-lib
188+
189+
# Create main directory to handle root path mismatch
190+
sudo mkdir -p /wordpress-tests-lib
191+
192+
# Set proper permissions
188193
sudo chmod 1777 /tmp
189194
sudo chmod 1777 /tmp/wordpress-tests-lib
195+
sudo chmod 1777 /wordpress-tests-lib
196+
197+
# Create a symlink to handle path discrepancies
198+
echo "Creating symlink to ensure path compatibility..."
199+
sudo ln -sf /tmp/wordpress-tests-lib/* /wordpress-tests-lib/ || echo "Warning: Symlink creation failed, will try direct copy later"
200+
201+
# Export WP_TESTS_DIR to ensure all scripts use the correct path
202+
export WP_TESTS_DIR=/tmp/wordpress-tests-lib
203+
echo "WP_TESTS_DIR=$WP_TESTS_DIR" >> $GITHUB_ENV
190204
191205
# Define variables for WordPress version
192206
WP_VERSION="${{ matrix.wordpress }}"
@@ -200,24 +214,78 @@ jobs:
200214
201215
# Try one more time with explicitly created directory
202216
echo "Retrying WordPress test environment setup..."
217+
sudo rm -rf /tmp/wordpress-tests-lib || echo "Failed to remove old test dir"
218+
sudo mkdir -p /tmp/wordpress-tests-lib
219+
sudo chmod 1777 /tmp/wordpress-tests-lib
220+
221+
# Make sure WP_TESTS_DIR is set correctly for the retry
222+
export WP_TESTS_DIR=/tmp/wordpress-tests-lib
223+
echo "WP_TESTS_DIR=$WP_TESTS_DIR" >> $GITHUB_ENV
224+
203225
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 $WP_VERSION || {
204226
echo "::error::Failed to setup WordPress test environment on second attempt."
205-
exit 1
227+
228+
# Last resort - try manually setting up core files
229+
echo "Attempting manual setup of core files as final fallback..."
230+
mkdir -p "$WP_TESTS_DIR/includes"
231+
232+
# Try to download the essential files directly
233+
curl -s https://develop.svn.wordpress.org/trunk/tests/phpunit/includes/functions.php > "$WP_TESTS_DIR/includes/functions.php"
234+
curl -s https://develop.svn.wordpress.org/trunk/tests/phpunit/includes/bootstrap.php > "$WP_TESTS_DIR/includes/bootstrap.php"
235+
curl -s https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php > "$WP_TESTS_DIR/wp-tests-config.php"
236+
237+
# Configure wp-tests-config.php
238+
sed -i "s:dirname( __FILE__ ) . '/src/':'/tmp/wordpress/':" "$WP_TESTS_DIR/wp-tests-config.php"
239+
sed -i "s/youremptytestdbnamehere/wordpress_test/" "$WP_TESTS_DIR/wp-tests-config.php"
240+
sed -i "s/yourusernamehere/root/" "$WP_TESTS_DIR/wp-tests-config.php"
241+
sed -i "s/yourpasswordhere//" "$WP_TESTS_DIR/wp-tests-config.php"
242+
sed -i "s|localhost|127.0.0.1|" "$WP_TESTS_DIR/wp-tests-config.php"
243+
244+
# Copy to the alternate path as well
245+
sudo mkdir -p /wordpress-tests-lib/includes/
246+
sudo cp -R "$WP_TESTS_DIR"/* /wordpress-tests-lib/
247+
248+
# Verify if manual setup succeeded
249+
if [ -f "$WP_TESTS_DIR/includes/functions.php" ]; then
250+
echo "Manual fallback setup succeeded."
251+
else
252+
echo "Manual fallback setup failed. Cannot proceed with tests."
253+
exit 1
254+
fi
206255
}
207256
}
208257
209258
# Verify the test environment was created successfully
210259
if [ ! -d "/tmp/wordpress-tests-lib" ]; then
211-
echo "::error::WordPress test directory not created."
260+
echo "::error::WordPress test directory not created at /tmp/wordpress-tests-lib."
212261
exit 1
213262
fi
214263
215264
if [ ! -f "/tmp/wordpress-tests-lib/includes/functions.php" ]; then
216-
echo "::error::WordPress test functions file missing."
265+
echo "::error::WordPress test functions file missing at /tmp/wordpress-tests-lib/includes/functions.php."
217266
ls -la /tmp/wordpress-tests-lib/includes/ || echo "Includes directory not found or empty"
218267
exit 1
219268
fi
220269
270+
# Ensure files are also available at non-tmp path (for scripts that may hardcode the path)
271+
echo "Syncing files to the /wordpress-tests-lib directory..."
272+
sudo mkdir -p /wordpress-tests-lib/includes/
273+
sudo cp -R /tmp/wordpress-tests-lib/* /wordpress-tests-lib/ || {
274+
echo "::warning::Failed to copy files to /wordpress-tests-lib - trying with rsync"
275+
sudo apt-get install -y rsync
276+
sudo rsync -a /tmp/wordpress-tests-lib/ /wordpress-tests-lib/ || echo "::warning::Failed to sync files with rsync"
277+
}
278+
279+
# Verify files in both locations
280+
if [ -f "/wordpress-tests-lib/includes/functions.php" ]; then
281+
echo "WordPress test files successfully copied to /wordpress-tests-lib/"
282+
else
283+
echo "::warning::Files may be missing in /wordpress-tests-lib, creating core files if needed"
284+
sudo mkdir -p /wordpress-tests-lib/includes/
285+
sudo cp -f /tmp/wordpress-tests-lib/includes/functions.php /wordpress-tests-lib/includes/ || echo "::warning::Failed to copy functions.php"
286+
sudo cp -f /tmp/wordpress-tests-lib/wp-tests-config.php /wordpress-tests-lib/ || echo "::warning::Failed to copy wp-tests-config.php"
287+
fi
288+
221289
# Check WordPress core installation and verify db.php was copied
222290
if [ ! -d "/tmp/wordpress" ]; then
223291
echo "::error::WordPress core directory not created."
@@ -256,13 +324,31 @@ jobs:
256324
# Ensure we have proper error reporting for tests
257325
export WP_TESTS_PHPUNIT_POLYFILLS_PATH=$(pwd)/vendor/yoast/phpunit-polyfills
258326
327+
# Set the WP_TESTS_DIR explicitly to ensure all scripts use the correct path
328+
export WP_TESTS_DIR=/tmp/wordpress-tests-lib
329+
echo "Using WordPress test directory: $WP_TESTS_DIR"
330+
259331
# Check WordPress test environment
260332
echo "Verifying WordPress test environment..."
261-
if [ ! -d "/tmp/wordpress-tests-lib" ] || [ ! -f "/tmp/wordpress-tests-lib/includes/functions.php" ]; then
262-
echo "::error::WordPress test environment verification failed. Missing required files."
263-
exit 1
333+
if [ ! -d "$WP_TESTS_DIR" ] || [ ! -f "$WP_TESTS_DIR/includes/functions.php" ]; then
334+
echo "::error::WordPress test environment verification failed at $WP_TESTS_DIR. Missing required files."
335+
336+
# Check alternate paths as fallback
337+
if [ -d "/wordpress-tests-lib" ] && [ -f "/wordpress-tests-lib/includes/functions.php" ]; then
338+
echo "::warning::Found WordPress test files at /wordpress-tests-lib instead, switching to this path."
339+
export WP_TESTS_DIR=/wordpress-tests-lib
340+
else
341+
exit 1
342+
fi
264343
fi
265344
345+
# Show test environment info for debugging
346+
echo "Final WordPress test environment information:"
347+
echo "WP_TESTS_DIR: $WP_TESTS_DIR"
348+
ls -la $WP_TESTS_DIR/includes/ || echo "Cannot list includes directory"
349+
echo "WordPress content directory:"
350+
ls -la /tmp/wordpress/wp-content/ || echo "Cannot list wp-content directory"
351+
266352
# PHP 8.x specific handling
267353
if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" || "$PHP_VERSION" == "8.3" || "$PHP_VERSION" == "8.4" ]]; then
268354
echo "Running tests with PHP $PHP_VERSION compatibility mode"

bin/install-wp-tests.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
3232
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
3333
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}
3434

35+
# Create a symlink from /wordpress-tests-lib to actual tests dir if not using the default
36+
if [[ "$WP_TESTS_DIR" == "/tmp/wordpress-tests-lib" && ! -d "/wordpress-tests-lib" ]]; then
37+
echo "Setting up compatibility symlink at /wordpress-tests-lib"
38+
if [ ! -d "/wordpress-tests-lib" ]; then
39+
sudo mkdir -p /wordpress-tests-lib || mkdir -p /wordpress-tests-lib || echo "Could not create /wordpress-tests-lib directory"
40+
sudo chmod 1777 /wordpress-tests-lib || chmod 1777 /wordpress-tests-lib 2>/dev/null || echo "Could not set permissions on /wordpress-tests-lib"
41+
fi
42+
fi
43+
3544
echo "Configuration:"
3645
echo " DB_NAME: $DB_NAME"
3746
echo " DB_USER: $DB_USER"
@@ -269,6 +278,27 @@ install_test_suite() {
269278
return 1
270279
fi
271280

281+
# Create a symlink or copy files to /wordpress-tests-lib if needed for compatibility
282+
if [[ "$WP_TESTS_DIR" == "/tmp/wordpress-tests-lib" && -d "$WP_TESTS_DIR" ]]; then
283+
if [ ! -d "/wordpress-tests-lib" ]; then
284+
echo "Creating directory at /wordpress-tests-lib for compatibility"
285+
mkdir -p /wordpress-tests-lib 2>/dev/null || sudo mkdir -p /wordpress-tests-lib 2>/dev/null
286+
fi
287+
288+
if [ -d "/wordpress-tests-lib" ]; then
289+
echo "Copying test files to /wordpress-tests-lib for compatibility"
290+
cp -R "$WP_TESTS_DIR"/* /wordpress-tests-lib/ 2>/dev/null || sudo cp -R "$WP_TESTS_DIR"/* /wordpress-tests-lib/ 2>/dev/null
291+
292+
if [ ! -f "/wordpress-tests-lib/includes/functions.php" ]; then
293+
echo "Warning: Could not copy all files to /wordpress-tests-lib"
294+
else
295+
echo "Successfully copied WordPress test files to /wordpress-tests-lib"
296+
fi
297+
else
298+
echo "Warning: Could not create /wordpress-tests-lib directory for compatibility"
299+
fi
300+
fi
301+
272302
echo "Test suite installation successful!"
273303
}
274304

tests/bootstrap.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
1717
}
1818

19+
// Check alternative paths if the initial path doesn't exist
20+
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
21+
$alternative_dirs = array(
22+
'/wordpress-tests-lib',
23+
dirname( __FILE__ ) . '/../wordpress-tests-lib',
24+
'/tmp/wordpress-tests-lib',
25+
);
26+
27+
foreach ( $alternative_dirs as $alt_dir ) {
28+
if ( file_exists( $alt_dir . '/includes/functions.php' ) ) {
29+
$_tests_dir = $alt_dir;
30+
break;
31+
}
32+
}
33+
}
34+
1935
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
2036
if (function_exists('esc_html')) {
2137
echo esc_html("Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?") . PHP_EOL;

0 commit comments

Comments
 (0)