Skip to content

Commit

Permalink
Merge pull request #27 from woocommerce/fix/phpcs-diff-no-changes
Browse files Browse the repository at this point in the history
Fix the JSON syntax error of running `phpcd-diff` action when no changes are made
  • Loading branch information
eason9487 committed Jul 11, 2022
2 parents e124634 + 7d69c1e commit 5567a0a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/js/github-actions/actions/phpcs-diff/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,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

0 comments on commit 5567a0a

Please sign in to comment.