Skip to content

Commit 99a9688

Browse files
authored
Workflow Changes
1 parent d4b9974 commit 99a9688

File tree

3 files changed

+181
-124
lines changed

3 files changed

+181
-124
lines changed

.github/workflows/wordpress-tests.yml

Lines changed: 121 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -80,80 +80,52 @@ jobs:
8080
sudo apt-get update
8181
sudo apt-get install -y subversion jq bc
8282
83-
# Robust PHPUnit installation with enhanced error handling
84-
- name: Verify and Install PHPUnit
83+
# Simplified PHPUnit installation with better error handling
84+
- name: Install Dependencies
8585
run: |
86-
echo "Installing PHPUnit for PHP ${{ matrix.php }}"
86+
echo "Installing dependencies for PHP ${{ matrix.php }}"
8787
88-
# Define PHP version for easier conditions
89-
PHP_VERSION="${{ matrix.php }}"
88+
# Clear composer cache to avoid using corrupted cache
89+
composer clear-cache
9090
9191
# Remove any existing lock file to ensure clean install
9292
rm -f composer.lock
9393
94-
# Setup environment information for debugging
94+
# Define PHP version for easier conditions
95+
PHP_VERSION="${{ matrix.php }}"
96+
97+
# Display PHP version for debugging
9598
echo "::notice::Debugging environment variables:"
9699
echo "PHP Version: $PHP_VERSION"
97100
php -v
98101
99-
# Configure platform version in composer.json for better dependency resolution
100-
cp composer.json composer.json.backup
102+
# Try composer update before installing PHPUnit
103+
composer update --no-progress --ignore-platform-reqs || {
104+
echo "::error::Composer update failed. Attempting direct installation..."
105+
# Try direct installation if update fails
106+
composer install --no-progress --ignore-platform-reqs || {
107+
echo "::error::Dependency installation failed. Debugging composer state:"
108+
composer diagnose
109+
# Try with --no-plugins as a last resort
110+
echo "Trying installation with --no-plugins flag"
111+
composer install --no-progress --ignore-platform-reqs --no-plugins || exit 1
112+
}
113+
}
101114
102-
# For PHP 8.x, use PHPUnit 9.5
103-
if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
104-
echo "::notice::Using PHPUnit 9.5 for PHP $PHP_VERSION"
105-
106-
# Configure platform and dependencies using multiple jq commands instead of heredoc
107-
jq '.config.platform.php = "8.0.0"' composer.json.backup > composer.json.tmp1
108-
jq '.["require-dev"]["phpunit/phpunit"] = "^9.5"' composer.json.tmp1 > composer.json.tmp2
109-
jq '.["require-dev"]["yoast/phpunit-polyfills"] = "^2.0"' composer.json.tmp2 > composer.json
110-
111-
# Add PHP 8 specific test script if needed
112-
if [[ "$PHP_VERSION" == "8.2" ]]; then
113-
jq '.scripts["test:php8"] = "php run-phpunit.php"' composer.json > composer.json.tmp3
114-
mv composer.json.tmp3 composer.json
115-
fi
116-
117-
# Install using direct require for more reliable installation
118-
echo "::notice::Installing PHPUnit via direct require for PHP $PHP_VERSION"
115+
# Attempt PHPUnit installation if necessary
116+
if [ ! -f "vendor/bin/phpunit" ]; then
117+
echo "PHPUnit not found, attempting to install specific version..."
119118
composer require --dev phpunit/phpunit:^9.5 yoast/phpunit-polyfills:^2.0 --no-progress --ignore-platform-reqs || {
120-
echo "::error::PHPUnit installation failed. Retrying with fallback method..."
121-
# Fallback: try removing composer.lock and trying again
122-
rm -f composer.lock
123-
composer require --dev phpunit/phpunit:^9.5 yoast/phpunit-polyfills:^2.0 --no-progress --ignore-platform-reqs || {
124-
echo "::error::PHPUnit installation failed on retry as well. Debugging composer error logs:"
125-
cat composer.lock 2>/dev/null || echo "composer.lock not generated"
126-
composer diagnose || echo "Composer diagnose command failed"
127-
exit 1
128-
}
129-
}
130-
else
131-
# For PHP 7.x, use PHPUnit 7.5
132-
echo "::notice::Using PHPUnit 7.5 for PHP $PHP_VERSION"
133-
134-
# Configure platform
135-
jq '.config.platform.php = "7.4.0"' composer.json.backup > composer.json
136-
137-
# Install using direct require for more reliable installation
138-
composer require --dev phpunit/phpunit:^7.5 yoast/phpunit-polyfills:^1.0 --no-progress || {
139-
echo "::warning::PHPUnit installation failed. Retrying with fallback method..."
140-
# Fallback: try removing composer.lock and trying again
141-
rm -f composer.lock
142-
composer require --dev phpunit/phpunit:^7.5 yoast/phpunit-polyfills:^1.0 --no-progress --ignore-platform-reqs || {
143-
echo "::error::PHPUnit installation failed on retry as well. Debugging composer error logs:"
144-
composer diagnose || echo "Composer diagnose command failed"
145-
exit 1
146-
}
119+
echo "::error::PHPUnit installation failed. Debugging composer error logs:"
120+
composer diagnose || echo "Composer diagnose command failed"
121+
exit 1
147122
}
148123
fi
149124
150-
# Clean up temporary files
151-
rm -f composer.json.tmp* composer.json.backup
152-
153125
# Verify PHPUnit installation
154126
if [ ! -f "vendor/bin/phpunit" ]; then
155127
echo "::error::PHPUnit installation unsuccessful. Cannot continue with tests."
156-
ls -la vendor || echo "vendor directory not found or empty"
128+
ls -la vendor/bin || echo "vendor/bin directory not found or empty"
157129
exit 1
158130
fi
159131
@@ -186,67 +158,114 @@ jobs:
186158
# Make the install script executable
187159
chmod +x bin/install-wp-tests.sh
188160
161+
# Create and fix permissions for /tmp directory
162+
sudo mkdir -p /tmp/wordpress-tests-lib
163+
sudo chmod 1777 /tmp
164+
sudo chmod 1777 /tmp/wordpress-tests-lib
165+
166+
# Define variables for WordPress version
167+
WP_VERSION="${{ matrix.wordpress }}"
168+
189169
# Run the script with detailed logging
190-
echo "Installing WordPress test environment for version ${{ matrix.wordpress }}..."
191-
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 ${{ matrix.wordpress }} || {
170+
echo "Installing WordPress test environment for version $WP_VERSION..."
171+
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 $WP_VERSION || {
192172
echo "::error::Failed to setup WordPress test environment. Showing detailed error information:"
193173
find /tmp -name "wordpress-tests-lib-install-*.log" -exec cat {} \; 2>/dev/null || echo "No install logs found."
194-
exit 1
174+
ls -la /tmp/wordpress-tests-lib || echo "/tmp/wordpress-tests-lib directory not found"
175+
176+
# Try one more time with explicitly created directory
177+
echo "Retrying WordPress test environment setup..."
178+
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 $WP_VERSION || {
179+
echo "::error::Failed to setup WordPress test environment on second attempt."
180+
exit 1
181+
}
195182
}
196183
197184
# Verify the test environment was created successfully
198-
if [ ! -d "/tmp/wordpress-tests-lib" ] || [ ! -f "/tmp/wordpress-tests-lib/includes/functions.php" ]; then
199-
echo "::error::WordPress test environment setup failed. Missing required files."
185+
if [ ! -d "/tmp/wordpress-tests-lib" ]; then
186+
echo "::error::WordPress test directory not created."
187+
exit 1
188+
fi
189+
190+
if [ ! -f "/tmp/wordpress-tests-lib/includes/functions.php" ]; then
191+
echo "::error::WordPress test functions file missing."
192+
ls -la /tmp/wordpress-tests-lib/includes/ || echo "Includes directory not found or empty"
200193
exit 1
201194
fi
202195
203-
echo "WordPress test environment successfully set up."
196+
# Check WordPress core installation
197+
if [ ! -d "/tmp/wordpress" ]; then
198+
echo "::error::WordPress core directory not created."
199+
exit 1
200+
fi
201+
202+
echo "WordPress test environment successfully set up:"
203+
ls -la /tmp/wordpress-tests-lib/
204204
205205
- name: Run tests
206206
if: steps.check-test-env.outputs.test_env_ready == 'true'
207207
run: |
208-
if [ -f "vendor/bin/phpunit" ]; then
209-
# Get the PHPUnit version
210-
PHPUNIT_VERSION=$(vendor/bin/phpunit --version | grep -oP '\d+\.\d+' | head -1)
211-
echo "Detected PHPUnit version: $PHPUNIT_VERSION"
212-
213-
# Define PHP version variable for use in conditions
214-
PHP_VERSION="${{ matrix.php }}"
208+
if [ ! -f "vendor/bin/phpunit" ]; then
209+
echo "::error::PHPUnit executable not found in vendor/bin directory."
210+
ls -la vendor/bin || echo "vendor/bin directory not found"
211+
exit 1
212+
fi
213+
214+
# Get the PHPUnit version
215+
PHPUNIT_VERSION=$(vendor/bin/phpunit --version | grep -oP '\d+\.\d+' | head -1 || echo "unknown")
216+
echo "Detected PHPUnit version: $PHPUNIT_VERSION"
217+
218+
# Define PHP version variable for use in conditions
219+
PHP_VERSION="${{ matrix.php }}"
220+
221+
# Ensure we have proper error reporting for tests
222+
export WP_TESTS_PHPUNIT_POLYFILLS_PATH=$(pwd)/vendor/yoast/phpunit-polyfills
223+
224+
# Check WordPress test environment
225+
echo "Verifying WordPress test environment..."
226+
if [ ! -d "/tmp/wordpress-tests-lib" ] || [ ! -f "/tmp/wordpress-tests-lib/includes/functions.php" ]; then
227+
echo "::error::WordPress test environment verification failed. Missing required files."
228+
exit 1
229+
fi
230+
231+
# PHP 8.x specific handling
232+
if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
233+
echo "Running tests with PHP $PHP_VERSION compatibility mode"
215234
216-
# Set up the command based on PHP and PHPUnit versions
217-
if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
218-
echo "::notice::Running tests with PHPUnit for PHP $PHP_VERSION"
219-
220-
# For PHP 8.x, check if it's PHPUnit 9.x
221-
if [[ $(echo "$PHPUNIT_VERSION >= 9.0" | bc -l) -eq 1 ]]; then
222-
# PHPUnit 9.x on PHP 8.x - safest approach
223-
echo "::notice::Using PHPUnit 9.x safe execution mode"
224-
225-
# Try running tests directly without any extra flags
226-
vendor/bin/phpunit || {
227-
echo "::warning::Test execution failed. Running individual test files..."
228-
EXIT_CODE=0
229-
# Try to run each test file individually to isolate issues
230-
for TEST_FILE in tests/test-*.php; do
231-
echo "Testing file: $TEST_FILE"
232-
vendor/bin/phpunit "$TEST_FILE" || EXIT_CODE=1
233-
done
234-
# Return the combined exit code
235-
exit $EXIT_CODE
236-
}
237-
else
238-
# PHPUnit < 9.0 on PHP 8.x - potentially problematic
239-
echo "::warning::Running PHPUnit version less than 9.0 on PHP 8.x - using compatibility mode"
240-
# Run with our compatibility layer which should handle the errors
241-
XDEBUG_MODE=coverage vendor/bin/phpunit
242-
fi
235+
# For PHP 8.x, we'll use our custom run-phpunit.php script
236+
if [ -f "run-phpunit.php" ]; then
237+
php run-phpunit.php || {
238+
echo "::warning::Tests failed with run-phpunit.php, trying individual test files..."
239+
EXIT_CODE=0
240+
# Try to run each test file individually to isolate issues
241+
for TEST_FILE in tests/test-*.php; do
242+
echo "Testing file: $TEST_FILE"
243+
php run-phpunit.php "$TEST_FILE" || EXIT_CODE=1
244+
done
245+
exit $EXIT_CODE
246+
}
243247
else
244-
# PHP 7.x with PHPUnit 7.x - standard execution
245-
echo "::notice::Running tests with PHPUnit for PHP $PHP_VERSION"
246-
vendor/bin/phpunit
248+
# Fallback if custom script is missing - suppress deprecation warnings
249+
php -d error_reporting=E_ALL^E_DEPRECATED vendor/bin/phpunit || {
250+
echo "::warning::Tests failed with standard execution, trying individual test files..."
251+
EXIT_CODE=0
252+
for TEST_FILE in tests/test-*.php; do
253+
echo "Testing file: $TEST_FILE"
254+
php -d error_reporting=E_ALL^E_DEPRECATED vendor/bin/phpunit "$TEST_FILE" || EXIT_CODE=1
255+
done
256+
exit $EXIT_CODE
257+
}
247258
fi
248259
else
249-
echo "::error::PHPUnit executable not found in vendor/bin directory."
250-
ls -la vendor/bin || echo "vendor/bin directory not found"
251-
exit 1
260+
# Standard execution for PHP 7.x
261+
echo "Running tests with PHP $PHP_VERSION standard mode"
262+
vendor/bin/phpunit || {
263+
echo "::warning::Tests failed with standard execution, trying individual test files..."
264+
EXIT_CODE=0
265+
for TEST_FILE in tests/test-*.php; do
266+
echo "Testing file: $TEST_FILE"
267+
vendor/bin/phpunit "$TEST_FILE" || EXIT_CODE=1
268+
done
269+
exit $EXIT_CODE
270+
}
252271
fi

bin/install-wp-tests.sh

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ download() {
4444
if command -v curl >/dev/null 2>&1; then
4545
echo "Downloading $1 using curl..."
4646
for i in {1..3}; do
47-
curl -s "$1" -o "$2" && return 0
47+
if curl -s "$1" -o "$2"; then
48+
# Verify download was successful
49+
if [ -s "$2" ]; then
50+
echo "Download successful!"
51+
return 0
52+
else
53+
echo "Downloaded file is empty. Retrying..."
54+
fi
55+
fi
4856
echo "Attempt $i failed, retrying in 3 seconds..."
4957
sleep 3
5058
done
@@ -53,7 +61,10 @@ download() {
5361
elif command -v wget >/dev/null 2>&1; then
5462
echo "Downloading $1 using wget..."
5563
for i in {1..3}; do
56-
wget -nv -O "$2" "$1" && return 0
64+
if wget -nv -O "$2" "$1" && [ -s "$2" ]; then
65+
echo "Download successful!"
66+
return 0
67+
fi
5768
echo "Attempt $i failed, retrying in 3 seconds..."
5869
sleep 3
5970
done
@@ -176,13 +187,38 @@ install_test_suite() {
176187
# set up testing suite if it doesn't yet exist
177188
if [ ! -d $WP_TESTS_DIR ]; then
178189
# set up testing suite
190+
echo "Creating WordPress tests directory at $WP_TESTS_DIR"
179191
mkdir -p $WP_TESTS_DIR
180-
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
181-
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
192+
193+
echo "Checking directory permissions"
194+
ls -ld $WP_TESTS_DIR
195+
196+
echo "Downloading test files from WordPress SVN"
197+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes || {
198+
echo "Failed to download test includes - retrying once"
199+
svn cleanup $WP_TESTS_DIR/includes
200+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes || {
201+
echo "Error: Could not download WordPress test includes"
202+
return 1
203+
}
204+
}
205+
206+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data || {
207+
echo "Failed to download test data - retrying once"
208+
svn cleanup $WP_TESTS_DIR/data
209+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data || {
210+
echo "Error: Could not download WordPress test data"
211+
return 1
212+
}
213+
}
182214
fi
183215

184216
if [ ! -f wp-tests-config.php ]; then
185-
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
217+
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php || {
218+
echo "Error: Could not download wp-tests-config-sample.php"
219+
return 1
220+
}
221+
186222
# remove all forward slashes in the end
187223
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
188224
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
@@ -195,21 +231,11 @@ install_test_suite() {
195231
# Verify test environment was created successfully
196232
if [ ! -d "$WP_TESTS_DIR/includes" ] || [ ! -f "$WP_TESTS_DIR/wp-tests-config.php" ]; then
197233
echo "Error: WordPress test environment setup failed. Missing required files."
198-
exit 1
234+
return 1
199235
fi
200-
}
201236

202-
# Verify test environment was created successfully
203-
if [ ! -d "$WP_TESTS_DIR/includes" ] || [ ! -f "$WP_TESTS_DIR/wp-tests-config.php" ]; then
204-
echo "Error: WordPress test environment setup failed. Missing required files."
205-
exit 1
206-
fi
237+
echo "Test suite installation successful!"
207238
}
208-
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
209-
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
210-
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
211-
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
212-
fi
213239

214240
}
215241

@@ -258,9 +284,21 @@ install_db() {
258284

259285
echo "Starting WordPress test environment setup..."
260286

261-
install_wp
262-
install_test_suite
263-
install_db
287+
# Execute each step with error handling
288+
install_wp || {
289+
echo "WordPress core installation failed!"
290+
exit 1
291+
}
292+
293+
install_test_suite || {
294+
echo "WordPress test suite installation failed!"
295+
exit 1
296+
}
297+
298+
install_db || {
299+
echo "Database setup failed!"
300+
exit 1
301+
}
264302

265303
echo "WordPress test environment setup complete."
266304
echo "Log file available at: $LOG_FILE"

0 commit comments

Comments
 (0)