-
-
Notifications
You must be signed in to change notification settings - Fork 72
add better dev experience #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
837b79c
d1147cc
7b0ad9c
44405cd
fa995be
8d7e9e3
b52c6cc
f22ba43
a63456a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Commit message hook for enforcing conventional commit format | ||
| # This hook validates commit message format | ||
|
|
||
| commit_regex='^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .{1,50}' | ||
|
|
||
| error_msg="Aborting commit. Your commit message is missing either a type of change or the description of changes." | ||
|
|
||
| if ! grep -qE "$commit_regex" "$1"; then | ||
| echo "$error_msg" >&2 | ||
| echo "" >&2 | ||
| echo "Valid format: <type>(<scope>): <subject>" >&2 | ||
| echo "Example: feat(auth): add login functionality" >&2 | ||
| echo "" >&2 | ||
| echo "Valid types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert" >&2 | ||
| echo "" >&2 | ||
| echo "To bypass this check, use: git commit --no-verify" >&2 | ||
| exit 1 | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Pre-commit hook for running phpcs and phpstan on changed files | ||
| # This hook runs PHPCS and PHPStan on staged PHP files | ||
|
|
||
| set -e | ||
|
|
||
| # Colors for output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| echo -e "${GREEN}Running pre-commit checks...${NC}" | ||
|
|
||
| # Get list of staged PHP files | ||
| STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.php$' | grep -v '^vendor/' | grep -v '^tests/' || true) | ||
|
|
||
| if [ -z "$STAGED_FILES" ]; then | ||
| echo -e "${GREEN}No PHP files to check.${NC}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo -e "${YELLOW}Checking PHP files:${NC}" | ||
| echo "$STAGED_FILES" | ||
|
|
||
| # Check if composer dependencies are installed | ||
| if [ ! -f "vendor/bin/phpcs" ] || [ ! -f "vendor/bin/phpstan" ]; then | ||
| echo -e "${RED}Error: Please run 'composer install' to install development dependencies.${NC}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Run PHPCS on staged files | ||
| echo -e "${YELLOW}Running PHPCS...${NC}" | ||
| HAS_PHPCS_ERRORS=0 | ||
| for FILE in $STAGED_FILES; do | ||
| if [ -f "$FILE" ]; then | ||
| vendor/bin/phpcs --colors "$FILE" || HAS_PHPCS_ERRORS=1 | ||
| fi | ||
| done | ||
|
|
||
| # Run PHPStan on staged files | ||
| echo -e "${YELLOW}Running PHPStan...${NC}" | ||
| HAS_PHPSTAN_ERRORS=0 | ||
| PHPSTAN_FILES="" | ||
| for FILE in $STAGED_FILES; do | ||
| if [ -f "$FILE" ] && [[ "$FILE" =~ ^inc/ ]]; then | ||
| PHPSTAN_FILES="$PHPSTAN_FILES $FILE" | ||
| fi | ||
| done | ||
|
|
||
| if [ -n "$PHPSTAN_FILES" ]; then | ||
| vendor/bin/phpstan analyse --no-progress --error-format=table $PHPSTAN_FILES || HAS_PHPSTAN_ERRORS=1 | ||
| fi | ||
|
|
||
| # Exit with error if any checks failed | ||
| if [ $HAS_PHPCS_ERRORS -ne 0 ] || [ $HAS_PHPSTAN_ERRORS -ne 0 ]; then | ||
| echo -e "${RED}Pre-commit checks failed!${NC}" | ||
| echo -e "${YELLOW}To bypass these checks, use: git commit --no-verify${NC}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo -e "${GREEN}All pre-commit checks passed!${NC}" | ||
| exit 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| name: Code Quality | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| code-quality: | ||
| name: Code Quality Checks | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: '8.1' | ||
| extensions: mysqli, gd, bcmath | ||
| tools: composer | ||
|
|
||
| - name: Install PHP Dependencies | ||
| run: composer install --no-interaction --prefer-dist | ||
|
|
||
| - name: Get changed PHP files | ||
| id: changed-files | ||
| uses: tj-actions/changed-files@v44 | ||
| with: | ||
| files: | | ||
| **/*.php | ||
|
|
||
| - name: Run PHP CodeSniffer | ||
| if: steps.changed-files.outputs.any_changed == 'true' | ||
| run: | | ||
| echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}" | ||
| vendor/bin/phpcs --report=checkstyle --report-file=phpcs-report.xml ${{ steps.changed-files.outputs.all_changed_files }} || true | ||
|
|
||
| - name: Run PHPStan | ||
| if: steps.changed-files.outputs.any_changed == 'true' | ||
| run: | | ||
| echo "Running PHPStan on changed files: ${{ steps.changed-files.outputs.all_changed_files }}" | ||
| vendor/bin/phpstan analyse --error-format=checkstyle --no-progress ${{ steps.changed-files.outputs.all_changed_files }} > phpstan-report.xml || true | ||
|
|
||
| - name: Annotate PR with PHPCS results | ||
| uses: staabm/annotate-pull-request-from-checkstyle-action@v1 | ||
| if: github.event_name == 'pull_request' | ||
| with: | ||
| files: phpcs-report.xml | ||
| notices-as-failures: false | ||
|
|
||
| - name: Annotate PR with PHPStan results | ||
| uses: staabm/annotate-pull-request-from-checkstyle-action@v1 | ||
| if: github.event_name == 'pull_request' | ||
| with: | ||
| files: phpstan-report.xml | ||
| notices-as-failures: false |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -67,5 +67,15 @@ jobs: | |||||||||||||||||||
| rm -rf /tmp/wordpress-tests-lib /tmp/wordpress/ | ||||||||||||||||||||
| bash bin/install-wp-tests.sh wordpress_test root root mysql latest | ||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Run PHPUnit Tests | ||||||||||||||||||||
| run: vendor/bin/phpunit | ||||||||||||||||||||
| - name: Run PHPUnit Tests with Coverage | ||||||||||||||||||||
| run: vendor/bin/phpunit --coverage-clover=coverage.xml | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+70
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainCoverage will likely fail without a driver (xdebug/pcov/phpdbg). Running PHPUnit with coverage requires a coverage driver; otherwise you get “No code coverage driver available” and no coverage.xml is produced. Prefer enabling Xdebug via env, or run under phpdbg. (about.codecov.io) Apply this minimal change (uses Xdebug if present): - - name: Run PHPUnit Tests with Coverage
- run: vendor/bin/phpunit --coverage-clover=coverage.xml
+ - name: Run PHPUnit Tests with Coverage
+ run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover=coverage.xmlIf you’d rather avoid Xdebug, run via phpdbg: - run: vendor/bin/phpunit --coverage-clover=coverage.xml
+ run: phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xmlYou can confirm driver availability in CI by adding: 🏁 Script executed: #!/bin/bash
php -v
php -m | grep -Ei 'xdebug|pcov'
command -v phpdbg || echo "phpdbg not found"Length of output: 217 Enable a code‐coverage driver in CI
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| - name: Upload coverage reports to Codecov | ||||||||||||||||||||
| uses: codecov/codecov-action@v4 | ||||||||||||||||||||
| with: | ||||||||||||||||||||
| file: ./coverage.xml | ||||||||||||||||||||
| flags: unittests | ||||||||||||||||||||
| name: codecov-umbrella | ||||||||||||||||||||
| fail_ci_if_error: false | ||||||||||||||||||||
| env: | ||||||||||||||||||||
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||||||||||||||||||||
|
Comment on lines
+73
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainCodecov input key should be “files”, not “file”; consider OIDC. The action expects with: files: ./coverage.xml (plural). Using file will be ignored. Also, v4 supports token via env or OIDC; consider use_oidc: true to avoid secrets on PRs from forks. (github.com) Apply: - name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
- file: ./coverage.xml
+ files: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- env:
- CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
+ # Optional: differentiate matrices
+ # flags: unittests,php-${{ matrix.php-version }}
+ # Optional (public repos): prefer OIDC over token
+ # use_oidc: true
+ # If not using OIDC, keep the token env:
+ # env:
+ # CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}Optionally restrict upload to one PHP to reduce noise: - - name: Upload coverage reports to Codecov
+ - name: Upload coverage reports to Codecov
+ if: matrix.php-version == '8.3'Docs for inputs and OIDC usage: see Codecov Action README. (github.com) 🌐 Web query: 💡 Result: Short answer: The v4 action accepts a range of inputs (token, codecov_yml_path, commit_parent, directory, disable_search, disable_file_fixes, dry_run, env_vars, exclude, fail_ci_if_error, files, flags, name, os, verbose, etc.). The README/Action docs show both file and files historically, but the repository warns that the singular input file was deprecated in favor of files (use files). [1][2] References:
🌐 Web query: 💡 Result: Yes. codecov/codecov-action@v4 supports OIDC — set with with: use_oidc: true and any token will be ignored. [1][2] Note: for GitHub Actions you must give the action permission to mint an ID token (id-token: write). [2] Sources: [1] README (v4) codecov/codecov-action, [2] README (v5) codecov/codecov-action (OIDC permissions note). Replace deprecated
Apply: - name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
- file: ./coverage.xml
+ files: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- env:
- CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
+ # Optional: use OIDC for authentication (requires `permissions: id-token: write`)
+ # use_oidc: true
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
🤖 Prompt for AI Agents |
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Allow Merge/Revert defaults and breaking-change
!; relax subject length to 72.Current hook blocks default “Merge …” and “Revert …” messages and doesn’t allow Conventional Commits’ breaking-change
!. Also 50 chars is tight; 72 is common. Update regex and permit Merge/Revert early-exit.📝 Committable suggestion
🤖 Prompt for AI Agents