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

Add option to exclude pr comments when no terraform changes are present #619

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions terraform-v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to the orb will be documented in this file.
Orbs are immutable, some orb versions with no significant changes are
not listed

## ovotech/[email protected]
- Add paramter `add_no_changes_comment` to exclude PR comments where there are no changes

## ovotech/[email protected]
- Disable bash xtrace when handling registry tokens to avoid displaying them in logs

Expand Down
6 changes: 6 additions & 0 deletions terraform-v2/orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ aliases:
type: "boolean"
description: "Add the plan to a GitHub PR"
default: true
add_no_changes_comment: &add_no_changes_comment
add_no_changes_comment:
type: "boolean"
description: "Add the plan to a GitHub PR even if there are no changes"
default: true
reuse_plan: &reuse_plan
reuse_plan:
type: "boolean"
Expand Down Expand Up @@ -135,6 +140,7 @@ commands:
<<: *parallelism
<<: *label
<<: *add_github_comment
<<: *add_no_changes_comment
<<: *target
<<: *trim_plan
steps:
Expand Down
2 changes: 1 addition & 1 deletion terraform-v2/orb_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ovotech/[email protected].9
ovotech/[email protected].10
14 changes: 11 additions & 3 deletions terraform-v2/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ else
| tee /dev/fd/3 \
| $COMPACT_PLAN \
>plan.txt

readonly TF_EXIT=${PIPESTATUS[0]}
fi

Expand All @@ -43,7 +43,15 @@ if [[ -n "$GITHUB_TOKEN" && "<< parameters.add_github_comment >>" == "true" ]];
export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"
export label="<< parameters.label >>"

if ! python3 /tmp/github.py plan <plan.txt; then
echo "Error adding comment to PR"
if grep 'No changes' plan.txt >/dev/null 2>&1; then
if [[ "<< parameters.add_no_changes_comment >>" == "true" ]]; then
if ! python3 /tmp/github.py plan <plan.txt; then
echo "Error adding comment to PR"
fi
fi
else
if ! python3 /tmp/github.py plan <plan.txt; then
echo "Error adding comment to PR"
fi
fi
fi