Skip to content

Commit 6e2c923

Browse files
authored
chore: add color to porch tests (#2847)
This should make it easier to find the error when porch tests fail.
1 parent d50f858 commit 6e2c923

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

e2e/live/end-to-end-test.sh

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ shift $((OPTIND-1))
107107

108108
[ "${1:-}" = "--" ] && shift
109109

110+
###########################################################################
111+
# Colors
112+
###########################################################################
113+
114+
GREEN='\033[0;32m'
115+
RED='\033[0;31m'
116+
NC='\033[0m' # No Color
117+
110118
###########################################################################
111119
# Helper functions
112120
###########################################################################
@@ -124,12 +132,12 @@ function downloadPreviousKpt {
124132
echo "Running on Darwin"
125133
curl -LJ -o kpt.tar.gz https://github.com/GoogleContainerTools/kpt/releases/download/v0.39.2/kpt_darwin_amd64-0.39.2.tar.gz > $OUTPUT_DIR/kptdownload 2>&1
126134
else
127-
echo "ERROR: Unknown OS $uname"
135+
echo -e "${RED}ERROR${NC}: Unknown OS $uname"
128136
exit 1
129137
fi
130138
tar -xvf kpt.tar.gz > $OUTPUT_DIR/kptdownload 2>&1
131139
mv kpt $BIN_DIR/previouskpt
132-
echo "Downloading previous kpt binary...SUCCESS"
140+
echo -e "Downloading previous kpt binary...${GREEN}SUCCESS${NC}"
133141
rm kpt.tar.gz LICENSES.txt lib.zip
134142
set +e
135143
}
@@ -147,12 +155,12 @@ function downloadKpt1.0 {
147155
echo "Running on Darwin"
148156
curl -LJ -o kpt.tar.gz https://github.com/GoogleContainerTools/kpt/releases/download/v1.0.0-beta.13/kpt_darwin_amd64-1.0.0-beta.13.tar.gz > $OUTPUT_DIR/kptdownload 2>&1
149157
else
150-
echo "ERROR: Unknown OS $uname"
158+
echo -e "${RED}ERROR${NC}: Unknown OS $uname"
151159
exit 1
152160
fi
153161
tar -xvf kpt.tar.gz > $OUTPUT_DIR/kptdownload 2>&1
154162
mv kpt $BIN_DIR/kpt1.0.0
155-
echo "Downloading 1.0.0 kpt binary...SUCCESS"
163+
echo -e "Downloading 1.0.0 kpt binary...${GREEN}SUCCESS${NC}"
156164
rm kpt.tar.gz LICENSES.txt lib.zip
157165
set +e
158166
}
@@ -167,7 +175,7 @@ function buildKpt {
167175
go version
168176
echo "Building kpt locally..."
169177
go build -o $BIN_DIR -v . > $OUTPUT_DIR/kptbuild 2>&1
170-
echo "Building kpt locally...SUCCESS"
178+
echo -e "Building kpt locally...${GREEN}SUCCESS${NC}"
171179

172180
else
173181
echo "Building kpt using dependencies at HEAD..."
@@ -177,32 +185,32 @@ function buildKpt {
177185
mkdir -p $KPT_SRC_DIR
178186
echo "Downloading kpt repository at HEAD..."
179187
git clone https://github.com/GoogleContainerTools/kpt ${KPT_SRC_DIR} > ${OUTPUT_DIR}/kptbuild 2>&1
180-
echo "Downloading kpt repository at HEAD...SUCCESS"
188+
echo -e "Downloading kpt repository at HEAD...${GREEN}SUCCESS${NC}"
181189
# Clone cli-utils repository into source directory
182190
CLI_UTILS_SRC_DIR="${SRC_DIR}/sigs.k8s.io/cli-utils"
183191
mkdir -p $CLI_UTILS_SRC_DIR
184192
echo "Downloading cli-utils repository at HEAD..."
185193
git clone https://github.com/kubernetes-sigs/cli-utils ${CLI_UTILS_SRC_DIR} > ${OUTPUT_DIR}/kptbuild 2>&1
186-
echo "Downloading cli-utils repository at HEAD...SUCCESS"
194+
echo -e "Downloading cli-utils repository at HEAD...${GREEN}SUCCESS${NC}"
187195
# Clone kustomize respository into source directory
188196
KUSTOMIZE_SRC_DIR="${SRC_DIR}/sigs.k8s.io/kustomize"
189197
mkdir -p $KUSTOMIZE_SRC_DIR
190198
echo "Downloading kustomize repository at HEAD..."
191199
git clone https://github.com/kubernetes-sigs/kustomize ${KUSTOMIZE_SRC_DIR} > ${OUTPUT_DIR}/kptbuild 2>&1
192-
echo "Downloading kustomize repository at HEAD...SUCCESS"
200+
echo -e "Downloading kustomize repository at HEAD...${GREEN}SUCCESS${NC}"
193201
# Tell kpt to build using the locally downloaded dependencies
194202
echo "Updating kpt/go.mod to reference locally downloaded repositories..."
195203
echo -e "\n\nreplace sigs.k8s.io/cli-utils => ../../../sigs.k8s.io/cli-utils" >> ${KPT_SRC_DIR}/go.mod
196204
echo -e "replace sigs.k8s.io/kustomize/cmd/config => ../../../sigs.k8s.io/kustomize/cmd/config" >> ${KPT_SRC_DIR}/go.mod
197205
echo -e "replace sigs.k8s.io/kustomize/kyaml => ../../../sigs.k8s.io/kustomize/kyaml\n" >> ${KPT_SRC_DIR}/go.mod
198-
echo "Updating kpt/go.mod to reference locally downloaded repositories...SUCCESS"
206+
echo -e "Updating kpt/go.mod to reference locally downloaded repositories...${GREEN}SUCCESS${NC}"
199207
# Build kpt using the cloned directories
200208
export GOPATH=${TMP_DIR}
201209
echo "Building kpt..."
202210
(cd -- ${KPT_SRC_DIR} && go build -o $BIN_DIR -v . > ${OUTPUT_DIR}/kptbuild)
203-
echo "Building kpt...SUCCESS"
211+
echo -e "Building kpt...${GREEN}SUCCESS${NC}"
204212
echo
205-
echo "Building kpt using dependencies at HEAD...SUCCESS"
213+
echo -e "Building kpt using dependencies at HEAD...${GREEN}SUCCESS${NC}"
206214
fi
207215
set +e
208216
}
@@ -216,13 +224,13 @@ function createTestSuite {
216224
# Create the k8s cluster
217225
echo "Deleting kind cluster..."
218226
kind delete cluster > /dev/null 2>&1
219-
echo "Deleting kind cluster...SUCCESS"
227+
echo -e "Deleting kind cluster...${GREEN}SUCCESS${NC}"
220228
echo "Creating kind cluster..."
221229
kind create cluster --image=kindest/node:v${K8S_VERSION} > $OUTPUT_DIR/k8sstartup 2>&1
222230
kubectl wait node/kind-control-plane --for condition=ready --timeout=2m
223-
echo "Creating kind cluster...SUCCESS"
231+
echo -e "Creating kind cluster...${GREEN}SUCCESS${NC}"
224232
echo
225-
echo "Setting Up Test Suite...SUCCESS"
233+
echo -e "Setting Up Test Suite...${GREEN}SUCCESS${NC}"
226234
echo
227235
set +e
228236
}
@@ -390,12 +398,12 @@ function assertPodNotExists {
390398
# printResult prints the results of the previous assert statements
391399
function printResult {
392400
if [ -f $OUTPUT_DIR/errors ]; then
393-
echo "ERROR"
401+
echo -e "${RED}ERROR${NC}"
394402
cat $OUTPUT_DIR/errors
395403
echo
396404
rm -f $OUTPUT_DIR/errors
397405
else
398-
echo "SUCCESS"
406+
echo -e "${GREEN}SUCCESS${NC}"
399407
fi
400408
echo
401409
}
@@ -933,7 +941,13 @@ cp -f e2e/live/testdata/Kptfile e2e/live/testdata/migrate-case-1a
933941
cp -f e2e/live/testdata/Kptfile e2e/live/testdata/migrate-case-1b
934942
cp -f e2e/live/testdata/Kptfile e2e/live/testdata/migrate-error
935943
kind delete cluster
936-
echo "FINISHED"
944+
echo -e "Cleaning up cluster...${GREEN}SUCCESS${NC}"
937945

938946
# Return error code if tests have failed
939-
exit $HAS_TEST_FAILURE
947+
if [[ ${HAS_TEST_FAILURE} -gt 0 ]]; then
948+
echo -e "${RED}ERROR: E2E Tests Failed${NC}"
949+
exit ${HAS_TEST_FAILURE}
950+
else
951+
echo -e "${GREEN}SUCCESS: E2E Tests Passed${NC}"
952+
exit 0
953+
fi

porch/hack/verify-fix-all.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,27 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
set -e
17+
set -o nounset -o errexit -o pipefail
18+
19+
GREEN='\033[0;32m'
20+
RED='\033[0;31m'
21+
NC='\033[0m' # No Color
1822

1923
REPO_ROOT="$(git rev-parse --show-toplevel)"
2024

2125
make -C "${REPO_ROOT}/porch" fix-all
2226

2327
changes=$(git status --porcelain || true)
2428
if [ -n "${changes}" ]; then
25-
echo "ERROR: some files changed, please run 'make -C porch fix-all'"
26-
echo "changed files:"
29+
echo
30+
echo -e "${RED}ERROR: required changes detected, please run 'make -C porch fix-all'${NC}"
31+
echo
32+
echo -e "${RED}FILE CHANGES:${NC}"
2733
printf "%s" "${changes}\n"
28-
echo "git diff:"
34+
echo
35+
echo -e "${RED}GIT DIFF:${NC}"
2936
git --no-pager diff
3037
exit 1
38+
else
39+
echo -e "${GREEN}SUCCESS: No changes required${NC}"
3140
fi

0 commit comments

Comments
 (0)