From b8287e979167a96fe9fa9b20078495995d433944 Mon Sep 17 00:00:00 2001 From: "Carlos L. Torres" Date: Fri, 13 Jan 2017 00:46:13 -0600 Subject: [PATCH 1/2] pre-commit hook --- Makefile | 16 +++ README.md | 13 ++- dashboard/.editorconfig | 1 + hooks/pre-commit | 102 ++++++++++++++++++ .../cmd/perfq-apiserver/apiserver.go | 17 +++ 5 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 Makefile create mode 100755 hooks/pre-commit create mode 100644 perf-query-api/cmd/perfq-apiserver/apiserver.go diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c67d460 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +MAKEFLAGS += -s + +SHELL := /bin/bash + +presubmit: dashboard-lint api + +dashboard-lint: + cd dashboard/ && node_modules/tslint/bin/tslint "src/**/*.ts" --project src/tsconfig.json --type-check + cd dashboard/ && node_modules/tslint/bin/tslint "e2e/**/*.ts" --project e2e/tsconfig.json --type-check + +api: + cd perf-query-api/ && go install ./cmd/... && go vet ./cmd/... && cd ../ + go build ./perf-query-api/cmd/... + +clean: + rm ./perfq-apiserver diff --git a/README.md b/README.md index 6043953..451ecd4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ -# rpc-perf-dash -RPC Performance Dashboard + +# RPC Performance Dashboard + +## Introduction + + +## Getting Started + + +## Contribute + diff --git a/dashboard/.editorconfig b/dashboard/.editorconfig index 6e87a00..5c50917 100644 --- a/dashboard/.editorconfig +++ b/dashboard/.editorconfig @@ -5,6 +5,7 @@ root = true charset = utf-8 indent_style = space indent_size = 2 +end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 0000000..bf9153f --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,102 @@ +#!/bin/bash + +readonly reset=$(tput sgr0) +readonly red=$(tput bold; tput setaf 1) +readonly green=$(tput bold; tput setaf 2) + +exit_code=0 + +PROJECT_ROOT=$(dirname "${BASH_SOURCE}")/../.. +cd "${PROJECT_ROOT}" + + +echo -ne "Checking for files that need gofmt..." +files_need_gofmt=() +files=($(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "^perf-query-api/vendor")) +for file in "${files[@]}"; do + diff="$(git show ":${file}" | gofmt -s -d 2>&1)" + if [[ -n "$diff" ]]; then + files_need_gofmt+=("${file}") + fi +done + +if [[ "${#files_need_gofmt[@]}" -ne 0 ]]; then + echo "${red}ERROR!" + echo "Some files have not been gofmt'd. To fix these errors, " + echo "copy and paste the following:" + echo " gofmt -s -w ${files_need_gofmt[@]}" + exit_code=1 +else + echo "${green}OK" +fi +echo "${reset}" + +echo -ne "Checking files for golint errors..." +golint_errors=() +for d in $(go list -e ./perf-query-api/cmd/... | egrep -v '/(vendor)' | sed -e "s|^_${PROJECT_ROOT}/\?||"); do + out="$(golint "$d" 2>&1)" + if [[ -n "$out" ]]; then + golint_errors+=("$out") + fi +done + +if [[ "${#golint_errors[@]}" -ne 0 ]]; then + echo "${red}ERROR!" + for err in "${golint_errors[@]}"; do + echo "$err" + done + echo + echo 'Some files have golint errors. Please fix and commit again.' + echo + exit_code=1 +else + echo "${green}OK" +fi +echo "${reset}" + +echo -ne "Checking perf-query-api compiles..." +if ! OUT=$(make api 2>&1); then + echo + echo "${red}${OUT}" + exit_code=1 +else + echo "${green}OK" +fi +echo "${reset}" + +echo -ne "Checking dashboard for tslint errors..." +if ! OUT=$(make dashboard-lint 2>&1); then + echo + echo "${red}${OUT}" + exit_code=1 +else + echo "${green}OK" +fi +echo "${reset}" + +echo -ne "Checking for tsfmt errors..." +files_with_tsfmt_errors=() +files=($(git diff --cached --name-only --diff-filter ACM | grep "\.ts" | grep -v -e "^dashboard/node_modules")) +for file in "${files[@]}"; do + OUT="$(tsfmt --baseDir dashboard --verify "${file}" 2>&1)" + if [[ -n "$OUT" ]]; then + files_with_tsfmt_errors+=("${file}") + fi +done + +if [[ "${#files_with_tsfmt_errors[@]}" -ne 0 ]]; then + echo "${red}ERROR!" + echo "Some files have not been tsfmt'd. To fix these errors, " + echo "copy and paste the following:" + echo " tsfmt --baseDir dashboard -r ${files_with_tsfmt_errors[@]}" + exit_code=1 +else + echo "${green}OK" +fi +echo "${reset}" + + +if [[ "${exit_code}" != 0 ]]; then + echo "${red}Aborting commit${reset}" +fi +exit ${exit_code} diff --git a/perf-query-api/cmd/perfq-apiserver/apiserver.go b/perf-query-api/cmd/perfq-apiserver/apiserver.go new file mode 100644 index 0000000..87321db --- /dev/null +++ b/perf-query-api/cmd/perfq-apiserver/apiserver.go @@ -0,0 +1,17 @@ +// perfqapi is the api server for querying the performance results +package main + +import ( + "fmt" + "net/http" +) + +func main() { + fmt.Printf("Starting perfqapi server...") + http.HandleFunc("/", handler) + http.ListenAndServe(":8000", nil) +} + +func handler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "It works!") +} From f39ac3fc1483678ecf5e7bae6fae16998bc14196 Mon Sep 17 00:00:00 2001 From: "Carlos L. Torres" Date: Fri, 13 Jan 2017 15:37:53 -0600 Subject: [PATCH 2/2] Move pre-hook tslint check to script --- Makefile | 6 ------ hooks/pre-commit | 10 ++++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c67d460..363a318 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,6 @@ MAKEFLAGS += -s SHELL := /bin/bash -presubmit: dashboard-lint api - -dashboard-lint: - cd dashboard/ && node_modules/tslint/bin/tslint "src/**/*.ts" --project src/tsconfig.json --type-check - cd dashboard/ && node_modules/tslint/bin/tslint "e2e/**/*.ts" --project e2e/tsconfig.json --type-check - api: cd perf-query-api/ && go install ./cmd/... && go vet ./cmd/... && cd ../ go build ./perf-query-api/cmd/... diff --git a/hooks/pre-commit b/hooks/pre-commit index bf9153f..f78f5a1 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -65,15 +65,21 @@ fi echo "${reset}" echo -ne "Checking dashboard for tslint errors..." -if ! OUT=$(make dashboard-lint 2>&1); then +TSLINT_BIN=dashboard/node_modules/tslint/bin/tslint +tslint_out=$("$TSLINT_BIN" "dashboard/src/**/*.ts" \ + --project dashboard/src/tsconfig.json \ + --type-check 2>&1) + +if [[ -n "$tslint_out" ]]; then echo - echo "${red}${OUT}" + echo "${red}${tslint_out}" exit_code=1 else echo "${green}OK" fi echo "${reset}" + echo -ne "Checking for tsfmt errors..." files_with_tsfmt_errors=() files=($(git diff --cached --name-only --diff-filter ACM | grep "\.ts" | grep -v -e "^dashboard/node_modules"))