diff --git a/packages/js/github-actions/actions/phpcs-diff/action.yml b/packages/js/github-actions/actions/phpcs-diff/action.yml index 876c76d4..f3963faf 100644 --- a/packages/js/github-actions/actions/phpcs-diff/action.yml +++ b/packages/js/github-actions/actions/phpcs-diff/action.yml @@ -25,12 +25,21 @@ runs: # a workflow to a pull request, it uses the revision of a merge commit to run the workflow # as well. Therefore, `git diff HEAD^...HEAD` includes all diffs of a PR. run: | - vendor/bin/diffFilter --phpcsStrict <(git diff HEAD^...HEAD) <(vendor/bin/phpcs ./* -q --report=json) --report=phpcs 0 > /tmp/phpcs-diff.json + JSON_REPORT="/tmp/phpcs-diff.json" + vendor/bin/diffFilter --phpcsStrict <(git diff HEAD^...HEAD) <(vendor/bin/phpcs ./* -q --report=json) --report=phpcs 0 > "$JSON_REPORT" + + # It's a workaround that prevents the empty result from being passed as a JSON file to annotate-phpcs-report.js + # Related issue: https://github.com/exussum12/coverageChecker/issues/72 + if [ ! -s "$JSON_REPORT" ]; then + echo "No changes." + exit 0 + fi + cd "${{ github.action_path }}" - node annotate-phpcs-report.js /tmp/phpcs-diff.json + node annotate-phpcs-report.js "$JSON_REPORT" cd - - TOTAL_ERRORS=$(jq ".totals.errors" /tmp/phpcs-diff.json) + TOTAL_ERRORS=$(jq ".totals.errors" "$JSON_REPORT" if [ "$TOTAL_ERRORS" != "0" ]; then exit 1 fi