Replies: 6 comments 4 replies
-
|
The most reliable way to validate PHP syntax in GitHub Actions is to use To lint a single file: - name: Validate PHP syntax
run: php -l path/to/your/script.phpTo lint all PHP files recursively: - name: Validate PHP syntax
run: find . -name "*.php" -not -path "./vendor/*" | xargs -I{} php -l {}
Full example workflow: name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Validate PHP syntax
run: find . -name "*.php" -not -path "./vendor/*" | xargs -I{} php -l {}
- name: Deploy via SSH
run: ssh user@yourserver "cd /var/www && git pull"Why not the built-in server? If you also want to catch runtime/logic issues beyond syntax, consider adding PHPStan or Psalm as a next step. |
Beta Was this translation helpful? Give feedback.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
-
|
The issue here is not that PHP validation is “broken” on GitHub Actions — it’s that the validation strategy is incorrect. You’re currently relying on:
That approach is fundamentally unreliable because:
Correct approach: validate PHP at multiple layersYou should treat validation as three independent checks: 1. Syntax validation (fast + mandatory)Use PHP’s built-in linter: - name: PHP Lint
run: find . -name "*.php" -exec php -l {} \;This will:
2. Static analysis (catches real bugs)Add tools like:
Example: - name: Install dependencies
run: composer install --no-progress --prefer-dist
- name: Run PHPStan
run: vendor/bin/phpstan analyseThis catches:
3. Runtime validation (actual behavior)Instead of relying on HTTP status, explicitly fail on errors: - name: Run PHP script with strict error handling
run: |
php -d display_errors=1 -d log_errors=1 -d error_reporting=E_ALL script.phpOR better — write proper tests: - name: Run PHPUnit
run: vendor/bin/phpunitWhy your current method failsYour current pipeline:
Problems:
So even broken code can appear “successful”. Recommended CI structureA proper pipeline should look like: jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Install dependencies
run: composer install --no-progress
- name: Lint
run: find . -name "*.php" -exec php -l {} \;
- name: Static Analysis
run: vendor/bin/phpstan analyse
- name: Tests
run: vendor/bin/phpunitThen only deploy if all steps pass. Key takeawayYou don’t validate PHP by checking HTTP responses. You validate it by:
Bonus (production-grade)If you want this to be bulletproof:
|
Beta Was this translation helpful? Give feedback.
-
|
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
🏷️ Discussion Type
Question
💬 Feature/Topic Area
ARC (Actions Runner Controller)
Discussion Details
I have a simple GitHub workflow that runs git pull on the server via SSH. This is a simple PHP script.
I want to add validation of the code before I update the server so I don't upload broken PHP code.
But in return, the PHP building server returns 200 even when there is an error.
And give errors when I try to enforce the checks.
What can I do to validate that the PHP code actually works in GitHub Actions?
Beta Was this translation helpful? Give feedback.
All reactions