Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the JSON syntax error of running phpcd-diff action when no changes are made #27

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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