From f0ac70401efc02c47da7510793922145cf6facf8 Mon Sep 17 00:00:00 2001
From: Anmol Sethi <hi@nhooyr.io>
Date: Sat, 20 Apr 2019 14:22:43 -0400
Subject: [PATCH] Improve local CI experience

---
 ci/bench/entrypoint.sh |  9 +++++----
 ci/run.sh              | 21 +++++++++++++++++++++
 ci/test/entrypoint.sh  |  5 ++---
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/ci/bench/entrypoint.sh b/ci/bench/entrypoint.sh
index 19edfe9..b71a5c1 100755
--- a/ci/bench/entrypoint.sh
+++ b/ci/bench/entrypoint.sh
@@ -3,12 +3,13 @@
 source ci/lib.sh || exit 1
 
 mkdir -p profs
+
 go test --vet=off --run=^$ -bench=. \
+	-cpuprofile=profs/cpu \
+	-memprofile=profs/mem \
+	-blockprofile=profs/block \
+	-mutexprofile=profs/mutex \
 	./...
-#	-cpuprofile=profs/cpu \
-#	-memprofile=profs/mem \
-#	-blockprofile=profs/block \
-#	-mutexprofile=profs/mutex \
 
 set +x
 echo "profiles are in ./profs
diff --git a/ci/run.sh b/ci/run.sh
index 66bb16a..9112c83 100755
--- a/ci/run.sh
+++ b/ci/run.sh
@@ -18,6 +18,19 @@ function docker_run() {
 		"${IMAGE}"
 }
 
+function help() {
+	set +x
+	echo
+	echo "$0 [-h] <step>"
+	cat << EOF
+
+If you do not pass in an explicit step, all steps will be ran in order.
+Pass "analyze" as the step to be put into an interactive container to analyze
+profiles.
+EOF
+	exit 1
+}
+
 # Use this to analyze benchmark profiles.
 if [[ ${1-} == "analyze" ]]; then
 	docker run \
@@ -29,7 +42,15 @@ if [[ ${1-} == "analyze" ]]; then
 		golang:1.12
 fi
 
+if [[ ${1-} == "-h" || ${1-} == "--help" || ${1-} == "help" ]]; then
+	help
+fi
+
 if [[ $# -gt 0 ]]; then
+	if [[ ! -d "ci/$*" ]]; then
+		help
+	fi
+
 	docker_run "ci/$*"
 	exit 0
 fi
diff --git a/ci/test/entrypoint.sh b/ci/test/entrypoint.sh
index 6cb11b0..d076fe0 100755
--- a/ci/test/entrypoint.sh
+++ b/ci/test/entrypoint.sh
@@ -16,10 +16,9 @@ go tool cover -func=profs/coverage
 if [[ $CI ]]; then
 	bash <(curl -s https://codecov.io/bash) -f profs/coverage
 else
-	go tool cover -html=profs/coverage -o=coverage.html
+	go tool cover -html=profs/coverage -o=profs/coverage.html
 
 	set +x
 	echo
-	echo "please open coverage.html to see detailed test coverage stats"
-	echo "profiles are in ./prof/"
+	echo "please open profs/coverage.html to see detailed test coverage stats"
 fi
-- 
GitLab