Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit hook #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MAKEFLAGS += -s

SHELL := /bin/bash

api:
cd perf-query-api/ && go install ./cmd/... && go vet ./cmd/... && cd ../
go build ./perf-query-api/cmd/...

clean:
rm ./perfq-apiserver
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# rpc-perf-dash
RPC Performance Dashboard

# RPC Performance Dashboard

## Introduction


## Getting Started


## Contribute

1 change: 1 addition & 0 deletions dashboard/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
108 changes: 108 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/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..."
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}${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"))
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}
17 changes: 17 additions & 0 deletions perf-query-api/cmd/perfq-apiserver/apiserver.go
Original file line number Diff line number Diff line change
@@ -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!")
}