-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: validate, tests, build and more
- Loading branch information
Showing
10 changed files
with
257 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ -z "${VALIDATE_UPSTREAM:-}" ]; then | ||
# this is kind of an expensive check, so let's not do this twice if we | ||
# are running more than one validate bundlescript | ||
|
||
VALIDATE_REPO='https://github.com/ldez/gcg.git' | ||
VALIDATE_BRANCH='master' | ||
|
||
VALIDATE_HEAD="$(git rev-parse --verify HEAD)" | ||
|
||
git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH" | ||
VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)" | ||
|
||
VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD" | ||
VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD" | ||
|
||
validate_diff() { | ||
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then | ||
git diff "$VALIDATE_COMMIT_DIFF" "$@" | ||
fi | ||
} | ||
validate_log() { | ||
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then | ||
git log "$VALIDATE_COMMIT_LOG" "$@" | ||
fi | ||
} | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# List of bundles to create when no argument is passed | ||
DEFAULT_BUNDLES=( | ||
validate-gofmt | ||
validate-govet | ||
validate-golint | ||
|
||
test-unit | ||
) | ||
|
||
bundle() { | ||
local bundle="$1"; shift | ||
echo "---> Making bundle: $(basename "$bundle") (in $DEST)" | ||
source ".script/$bundle" "$@" | ||
} | ||
|
||
if [ $# -lt 1 ]; then | ||
bundles=(${DEFAULT_BUNDLES[@]}) | ||
else | ||
bundles=($@) | ||
fi | ||
for bundle in ${bundles[@]}; do | ||
export DEST=. | ||
ABS_DEST="$(cd "$DEST" && pwd -P)" | ||
bundle "$bundle" | ||
echo | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
RED=$'\033[31m' | ||
GREEN=$'\033[32m' | ||
TEXTRESET=$'\033[0m' # reset the foreground colour | ||
|
||
# This helper function walks the current directory looking for directories | ||
# holding certain files ($1 parameter), and prints their paths on standard | ||
# output, one per line. | ||
find_dirs() { | ||
find . -not \( \ | ||
\( \ | ||
-path './.glide/*' \ | ||
-o -path './vendor/*' \ | ||
-o -path './.git/*' \ | ||
\) \ | ||
-prune \ | ||
\) -name "$1" -print0 | xargs -0n1 dirname | sort -u | ||
} | ||
|
||
TESTFLAGS="-cover -coverprofile=cover.out ${TESTFLAGS}" | ||
|
||
if [ -n "$VERBOSE" ]; then | ||
TESTFLAGS="${TESTFLAGS} -v" | ||
fi | ||
|
||
if [ -z "$TESTDIRS" ]; then | ||
TESTDIRS=$(find_dirs '*_test.go') | ||
fi | ||
|
||
TESTS_FAILED=() | ||
|
||
for dir in $TESTDIRS; do | ||
echo '+ go test' $TESTFLAGS "${dir}" | ||
go test ${TESTFLAGS} ${dir} | ||
if [ $? != 0 ]; then | ||
TESTS_FAILED+=("$dir") | ||
echo | ||
echo "${RED}Tests failed: $dir${TEXTRESET}" | ||
sleep 1 # give it a second, so observers watching can take note | ||
fi | ||
done | ||
echo | ||
|
||
# if some tests fail, we want the bundlescript to fail, but we want to | ||
# try running ALL the tests first, hence TESTS_FAILED | ||
if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then | ||
echo "${RED}Test failures in: ${TESTS_FAILED[@]}${TEXTRESET}" | ||
echo | ||
false | ||
else | ||
echo "${GREEN}Test success${TEXTRESET}" | ||
echo | ||
true | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
source "$(dirname "$BASH_SOURCE")/.validate" | ||
|
||
if grep -q "$(glide-hash)" glide.lock; then | ||
echo 'Congratulations! glide.lock is unchanged.' | ||
else | ||
{ | ||
echo "Error: glide.lock has been manually changed. Don't do this. Use script/glide.sh up instead." | ||
echo | ||
} >&2 | ||
false | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
source "$(dirname "$BASH_SOURCE")/.validate" | ||
|
||
IFS=$'\n' | ||
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^\(integration/\)\?vendor/' || true) ) | ||
unset IFS | ||
|
||
badFiles=() | ||
for f in "${files[@]}"; do | ||
# we use "git show" here to validate that what's committed is formatted | ||
if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then | ||
badFiles+=( "$f" ) | ||
fi | ||
done | ||
|
||
if [ ${#badFiles[@]} -eq 0 ]; then | ||
echo 'Congratulations! All Go source files are properly formatted.' | ||
else | ||
{ | ||
echo "These files are not properly gofmt'd:" | ||
for f in "${badFiles[@]}"; do | ||
echo " - $f" | ||
done | ||
echo | ||
echo 'Please reformat the above files using "gofmt -s -w" and commit the result.' | ||
echo | ||
} >&2 | ||
false | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
source "$(dirname "$BASH_SOURCE")/.validate" | ||
|
||
IFS=$'\n' | ||
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^\(integration/\)\?vendor/\|autogen' || true) ) | ||
unset IFS | ||
|
||
errors=() | ||
for f in "${files[@]}"; do | ||
# we use "git show" here to validate that what's committed passes go vet | ||
failedLint=$(golint "$f") | ||
if [ "$failedLint" ]; then | ||
errors+=( "$failedLint" ) | ||
fi | ||
done | ||
|
||
if [ ${#errors[@]} -eq 0 ]; then | ||
echo 'Congratulations! All Go source files have been linted.' | ||
else | ||
{ | ||
echo "Errors from golint:" | ||
for err in "${errors[@]}"; do | ||
echo "$err" | ||
done | ||
echo | ||
echo 'Please fix the above errors. You can test via "golint" and commit the result.' | ||
echo | ||
} >&2 | ||
false | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
source "$(dirname "$BASH_SOURCE")/.validate" | ||
|
||
IFS=$'\n' | ||
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^\(integration/\)\?vendor/' || true) ) | ||
unset IFS | ||
|
||
errors=() | ||
for f in "${files[@]}"; do | ||
# we use "git show" here to validate that what's committed passes go vet | ||
failedVet=$(go tool vet -printf=false "$f") | ||
if [ "$failedVet" ]; then | ||
errors+=( "$failedVet" ) | ||
fi | ||
done | ||
|
||
if [ ${#errors[@]} -eq 0 ]; then | ||
echo 'Congratulations! All Go source files have been vetted.' | ||
else | ||
{ | ||
echo "Errors from govet:" | ||
for err in "${errors[@]}"; do | ||
echo "$err" | ||
done | ||
echo | ||
echo 'Please fix the above errors. You can test via "go vet" and commit the result.' | ||
echo | ||
} >&2 | ||
false | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
source "$(dirname "$BASH_SOURCE")/.validate" | ||
|
||
IFS=$'\n' | ||
src=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^\(integration/\)\?vendor/\|autogen' || true) ) | ||
docs=( $(validate_diff --diff-filter=ACMR --name-only -- 'docs/*.md') ) | ||
unset IFS | ||
files=("${src[@]}" "${docs[@]}") | ||
|
||
errors=() | ||
for f in "${files[@]}"; do | ||
# we use source text here so we also check spelling of variable names | ||
failedSpell=$(misspell -source=text "$f") | ||
if [ "$failedSpell" ]; then | ||
errors+=( "$failedSpell" ) | ||
fi | ||
done | ||
|
||
if [ ${#errors[@]} -eq 0 ]; then | ||
echo 'Congratulations! All Go source files and docs have been checked for common misspellings.' | ||
else | ||
{ | ||
echo "Errors from misspell:" | ||
for err in "${errors[@]}"; do | ||
echo "$err" | ||
done | ||
echo | ||
echo 'Please fix the above errors. You can test via "misspell" and commit the result.' | ||
echo | ||
} >&2 | ||
false | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
.PHONY: all | ||
|
||
default: test-unit binary | ||
default: test-unit validate build | ||
|
||
dependencies: | ||
glide install | ||
|
||
binary: | ||
build: | ||
go build | ||
|
||
validate: | ||
./.script/make.sh validate-glide validate-gofmt validate-govet validate-golint validate-misspell | ||
|
||
test-unit: | ||
go test -v -cover -coverprofile=cover.out "github.com/ldez/gcg" &&\ | ||
go test -v -cover -coverprofile=cover.out "github.com/ldez/gcg/core" &&\ | ||
go test -v -cover -coverprofile=cover.out "github.com/ldez/gcg/label" | ||
./.script/make.sh test-unit |