Skip to content

Commit

Permalink
feat: stream terraform/helmfile output to stdout (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcind authored Mar 16, 2022
1 parent 5af9268 commit 39a279a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
7 changes: 5 additions & 2 deletions helmfile-actions/apply.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#!/bin/bash

function helmfileApply {
set -o pipefail
tempfile=$(mktemp)
# suppress secrets in workflows #incident-150567
output=$(helmfile --no-color apply --suppress-secrets ${*} 2>&1)
helmfile --no-color apply --suppress-secrets ${*} 2>&1 | tee $tempfile
exitCode=$?
output=$(cat $tempfile)
rm $tempfile

if [ ${exitCode} -eq 0 ]; then
echo "Successfully ran helmfile apply command."
else
echo "Error: Failed to run helmfile apply"
fi

echo "${output}"
echo
exit ${exitCode}
}
9 changes: 5 additions & 4 deletions helmfile-actions/diff.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/bin/bash

function helmfileDiff {
set -o pipefail
tempfile=$(mktemp)
# suppress secrets in workflows #incident-150567
output=$(helmfile --no-color diff --detailed-exitcode --suppress-secrets ${*} 2>&1)
helmfile --no-color diff --detailed-exitcode --suppress-secrets ${*} 2>&1 | tee $tempfile
exitCode=$?
output=$(cat $tempfile)
rm $tempfile
hasChanges=false
commentStatus="Failed"

if [ ${exitCode} -eq 0 ]; then
echo "Successfully ran helmfile diff command. No changes were found"
echo "${output}"
echo
echo "::set-output name=diff-has-changes::${hasChanges}"
exit ${exitCode}
Expand All @@ -22,7 +25,6 @@ function helmfileDiff {
commentStatus="Success"

echo "Successfully ran helmfile diff command. Changes were found"
echo "${output}"
echo

# If output is longer than max length (65536 characters), keep last part
Expand All @@ -31,7 +33,6 @@ function helmfileDiff {

if [ ${exitCode} -ne 0 ]; then
echo "Error: Failed to run helmfile diff"
echo "${output}"
echo

# If output is longer than max length (65536 characters), keep last part
Expand Down
8 changes: 5 additions & 3 deletions terraform-actions/apply.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/bin/bash

function terraformApply {
output=$(terraform apply -no-color -auto-approve -input=false ${*} 2>&1)
set -o pipefail
tempfile=$(mktemp)
terraform apply -no-color -auto-approve -input=false ${*} 2>&1 | tee $tempfile
exitCode=$?
output=$(cat $tempfile)
rm $tempfile

if [ ${exitCode} -eq 0 ]; then
echo "Successfully ran terraform apply command."
else
echo "Error: Failed to run terraform apply"
fi

echo "${output}"
echo
exit ${exitCode}
}
8 changes: 5 additions & 3 deletions terraform-actions/fmt.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/bin/bash

function terraformFmt {
output=$(terraform fmt -check=true -write=false -diff -recursive -no-color ${*} 2>&1)
set -o pipefail
tempfile=$(mktemp)
terraform fmt -check=true -write=false -diff -recursive -no-color ${*} 2>&1 | tee $tempfile
exitCode=$?
output=$(cat $tempfile)
rm $tempfile
commentStatus="Failed"

if [ ${exitCode} -eq 0 ]; then
echo "Successfully ran terraform fmt command."
echo "${output}"
echo
exit ${exitCode}
fi

echo "Error: terraform fmt found changes"
echo "${output}"
echo

if [ "$GITHUB_EVENT_NAME" == "pull_request" ] && [ "${commentStatus}" == "Failed" ]; then
Expand Down
8 changes: 5 additions & 3 deletions terraform-actions/init.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/bin/bash

function terraformInit {
output=$(terraform init -no-color -input=false ${*} 2>&1)
set -o pipefail
tempfile=$(mktemp)
terraform init -no-color -input=false ${*} 2>&1 | tee $tempfile
exitCode=$?
output=$(cat $tempfile)
rm $tempfile
commentStatus="Failed"

if [ ${exitCode} -eq 0 ]; then
echo "Successfully ran terraform init command."
echo "${output}"
echo
exit ${exitCode}
fi

echo "Error: Failed to run terraform init"
echo "${output}"
echo

if [ "$GITHUB_EVENT_NAME" == "pull_request" ] && [ "${commentStatus}" == "Failed" ]; then
Expand Down
9 changes: 5 additions & 4 deletions terraform-actions/plan.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/bin/bash

function terraformPlan {
output=$(terraform plan -no-color -detailed-exitcode ${*} 2>&1)
set -o pipefail
tempfile=$(mktemp)
terraform plan -no-color -detailed-exitcode ${*} 2>&1 | tee $tempfile
exitCode=$?
output=$(cat $tempfile)
rm $tempfile
hasChanges=false
commentStatus="Failed"

if [ ${exitCode} -eq 0 ]; then
echo "Successfully ran terraform plan command. No changes were found"
echo "${output}"
echo
echo "::set-output name=plan-has-changes::${hasChanges}"
exit ${exitCode}
Expand All @@ -21,7 +24,6 @@ function terraformPlan {
commentStatus="Success"

echo "Successfully ran terraform plan command. Changes were found"
echo "${output}"
echo

if echo "${output}" | egrep '^-{72}$' &> /dev/null; then
Expand All @@ -40,7 +42,6 @@ function terraformPlan {

if [ ${exitCode} -ne 0 ]; then
echo "Error: Failed to run terraform plan"
echo "${output}"
echo
fi

Expand Down
8 changes: 5 additions & 3 deletions terraform-actions/validate.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/bin/bash

function terraformValidate {
output=$(terraform validate -no-color ${*} 2>&1)
set -o pipefail
tempfile=$(mktemp)
terraform validate -no-color ${*} 2>&1 | tee $tempfile
exitCode=$?
output=$(cat $tempfile)
rm $tempfile
commentStatus="Failed"

if [ ${exitCode} -eq 0 ]; then
echo "Successfully ran terraform validate command."
echo "${output}"
echo
exit ${exitCode}
fi

echo "Error: Failed to run terraform validate"
echo "${output}"
echo

if [ "$GITHUB_EVENT_NAME" == "pull_request" ] && [ "${commentStatus}" == "Failed" ]; then
Expand Down

0 comments on commit 39a279a

Please sign in to comment.