Skip to content

Commit

Permalink
GH Actions: show PHPCS results both in log + PR
Browse files Browse the repository at this point in the history
As it was, results of PHPCS runs would only ever show inline in a commit code view/PR code view.

This is confusing as people will often try to find an output log of the run in the GH Actions build log, not realizing the scan results are not available in the GH Actions log.

This commit changes the steps in the GH Actions workflows for both the PHPCS run against the WordPress Coding Standards as well as for the run against PHPCompatibility to show the full scan results report in the GH Actions logs **_as well as_** show the results in commit/PR code views and still fail the build correctly when new issues are detected.

I've elected to store the (temporary) `phpcs-report.xml` file in the `.cache` subdirectory as that directory is (git/svn)-ignored by default already to prevent this new, temporary file from interfering with the `git diff` check at the end of the workflows.

Note: I'm also removing the `-q` (quiet) flag from the PHPCS runs as it could give the misleading impression that nothing happened in the step for a successfull run. The progress report being shown will take away that impression.

Refs:
* https://github.com/staabm/annotate-pull-request-from-checkstyle#using-php_codesniffer
* WordPress/gutenberg#44536 (comment)
  • Loading branch information
jrfnl committed Sep 29, 2022
1 parent c861d58 commit e300711
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,18 @@ jobs:
run: phpcs -i

- name: Run PHPCS on all Core files
run: phpcs -q -n --report=checkstyle | cs2pr
continue-on-error: true
run: phpcs -n --report-full --report-checkstyle=./.cache/phpcs-report.xml

- name: Show PHPCS results in PR
run: cs2pr ./.cache/phpcs-report.xml

- name: Check test suite files for warnings
run: phpcs tests -q --report=checkstyle | cs2pr
continue-on-error: true
run: phpcs tests --report-full --report-checkstyle=./.cache/phpcs-tests-report.xml

- name: Show test suite scan results in PR
run: cs2pr ./.cache/phpcs-tests-report.xml

- name: Ensure version-controlled files are not modified during the tests
run: git diff --exit-code
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/php-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ jobs:
run: phpcs -i

- name: Run PHP compatibility tests
run: phpcs --standard=phpcompat.xml.dist -q --report=checkstyle | cs2pr
continue-on-error: true
run: phpcs --standard=phpcompat.xml.dist --report-full --report-checkstyle=./.cache/phpcs-compat-report.xml

- name: Show PHPCompatibility results in PR
run: cs2pr ./.cache/phpcs-compat-report.xml

- name: Ensure version-controlled files are not modified or deleted
run: git diff --exit-code
Expand Down

0 comments on commit e300711

Please sign in to comment.