-
-
Notifications
You must be signed in to change notification settings - Fork 36
Description
Describe the bug
When the action is run with comment-pr: on-diff, it works as intended when ran with command: plan: comments are only added if the plan contains changes, and if a commit is pushed that causes a re-run to plan "No changes", then the comment is removed again.
Unfortunately it has a slightly problematic behavior when ran with command: apply. In that case you'd expect the comment to be updated to "Applied ..." if it exists, just like it is without comment-pr: on-diff, but the comment is instead deleted entirely. This makes it difficult to evaluate what infrastructure changes were actually applied at a later time.
I believe this behavior happens because terraform apply outputs an exit code of 0 when it succeeds. This causes this code to delete the comment instead of updating it:
Lines 488 to 491 in 5b5ec65
| elif [[ ("$INPUTS_COMMENT_PR" == "on-diff" || "$INPUTS_COMMENT_PR" == "on-change") && "$exitcode" -eq 0 && -n "$bot_comment" ]]; then | |
| gh api /repos/${{ github.repository }}/issues/comments/${bot_comment} --header "$GH_API" --method DELETE | |
| exit 0 | |
| fi |
To Reproduce
- Run the action with
command: planandcomment-pr: on-difffor a PR with changes. - Observe that a comment is added to the PR
- Run the action with
command: applyandcomment-pr: on-difffor that same PR. - Observe that the comment is deleted.
Expected behavior
The comment is updated to reflect that it has been applied, but is not deleted.