Skip to content

Commit

Permalink
Add php codesniffer with wordpress standards (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlHandy authored Jul 27, 2024
1 parent 3b793a1 commit 560d99b
Show file tree
Hide file tree
Showing 3,729 changed files with 324,555 additions and 70,120 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
50 changes: 50 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: PHP CodeSniffer

on:
pull_request:
paths:
- '**.php'
push:
paths:
- '**.php'

permissions:
contents: read
pull-requests: write

jobs:
phpcs:
name: PHP CodeSniffer
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer:v2

- name: Install dependencies
run: composer install

- name: Run PHP CodeSniffer
run: vendor/bin/phpcs -p --standard=phpcs.xml --report=full --runtime-set ignore_warnings_on_exit 1 > phpcs-results.txt

- name: Post PHPCS results as PR comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const phpcsOutput = fs.readFileSync('phpcs-results.txt', 'utf8');
const summary = phpcsOutput.split('\n').slice(0, 10).join('\n'); // Get first 10 lines for summary
const fullReport = '## PHP CodeSniffer Results\n\n<details><summary>Click to expand full report</summary>\n\n```\n' + phpcsOutput + '\n```\n</details>';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## PHP CodeSniffer Summary\n\n```\n' + summary + '\n```\n\n' + fullReport
});
41 changes: 34 additions & 7 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
branches:
- main

permissions:
contents: read
pull-requests: write

jobs:
test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -79,6 +83,7 @@ jobs:
fi
- name: Run PHPUnit tests
id: run-tests
env:
COMPOSER_PROCESS_TIMEOUT: 0
COMPOSER_NO_INTERACTION: 1
Expand All @@ -100,10 +105,32 @@ jobs:
# Copy WooCommerce to WordPress test environment
mkdir -p /home/runner/wordpress-tests/wordpress-develop/src/wp-content/plugins
cp -r wp-content/plugins/woocommerce /home/runner/wordpress-tests/wordpress-develop/src/wp-content/plugins/
# Run PHPUnit tests
vendor/bin/phpunit --bootstrap tests/bootstrap.php --debug --verbose --configuration phpunit.xml
# Check if any tests failed
if [ $? -ne 0 ]; then
echo "PHPUnit tests failed. Exiting with error."
exit 1
fi
# Run PHPUnit tests and save output
vendor/bin/phpunit --bootstrap tests/bootstrap.php --debug --verbose --configuration phpunit.xml > phpunit-results.txt
# Check if any tests failed and set output
if grep -q "FAILURES!" phpunit-results.txt; then
echo "tests_failed=true" >> $GITHUB_OUTPUT
else
echo "tests_failed=false" >> $GITHUB_OUTPUT
fi
- name: Post PHPUnit results as PR comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const phpunitOutput = fs.readFileSync('phpunit-results.txt', 'utf8');
const summary = phpunitOutput.split('\n').slice(0, 10).join('\n'); // Get first 10 lines for summary
const fullReport = '## PHPUnit Test Results\n\n<details><summary>Click to expand full report</summary>\n\n```\n' + phpunitOutput + '\n```\n</details>';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## PHPUnit Test Summary\n\n```\n' + summary + '\n```\n\n' + fullReport
});
- name: Check test results
if: steps.run-tests.outputs.tests_failed == 'true'
run: exit 1
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
git pull origin main
- name: Zip project
run: zip -r mmg-checkout-payment.zip . -x "*.git*" -x "tests/*" -x "bin/*" -x "composer.json" -x "composer.lock" -x "phpunit.xml" -x "README.md" -x "*.DS_Store" -x "SECURITY.md"
run: zip -r mmg-checkout-payment.zip main.php uninstall.php vendor/* README.txt js/* assets/* includes/*

- name: Setup GitHub CLI
uses: actions/setup-go@v4
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
.idea/inspectionProfiles/
.idea/inspectionProfiles/Profiles_2023.05.xml
.idea/inspectionProfiles/Profiles_2023.06.xml
.idea/inspectionProfiles/Profiles_2023.07.xml
.idea/inspectionProfiles/Profiles_2023.07.xml
wp-content/*
20 changes: 15 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{
"require": {
"phpseclib/phpseclib": "~3.0",
"woocommerce/woocommerce": "^5.9.1",
"php": "~7.4"
"phpseclib/phpseclib": "~3.0"

},
"require-dev": {
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6",
"wp-coding-standards/wpcs": "^3.1",
"woocommerce/woocommerce": "^5.9.1",
"php": "^5.6 || ~7.0 || ~7.1 || ~7.2 || ~7.3 || ~7.4"
},
"config": {
"allow-plugins": {
"composer/installers": true,
"automattic/jetpack-autoloader": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
}
Loading

0 comments on commit 560d99b

Please sign in to comment.