Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit 5162a59

Browse files
authored
Merge pull request #65 from jalaziz/log-coloring
Enable output coloring for logs
2 parents 788d1b9 + 3de54d5 commit 5162a59

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

apply/entrypoint.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/sh
22

3+
# stripcolors takes some output and removes ANSI color codes.
4+
stripcolors() {
5+
echo "$1" | sed 's/\x1b\[[0-9;]*m//g'
6+
}
7+
38
# wrap takes some output and wraps it in a collapsible markdown section if
49
# it's over $TF_ACTION_WRAP_LINES long.
510
wrap() {
@@ -39,7 +44,7 @@ if [[ ! -z "$TF_ACTION_WORKSPACE" ]] && [[ "$TF_ACTION_WORKSPACE" != "default" ]
3944
fi
4045

4146
set +e
42-
OUTPUT=$(sh -c "TF_IN_AUTOMATION=true terraform apply -no-color -auto-approve -input=false $*" 2>&1)
47+
OUTPUT=$(sh -c "TF_IN_AUTOMATION=true terraform apply -auto-approve -input=false $*" 2>&1)
4348
SUCCESS=$?
4449
echo "$OUTPUT"
4550
set -e
@@ -52,6 +57,7 @@ if [ "$TF_ACTION_COMMENT" = "1" ] || [ "$TF_ACTION_COMMENT" = "false" ] || [ "$P
5257
fi
5358

5459
# Build the comment we'll post to the PR.
60+
OUTPUT=$(stripcolors "$OUTPUT")
5561
COMMENT=""
5662
if [ $SUCCESS -ne 0 ]; then
5763
OUTPUT=$(wrap "$OUTPUT")

fmt/entrypoint.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#!/bin/sh
2+
3+
# stripcolors takes some output and removes ANSI color codes.
4+
stripcolors() {
5+
echo "$1" | sed 's/\x1b\[[0-9;]*m//g'
6+
}
7+
28
set -e
39
cd "${TF_ACTION_WORKING_DIR:-.}"
410

511
set +e
6-
OUTPUT=$(sh -c "terraform fmt -no-color -check -list -recursive $*" 2>&1)
12+
OUTPUT=$(sh -c "terraform fmt -check -list -recursive $*" 2>&1)
713
SUCCESS=$?
814
echo "$OUTPUT"
915
set -e
@@ -16,6 +22,7 @@ if [ "$TF_ACTION_COMMENT" = "1" ] || [ "$TF_ACTION_COMMENT" = "false" ]; then
1622
exit $SUCCESS
1723
fi
1824

25+
OUTPUT=$(stripcolors "$OUTPUT")
1926
if [ $SUCCESS -eq 2 ]; then
2027
# If it exits with 2, then there was a parse error and the command won't have
2128
# printed out the files that have failed. In this case we comment back with the

init/entrypoint.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/sh
2+
3+
# stripcolors takes some output and removes ANSI color codes.
4+
stripcolors() {
5+
echo "$1" | sed 's/\x1b\[[0-9;]*m//g'
6+
}
7+
28
set -e
39
cd "${TF_ACTION_WORKING_DIR:-.}"
410

@@ -12,7 +18,7 @@ fi
1218

1319
set +e
1420
export TF_APPEND_USER_AGENT="terraform-github-actions/1.0"
15-
OUTPUT=$(sh -c "terraform init -no-color -input=false $*" 2>&1)
21+
OUTPUT=$(sh -c "terraform init -input=false $*" 2>&1)
1622
SUCCESS=$?
1723
echo "$OUTPUT"
1824
set -e
@@ -25,6 +31,7 @@ if [ "$TF_ACTION_COMMENT" = "1" ] || [ "$TF_ACTION_COMMENT" = "false" ]; then
2531
exit $SUCCESS
2632
fi
2733

34+
OUTPUT=$(stripcolors "$OUTPUT")
2835
COMMENT="#### \`terraform init\` Failed
2936
\`\`\`
3037
$OUTPUT

plan/entrypoint.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/sh
22

3+
# stripcolors takes some output and removes ANSI color codes.
4+
stripcolors() {
5+
echo "$1" | sed 's/\x1b\[[0-9;]*m//g'
6+
}
7+
38
# wrap takes some output and wraps it in a collapsible markdown section if
49
# it's over $TF_ACTION_WRAP_LINES long.
510
wrap() {
@@ -39,7 +44,7 @@ if [[ ! -z "$TF_ACTION_WORKSPACE" ]] && [[ "$TF_ACTION_WORKSPACE" != "default" ]
3944
fi
4045

4146
set +e
42-
OUTPUT=$(sh -c "TF_IN_AUTOMATION=true terraform plan -no-color -input=false $*" 2>&1)
47+
OUTPUT=$(sh -c "TF_IN_AUTOMATION=true terraform plan -input=false $*" 2>&1)
4348
SUCCESS=$?
4449
echo "$OUTPUT"
4550
set -e
@@ -49,6 +54,7 @@ if [ "$TF_ACTION_COMMENT" = "1" ] || [ "$TF_ACTION_COMMENT" = "false" ]; then
4954
fi
5055

5156
# Build the comment we'll post to the PR.
57+
OUTPUT=$(stripcolors "$OUTPUT")
5258
COMMENT=""
5359
if [ $SUCCESS -ne 0 ]; then
5460
OUTPUT=$(wrap "$OUTPUT")

validate/entrypoint.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/sh
2+
3+
# stripcolors takes some output and removes ANSI color codes.
4+
stripcolors() {
5+
echo "$1" | sed 's/\x1b\[[0-9;]*m//g'
6+
}
7+
28
set -e
39
cd "${TF_ACTION_WORKING_DIR:-.}"
410

@@ -7,7 +13,7 @@ if [[ ! -z "$TF_ACTION_WORKSPACE" ]] && [[ "$TF_ACTION_WORKSPACE" != "default" ]
713
fi
814

915
set +e
10-
OUTPUT=$(sh -c "terraform validate -no-color $*" 2>&1)
16+
OUTPUT=$(sh -c "terraform validate $*" 2>&1)
1117
SUCCESS=$?
1218
echo "$OUTPUT"
1319
set -e
@@ -20,6 +26,7 @@ if [ "$TF_ACTION_COMMENT" = "1" ] || [ "$TF_ACTION_COMMENT" = "false" ]; then
2026
exit $SUCCESS
2127
fi
2228

29+
OUTPUT=$(stripcolors "$OUTPUT")
2330
COMMENT="#### \`terraform validate\` Failed
2431
\`\`\`
2532
$OUTPUT

0 commit comments

Comments
 (0)