Skip to content

Commit 9350785

Browse files
authored
Workflow Updates
1 parent 038ed8b commit 9350785

File tree

2 files changed

+57
-39
lines changed

2 files changed

+57
-39
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ on:
1616
paths:
1717
- '**.php'
1818

19+
# Define permissions needed for auto-committing fixes
20+
permissions:
21+
contents: write
22+
1923
jobs:
2024
php-code-quality:
2125
name: PHP Code Quality Checks
@@ -47,6 +51,17 @@ jobs:
4751
composer require --dev wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer phpcompatibility/php-compatibility --no-interaction
4852
fi
4953
54+
- name: Run PHP Code Beautifier and Fixer
55+
run: |
56+
if [ -f phpcs.xml ] || [ -f phpcs.xml.dist ]; then
57+
# Try to fix code style issues automatically using the project's standards
58+
vendor/bin/phpcbf --standard=phpcs.xml || vendor/bin/phpcbf --standard=phpcs.xml.dist || true
59+
else
60+
# Use WordPress-Core standard if no phpcs config file exists
61+
vendor/bin/phpcbf --standard=WordPress-Core --extensions=php --ignore=vendor/,node_modules/ . || true
62+
fi
63+
# The '|| true' ensures the workflow continues even if phpcbf exits with non-zero code
64+
5065
- name: Run PHP_CodeSniffer
5166
run: |
5267
if [ -f phpcs.xml ] || [ -f phpcs.xml.dist ]; then
@@ -59,9 +74,34 @@ jobs:
5974
run: |
6075
# Install PHP compatibility standards if they're not already installed
6176
composer require --dev phpcompatibility/php-compatibility wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer --no-interaction || true
77+
78+
# Set up PHPCompatibility standard
6279
vendor/bin/phpcs --config-set installed_paths $(pwd)/vendor/phpcompatibility/php-compatibility || true
80+
81+
# Try to auto-fix compatibility issues where possible
82+
vendor/bin/phpcbf --standard=PHPCompatibilityWP --extensions=php --ignore=vendor/,node_modules/ --runtime-set testVersion 7.0- . || true
83+
84+
# Run the actual compatibility check
6385
vendor/bin/phpcs --standard=PHPCompatibilityWP --extensions=php --ignore=vendor/,node_modules/ --runtime-set testVersion 7.0- .
6486
6587
- name: Check PHP syntax
6688
run: |
6789
find . -type f -name "*.php" -not -path "./vendor/*" -not -path "./node_modules/*" -print0 | xargs -0 -n1 php -l
90+
91+
- name: Commit auto-fixed code style changes
92+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
93+
run: |
94+
# Configure Git
95+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
96+
git config --local user.name "github-actions[bot]"
97+
98+
# Check if there are changes to commit
99+
if git diff --quiet; then
100+
echo "No changes to commit"
101+
exit 0
102+
fi
103+
104+
# 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

.github/workflows/wordpress-tests.yml

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -115,45 +115,23 @@ jobs:
115115
# Write a custom composer.json for PHP 8.2 to handle specific requirements
116116
if [[ "$PHP_VERSION" == "8.2" ]]; then
117117
echo "::notice::Using PHP 8.2, creating specialized composer configuration"
118-
cat > composer.json.php82 << 'EOL'
119-
{
120-
"name": "enginescript/simple-wp-optimizer",
121-
"description": "Simple WP Optimizer - A lightweight WordPress optimization plugin",
122-
"type": "wordpress-plugin",
123-
"license": "GPL-2.0-or-later",
124-
"authors": [
125-
{
126-
"name": "EngineScript",
127-
"email": "[email protected]"
128-
}
129-
],
130-
"minimum-stability": "stable",
131-
"require": {
132-
"php": ">=7.4"
133-
},
134-
"require-dev": {
135-
"phpunit/phpunit": "^9.5",
136-
"yoast/phpunit-polyfills": "^2.0",
137-
"wp-coding-standards/wpcs": "^2.3",
138-
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1"
139-
},
140-
"config": {
141-
"allow-plugins": {
142-
"dealerdirect/phpcodesniffer-composer-installer": true
143-
},
144-
"platform": {
145-
"php": "8.1.99"
146-
}
147-
},
148-
"scripts": {
149-
"test": "vendor/bin/phpunit",
150-
"phpcs": "vendor/bin/phpcs --standard=WordPress",
151-
"phpcbf": "vendor/bin/phpcbf --standard=WordPress"
152-
}
153-
}
154-
EOL
155-
# Use the PHP 8.2 specific composer file
156-
mv composer.json.php82 composer.json
118+
119+
# Start with a copy of the existing composer.json
120+
cp composer.json composer.json.original
121+
122+
# Update dependencies for PHP 8.2 compatibility
123+
jq '.["require-dev"]["phpunit/phpunit"] = "^9.5"' composer.json.original > composer.json.tmp
124+
jq '.["require-dev"]["yoast/phpunit-polyfills"] = "^2.0"' composer.json.tmp > composer.json.tmp2
125+
126+
# Set platform config
127+
jq '.config.platform.php = "8.1.99"' composer.json.tmp2 > composer.json.tmp3
128+
129+
# Add PHP 8 specific test script
130+
jq '.scripts["test:php8"] = "php run-phpunit.php"' composer.json.tmp3 > composer.json
131+
132+
# Clean up tmp files
133+
rm -f composer.json.tmp*
134+
rm -f composer.json.original
157135
fi
158136
159137
# Install dependencies based on PHP version

0 commit comments

Comments
 (0)