Skip to content

Commit

Permalink
Move the before-commit.sh -> hack/ci/run-tests.sh, add Travis CI support
Browse files Browse the repository at this point in the history
- remove also the `dep ensure -v --vendor-only`, go lint and go vet from before-commit script
  • Loading branch information
mszostok committed Nov 1, 2019
1 parent b2b0d86 commit 71c2c61
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 2,385 deletions.
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: go
go: "1.13"

# Skip the install step. Don't `go get` dependencies. Only build with the code in vendor/
install: skip

env:
- GO111MODULE=off
- RUN_ON_CI=true

jobs:
include:
- stage: "Before commit checks"
name: tests
before_script:
# Download the binary to bin folder in $GOPATH
- curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o $GOPATH/bin/dep
# Make the binary executable
- chmod +x $GOPATH/bin/dep
script: ./hack/ci/run-tests.sh
12 changes: 0 additions & 12 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
required = [
"github.com/golang/lint/golint",
"golang.org/x/tools/cmd/goimports",
]

Expand Down
86 changes: 22 additions & 64 deletions before-commit.sh → hack/ci/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#!/usr/bin/env bash

readonly ROOT_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# standard bash error handling
set -o nounset # treat unset variables as an error and exit immediately.
set -o errexit # exit immediately when a command fails.
set -E # needs to be set if we want the ERR trap

# Currently we are using the newest go (1.13) but project is still not switched to go modules
export GO111MODULE=off

readonly CURRENT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
readonly ROOT_PATH=${CURRENT_DIR}/../..

source "${CURRENT_DIR}/utilities.sh" || { echo 'Cannot load CI utilities.'; exit 1; }

pushd ${ROOT_PATH} > /dev/null

Expand All @@ -11,39 +22,32 @@ function _trap_exit () {
}
trap _trap_exit EXIT

readonly CI_FLAG=ci
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly INVERTED='\033[7m'
readonly NC='\033[0m' # No Color

echo -e "${INVERTED}"
echo "USER: " + ${USER}
echo "PATH: " + ${PATH}
echo "GOPATH:" + ${GOPATH}
echo -e "${NC}"


##
# DEP ENSURE
# DEP STATUS
##
dep ensure -v --vendor-only
ensureResult=$?
if [[ ${ensureResult} != 0 ]]; then
echo -e "${RED}✗ dep ensure -v --vendor-only${NC}\n$ensureResult${NC}"
shout "? dep status"
depResult=$(dep status -v)
if [[ $? != 0 ]]; then
echo -e "${RED}✗ dep status\n$depResult${NC}"
exit 1
else echo -e "${GREEN}√ dep ensure -v --vendor-only${NC}"
else echo -e "${GREEN}√ dep status${NC}"
fi

##
# GO BUILD
##
buildEnv=""
if [[ "$1" == "$CI_FLAG" ]]; then
if [[ "${RUN_ON_CI:-x}" == "true" ]]; then
# build binary statically
buildEnv="env CGO_ENABLED=0"
fi
echo "? go build"
shout "? go build"
${buildEnv} go build -o codeowners-validator ./main.go
goBuildResult=$?
if [[ ${goBuildResult} != 0 ]]; then
Expand All @@ -52,21 +56,10 @@ if [[ ${goBuildResult} != 0 ]]; then
else echo -e "${GREEN}√ go build ${NC}"
fi

##
# DEP STATUS
##
echo "? dep status"
depResult=$(dep status -v)
if [[ $? != 0 ]]; then
echo -e "${RED}✗ dep status\n$depResult${NC}"
exit 1
else echo -e "${GREEN}√ dep status${NC}"
fi

##
# GO TEST
##
echo "? go test"
shout "? go test"
go test ./...
# Check if tests passed
if [[ $? != 0 ]]; then
Expand All @@ -77,26 +70,6 @@ fi

goFilesToCheck=$(find . -type f -name "*.go" | egrep -v "\/vendor\/|_*/automock/|_*/testdata/|/pkg\/|_*export_test.go")

##
# GO LINT
##
#go build -o golint-vendored ./vendor/github.com/golang/lint/golint
#buildLintResult=$?
#if [[ ${buildLintResult} != 0 ]]; then
# echo -e "${RED}✗ go build lint${NC}\n$buildLintResult${NC}"
# exit 1
#fi
#
#echo "? golint"
#golintResult=$(echo "${goFilesToCheck}" | xargs -L1 ./golint-vendored)
#rm golint-vendored
#
#if [[ $(echo ${#golintResult}) != 0 ]]; then
# echo -e "${RED}✗ golint\n$golintResult${NC}"
# exit 1
#else echo -e "${GREEN}√ golint${NC}"
#fi

##
# GO IMPORTS & FMT
##
Expand All @@ -107,7 +80,7 @@ if [[ ${buildGoImportResult} != 0 ]]; then
exit 1
fi

echo "? goimports"
shout "? goimports"
goImportsResult=$(echo "${goFilesToCheck}" | xargs -L1 ./goimports-vendored -w -l)
rm goimports-vendored

Expand All @@ -116,18 +89,3 @@ if [[ $(echo ${#goImportsResult}) != 0 ]]; then
exit 1
else echo -e "${GREEN}√ goimports and fmt ${NC}"
fi

##
# GO VET
##

echo "? go build vet"
packagesToVet=("./internal/..." "./pkg/...")
for vPackage in "${packagesToVet[@]}"; do
vetResult=$(go vet ${vPackage})
if [[ $(echo ${#vetResult}) != 0 ]]; then
echo -e "${RED}✗ go vet ${vPackage} ${NC}\n$vetResult${NC}"
exit 1
else echo -e "${GREEN}√ go vet ${vPackage} ${NC}"
fi
done
20 changes: 20 additions & 0 deletions hack/ci/utilities.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Library of useful utilities for CI purposes.
#

readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly INVERTED='\033[7m'
readonly NC='\033[0m' # No Color

readonly LIB_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

# Prints first argument as header. Additionally prints current date.
shout() {
echo -e "
#################################################################################################
# $(date)
# $1
#################################################################################################
"
}
18 changes: 0 additions & 18 deletions vendor/github.com/golang/lint/.travis.yml

This file was deleted.

15 changes: 0 additions & 15 deletions vendor/github.com/golang/lint/CONTRIBUTING.md

This file was deleted.

27 changes: 0 additions & 27 deletions vendor/github.com/golang/lint/LICENSE

This file was deleted.

82 changes: 0 additions & 82 deletions vendor/github.com/golang/lint/README.md

This file was deleted.

Loading

0 comments on commit 71c2c61

Please sign in to comment.