From a9e9cef2451af258e81f48a4ea383bc809816606 Mon Sep 17 00:00:00 2001 From: Eason Su Date: Fri, 8 Jul 2022 15:54:24 +0800 Subject: [PATCH 1/2] Fix the JSON syntax error of running PHPCS diff check when no changes are made --- .../js/github-actions/actions/phpcs-diff/action.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/js/github-actions/actions/phpcs-diff/action.yml b/packages/js/github-actions/actions/phpcs-diff/action.yml index 876c76d4..a9833df7 100644 --- a/packages/js/github-actions/actions/phpcs-diff/action.yml +++ b/packages/js/github-actions/actions/phpcs-diff/action.yml @@ -25,12 +25,19 @@ 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" + + 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 From 7d69c1edd9170a32f4edbcb887ce6a5a78ab1523 Mon Sep 17 00:00:00 2001 From: Eason Su Date: Mon, 11 Jul 2022 10:42:01 +0800 Subject: [PATCH 2/2] Add a code comment for the workaround of empty result in phpcs-diff action. Address https://github.com/woocommerce/grow/pull/27#pullrequestreview-1032779838 --- packages/js/github-actions/actions/phpcs-diff/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/js/github-actions/actions/phpcs-diff/action.yml b/packages/js/github-actions/actions/phpcs-diff/action.yml index a9833df7..f3963faf 100644 --- a/packages/js/github-actions/actions/phpcs-diff/action.yml +++ b/packages/js/github-actions/actions/phpcs-diff/action.yml @@ -28,6 +28,8 @@ runs: 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