Skip to content

Commit

Permalink
Add git-hook.sh script, pre-commit and message templates
Browse files Browse the repository at this point in the history
  • Loading branch information
iver authored and owulveryck committed Oct 25, 2019
1 parent 156857d commit 54fa56a
Show file tree
Hide file tree
Showing 7 changed files with 389 additions and 315 deletions.
15 changes: 15 additions & 0 deletions .gitmessage
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Hey there o/!
#
# Please use the following guidelines to format all your commit
# messages:
#
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

# Thank you <3

# NOTE: The coverage report is generated automatically, please check
# the `make coverage` task if you wish to know more about it.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go:
- 1.13.x

before_install:
- go get -t -v ./...
- make install

script:
- ./go.test.sh
- ./scripts/go.test.sh
- make coverage

after_success:
Expand Down
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
PROJECT_PATH := $(shell pwd)
GOFILES := $(wildcard *.go)
TESTFILES := $(wildcard *test.go)
get ?= ./...
ONNX_COVERAGE ?= /tmp/report.md
TEST_LOCATION ?= backend/x/gorgonnx
COVER_TARGET ?= ${TEST_LOCATION}

export PROJECT_PATH

help:
@echo "\t\t\tONNX MAKE TASKS\n"
@echo "\tinstall\t\t Get all dependencies (go get ./..)\n"
@echo "\tgo get\t\t Run go get with the -get- variable as param (get=./.. by default)"
@echo "\tgo-get\t\t Run go get with the -get- variable as param (get=./.. by default)"
@echo "\t\t\t Example: make install get=github.com/foo/bar\n"
@echo "\tdoc\t\t Execute embedmd command with (-w README.md) as parameter\n"
@echo "\tcoverage\t Create a coverage report in the -COVER_TARGET- location. You can change it with COVER_TARGET variable."
@echo "\t\t\t Example: make coverage COVER_TARGET=/tmp/report.md"

## install: Install missing dependencies.
## Runs `go get` internally. e.g;
install: go-get
## install: Install missing dependencies.
## Runs `go get` internally. e.g;
install:
@./scripts/git-hooks.sh

go-get:
@echo " > Checking if there is any missing dependencies..."
@go get -v ${get}
@go get -t -v ${get}

doc:
doc:
@go get -v github.com/campoy/embedmd
$(GOPATH)/bin/embedmd ${TESTFILES}
@$(GOPATH)/bin/embedmd -w README.md
@$(GOPATH)/bin/embedmd -w README.md

coverage:
@cd ${TEST_LOCATION} && \
Expand Down
612 changes: 306 additions & 306 deletions backend/x/gorgonnx/ONNX_COVERAGE.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions scripts/git-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh
set -o errexit
set -o nounset

git config commit.template .gitmessage

cp "${PROJECT_PATH}/scripts/pre-commit" "${PROJECT_PATH}/.git/hooks/"
File renamed without changes.
48 changes: 48 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/sh

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi

# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --bool hooks.allownonascii)

# Redirect output to stderr.
exec 1>&2

# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test $(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
Error: Attempt to add a non-ASCII file name.
This can cause problems if you want to work with people on other platforms.
To be portable it is advisable to rename the file.
If you know what you are doing you can disable this check using:
git config hooks.allownonascii true
EOF
exit 1
fi

PROJECT_PATH="$(pwd)"
echo "[ONNX-GO] Building coverage report ..."
make -f ${PROJECT_PATH}/Makefile coverage
echo "[ONNX-GO] Done!"
git add ${PROJECT_PATH}/backend/x/gorgonnx/ONNX_COVERAGE.md

# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached $against --

0 comments on commit 54fa56a

Please sign in to comment.