diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index c37d3c3..c80bc68 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -75,15 +75,23 @@ jobs: custom-cache-suffix: $(date -u "+%Y-%m") # Check the codestyle of the files against a threshold of expected errors and warnings. + # Keep track of the exit code as it determines whether to run the branch check or not. + # Exit code 128 means the thresholds needs to be lowered. Other exit codes imply CS errors. - name: Check PHP code style against the thresholds - run: composer check-cs-thresholds + id: thresholds + run: | + set +e + composer check-cs-thresholds + exitcode="$?" + echo "EXITCODE=$exitcode" >> $GITHUB_OUTPUT + exit "$exitcode" # Check the codestyle only of the files which were changed in the current branch. # This step will only be executed if the threshold check exited with a failure status. # The results of this CS check will be shown inline in the PR via the CS2PR tool. # @link https://github.com/staabm/annotate-pull-request-from-checkstyle/ - name: Check PHP code style for the changes made in the branch only - if: ${{ failure() }} + if: ${{ failure() && steps.thresholds.outputs.EXITCODE != 128 }} id: phpcs run: composer check-branch-cs -- ${{ steps.base_branch.outputs.REF }} diff --git a/config/composer/actions.php b/config/composer/actions.php index 13c01a3..2333209 100644 --- a/config/composer/actions.php +++ b/config/composer/actions.php @@ -153,6 +153,11 @@ public static function check_cs_thresholds() { $above_threshold = false; } + $threshold_exact = true; + if ( \strpos( $phpcs_output, ' than the threshold, great job!' ) !== false ) { + $threshold_exact = false; + } + /* * Don't run the branch check in CI/GH Actions as it prevents the errors from being shown inline. * The GH Actions script will run this via a separate script step. @@ -167,7 +172,15 @@ public static function check_cs_thresholds() { @\passthru( 'composer check-branch-cs' ); } - exit( ( $above_threshold === true || $return > 2 ) ? $return : 0 ); + $exit_code = 0; + if ( $above_threshold === true || $return > 2 ) { + $exit_code = $return; + } + elseif ( $threshold_exact === false ) { + $exit_code = 128; + } + + exit( $exit_code ); } /**