PHPStan and PHPMD outputs missing in GitHub Actions but present locally

140 views Asked by At

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

There are 1 answers

1
Ondřej Mirtes On BEST ANSWER

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.