Skip to content

Commit d4b9974

Browse files
authored
Workflow Updates
1 parent 3e85a9b commit d4b9974

File tree

3 files changed

+78
-40
lines changed

3 files changed

+78
-40
lines changed

.github/workflows/php-code-quality.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,22 @@ jobs:
5353
5454
- name: Run PHP Code Beautifier and Fixer
5555
run: |
56+
echo "Running PHP Code Beautifier and Fixer to automatically fix code style issues..."
5657
if [ -f phpcs.xml ] || [ -f phpcs.xml.dist ]; then
5758
# Try to fix code style issues automatically using the project's standards
5859
vendor/bin/phpcbf --standard=phpcs.xml || vendor/bin/phpcbf --standard=phpcs.xml.dist || true
5960
else
6061
# Use WordPress-Core standard if no phpcs config file exists
6162
vendor/bin/phpcbf --standard=WordPress-Core --extensions=php --ignore=vendor/,node_modules/ . || true
6263
fi
64+
65+
# Check if changes were made and output a summary
66+
if git diff --name-only | grep -q "\.php$"; then
67+
echo "PHPCBF fixed issues in the following files:"
68+
git diff --name-only | grep "\.php$"
69+
else
70+
echo "No code style issues fixed by PHPCBF."
71+
fi
6372
# The '|| true' ensures the workflow continues even if phpcbf exits with non-zero code
6473
6574
- name: Run PHP_CodeSniffer
@@ -101,7 +110,21 @@ jobs:
101110
exit 0
102111
fi
103112
113+
# Stage all PHP files that were modified
114+
git add "*.php"
115+
116+
# Commit with descriptive message including which coding standards were applied
117+
if [ -f phpcs.xml ]; then
118+
STANDARD="phpcs.xml"
119+
elif [ -f phpcs.xml.dist ]; then
120+
STANDARD="phpcs.xml.dist"
121+
else
122+
STANDARD="WordPress-Core"
123+
fi
124+
104125
# Commit and push changes
105-
git add .
106-
git commit -m "Auto-fix code style issues with PHPCBF [skip ci]" || true
107-
git push || true
126+
git commit -m "Auto-fix code style issues with PHPCBF [standard: $STANDARD] [skip ci]" || true
127+
git push || {
128+
echo "::warning::Failed to push changes. This could be due to a race condition with other workflows."
129+
echo "::warning::The code style fixes will still be available in this build."
130+
}

.github/workflows/wordpress-tests.yml

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
sudo apt-get update
8181
sudo apt-get install -y subversion jq bc
8282
83-
# Robust PHPUnit installation
83+
# Robust PHPUnit installation with enhanced error handling
8484
- name: Verify and Install PHPUnit
8585
run: |
8686
echo "Installing PHPUnit for PHP ${{ matrix.php }}"
@@ -91,38 +91,57 @@ jobs:
9191
# Remove any existing lock file to ensure clean install
9292
rm -f composer.lock
9393
94+
# Setup environment information for debugging
95+
echo "::notice::Debugging environment variables:"
96+
echo "PHP Version: $PHP_VERSION"
97+
php -v
98+
99+
# Configure platform version in composer.json for better dependency resolution
100+
cp composer.json composer.json.backup
101+
94102
# For PHP 8.x, use PHPUnit 9.5
95103
if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
96104
echo "::notice::Using PHPUnit 9.5 for PHP $PHP_VERSION"
97105
98-
# Create a compatible composer.json for PHP 8.x
99-
cp composer.json composer.json.backup
100-
jq '.["require-dev"]["phpunit/phpunit"] = "^9.5"' composer.json.backup > composer.json.tmp1
101-
jq '.["require-dev"]["yoast/phpunit-polyfills"] = "^2.0"' composer.json.tmp1 > composer.json
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
102110
103111
# Add PHP 8 specific test script if needed
104112
if [[ "$PHP_VERSION" == "8.2" ]]; then
105-
jq '.config.platform.php = "8.1.99"' composer.json > composer.json.tmp2
106-
jq '.scripts["test:php8"] = "php run-phpunit.php"' composer.json.tmp2 > composer.json
113+
jq '.scripts["test:php8"] = "php run-phpunit.php"' composer.json > composer.json.tmp3
114+
mv composer.json.tmp3 composer.json
107115
fi
108116
109-
# Install using the modified composer.json
110-
composer update --no-progress --ignore-platform-reqs || {
111-
echo "::warning::Composer update failed, trying direct require"
112-
rm -rf vendor
117+
# Install using direct require for more reliable installation
118+
echo "::notice::Installing PHPUnit via direct require for PHP $PHP_VERSION"
119+
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
113123
composer require --dev phpunit/phpunit:^9.5 yoast/phpunit-polyfills:^2.0 --no-progress --ignore-platform-reqs || {
114-
echo "::error::PHPUnit installation failed"
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"
115127
exit 1
116128
}
117129
}
118130
else
119131
# For PHP 7.x, use PHPUnit 7.5
120132
echo "::notice::Using PHPUnit 7.5 for PHP $PHP_VERSION"
121-
composer update --no-progress || {
122-
echo "::warning::Composer update failed, trying direct require"
123-
rm -rf vendor
124-
composer require --dev phpunit/phpunit:^7.5 yoast/phpunit-polyfills:^1.0 --no-progress || {
125-
echo "::error::PHPUnit installation failed"
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"
126145
exit 1
127146
}
128147
}
@@ -133,7 +152,8 @@ jobs:
133152
134153
# Verify PHPUnit installation
135154
if [ ! -f "vendor/bin/phpunit" ]; then
136-
echo "::error::PHPUnit installation unsuccessful."
155+
echo "::error::PHPUnit installation unsuccessful. Cannot continue with tests."
156+
ls -la vendor || echo "vendor directory not found or empty"
137157
exit 1
138158
fi
139159

bin/install-wp-tests.sh

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,22 @@ echo " WP_CORE_DIR: $WP_CORE_DIR"
4343
download() {
4444
if command -v curl >/dev/null 2>&1; then
4545
echo "Downloading $1 using curl..."
46-
curl -s "$1" -o "$2" || { echo "Error: Failed to download $1"; exit 1; }
46+
for i in {1..3}; do
47+
curl -s "$1" -o "$2" && return 0
48+
echo "Attempt $i failed, retrying in 3 seconds..."
49+
sleep 3
50+
done
51+
echo "Error: Failed to download $1 after 3 attempts"
52+
exit 1
4753
elif command -v wget >/dev/null 2>&1; then
4854
echo "Downloading $1 using wget..."
49-
wget -nv -O "$2" "$1" || { echo "Error: Failed to download $1"; exit 1; }
55+
for i in {1..3}; do
56+
wget -nv -O "$2" "$1" && return 0
57+
echo "Attempt $i failed, retrying in 3 seconds..."
58+
sleep 3
59+
done
60+
echo "Error: Failed to download $1 after 3 attempts"
61+
exit 1
5062
else
5163
echo "Error: Neither curl nor wget is available for downloads."
5264
exit 1
@@ -186,12 +198,6 @@ install_test_suite() {
186198
exit 1
187199
fi
188200
}
189-
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
190-
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
191-
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
192-
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
193-
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
194-
fi
195201

196202
# Verify test environment was created successfully
197203
if [ ! -d "$WP_TESTS_DIR/includes" ] || [ ! -f "$WP_TESTS_DIR/wp-tests-config.php" ]; then
@@ -266,14 +272,3 @@ if [ ! -d "$WP_TESTS_DIR/includes" ] || [ ! -f "$WP_TESTS_DIR/wp-tests-config.ph
266272
fi
267273

268274
echo "Success: WordPress test environment is ready."
269-
echo "Error: Could not create database $DB_NAME."
270-
echo "Please check your database credentials and permissions."
271-
exit 1
272-
fi
273-
274-
echo "Database setup complete!"
275-
}
276-
277-
install_wp
278-
install_test_suite
279-
install_db

0 commit comments

Comments
 (0)