@@ -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"
0 commit comments