circleci-orbs icon indicating copy to clipboard operation
circleci-orbs copied to clipboard

[terraform] No error on failed github comment

Open mccall114 opened this issue 4 years ago • 0 comments

If a terraform plan fails to post a comment to github, it doesn't return an error code, so CircleCI does not recognize this as a failed job:

Plan: 1 to add, 114 to change, 6 to destroy.
Traceback (most recent call last):
  File "/tmp/github.py", line 178, in <module>
    comment.plan = sys.stdin.read().strip()
  File "/tmp/github.py", line 136, in plan
    self._update_comment()
  File "/tmp/github.py", line 164, in _update_comment
    response.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: https://api.github.com/repos/<redacted>
CircleCI received exit code 0

Without an error returned, a reviewer may approve the PR without realizing a plan is missing from the PR comments. With an error returned, a github status check for the CircleCI job could show that the plan failed to post, ensuring the output is reviewed.

Would like to add exit 1 here:

    if ! python3 /tmp/github.py plan <plan.txt; then
        echo "Error adding comment to PR"
    fi

mccall114 avatar Aug 27 '20 18:08 mccall114