1

I'm running PHPStan and PHPMD in my GitHub Actions workflow. Locally, both tools return a list of issues, but in GitHub Actions, no issues are reported. I've made sure the path is right in github actions by ls and pwd. I have no idea what I really need to delve into.

Local Environment:

  • Laravel Sail
  • PHP Version: 8.2.12
  • PHPStan Version: 1.10.47
  • PHPMD Version: 2.14.1 ※ I use the PHAR version to avoid errors with Laravel.

GitHub Actions Environment:

  • Runner: ubuntu-latest
  • PHP Version: 8.2 (configured in workflow)
  • PHPMD Version: 2.14.1 ※ I use the PHAR version to avoid errors with Laravel.

PHPStan and PHPMD are set up in the workflow as shown below:

  - name: Run PHPStan
run: |
./vendor/bin/phpstan analyse --error-format=raw --no-progress --memory-limit=1G --configuration=./phpstan.neon | reviewdog -f=phpstan -name="PHPStan" -reporter=github-pr-review -level=warning

- name: Run PHPMD
run: |
  php /usr/local/bin/phpmd.phar ./app/Exceptions,./app/Http,./app/Models,./app/Contracts,./app/Repositories,./app/Services,./routes,./tests checkstyle ./phpmd.xml | reviewdog -f=checkstyle -name="PHPMD" -reporter=github-pr-review -level=warning

Logs in github action

- PHPStan -
Run ./vendor/bin/phpstan analyse --error-format=raw --no-progress --memory-limit=1G --configuration=./phpstan.neon | reviewdog  -f=phpstan -name="PHPStan"  -reporter=github-pr-review -level=warning

  ./vendor/bin/phpstan analyse --error-format=raw --no-progress --memory-limit=1G --configuration=./phpstan.neon | reviewdog  -f=phpstan -name="PHPStan"  -reporter=github-pr-review -level=warning
  shell: /usr/bin/bash -e {0}
  env:
    COMPOSER_PROCESS_TIMEOUT: 0
    COMPOSER_NO_INTERACTION: 1
    COMPOSER_NO_AUDIT: 1
    REVIEWDOG_GITHUB_API_TOKEN: ***

- PHPMD -    
Run php /usr/local/bin/phpmd.phar ./app/Exceptions,./app/Http,./app/Models,./app/Contracts,./app/Repositories,./app/Services,./routes,./tests checkstyle phpmd.xml | reviewdog -f=checkstyle -name="PHPMD" -reporter=github-pr-review -level=warning

  php /usr/local/bin/phpmd.phar ./app/Exceptions,./app/Http,./app/Models,./app/Contracts,./app/Repositories,./app/Services,./routes,./tests checkstyle phpmd.xml | reviewdog -f=checkstyle -name="PHPMD" -reporter=github-pr-review -level=warning
  shell: /usr/bin/bash -e {0}
  env:
    COMPOSER_PROCESS_TIMEOUT: 0
    COMPOSER_NO_INTERACTION: 1
    COMPOSER_NO_AUDIT: 1
    REVIEWDOG_GITHUB_API_TOKEN: ***

Has anyone encountered this issue, or can anyone suggest what might be causing this discrepancy between the local and CI environments?

1
  • Please include your GHA workflow in your question. Commented Dec 6, 2023 at 7:34

1 Answer 1

2

Remove these parts from your commands that run PHPStan:

  • --error-format=raw
  • | reviewdog -f=phpstan -name="PHPStan" -reporter=github-pr-review -level=warning

So basically run PHPStan as usual as you'd run it locally:

./vendor/bin/phpstan analyse --no-progress --memory-limit=1G --configuration=./phpstan.neon

PHPStan automatically detects it runs in GitHub Actions and will output the correct format understood by GitHub Actions to show errors in pull requests on specific lines where the errors occurred.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response. I wasn't aware that GitHub Actions could display errors without using reviewdog. After implementing your suggestion, I realized that GitHub Actions itself can indicate errors, and all the necessary information is available in the GitHub Actions logs. I applied the same approach to my phpmd settings and it worked well. I appreciate your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.