diff --git a/.travis.yml b/.travis.yml index 6be8b9b77..c76c36f9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,8 @@ before_script: - helm lint helm/botkube script: - - make container-image + - make unit-test + - make after_success: - if [[ "$TRAVIS_BRANCH" == "develop" ]] && [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then diff --git a/Makefile b/Makefile index 06579edf9..4d30aa7e4 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,12 @@ IMAGE_REPO=infracloud/botkube TAG=$(shell cut -d'=' -f2- .release) .DEFAULT_GOAL := build -.PHONY: release git-tag check-git-status build container-image pre-build tag-image publish +.PHONY: release git-tag check-git-status build container-image pre-build tag-image publish unit-test system-check #Docker Tasks #Make a release -release: check-git-status container-image tag-image publish git-tag - @echo "Successfully released version $(TAG)" +release: check-git-status unit-test container-image tag-image publish git-tag + @echo "Successfully releeased version $(TAG)" #Create a git tag git-tag: @@ -25,24 +25,38 @@ check-git-status: @if [ -z "$(shell git remote -v)" ] ; then echo 'ERROR: No remote to push tags to' && exit 1 ; fi @if [ -z "$(shell git config user.email)" ] ; then echo 'ERROR: Unable to detect git credentials' && exit 1 ; fi +# unit-test +unit-test: system-check + @echo "Starting unit tests" + @./hack/unit-test.sh -v + #Build the binary build: pre-build @cd cmd/botkube;GOOS_VAL=$(shell go env GOOS) GOARCH_VAL=$(shell go env GOARCH) go build -o $(shell go env GOPATH)/bin/botkube #Build the image -container-image: pre-build +container-image: pre-build @echo "Building docker image" @docker build --build-arg GOOS_VAL=$(shell go env GOOS) --build-arg GOARCH_VAL=$(shell go env GOARCH) -t $(IMAGE_REPO) -f build/Dockerfile --no-cache . @echo "Docker image build successfully" -#Pre-build checks -pre-build: +#system checks +system-check: @echo "Checking system information" - @if [ -z "$(shell go env GOOS)" ] || [ -z "$(shell go env GOARCH)" ] ; then echo 'ERROR: Could not determine the system architecture.' && exit 1 ; fi + @if [ -z "$(shell go env GOOS)" ] || [ -z "$(shell go env GOARCH)" ] ; \ + then \ + echo 'ERROR: Could not determine the system architecture.' && exit 1 ; \ + else \ + echo 'GOOS: $(shell go env GOOS)' ; \ + echo 'GOARCH: $(shell go env GOARCH)' ; \ + echo 'System information checks passed.'; \ + fi ; +#Pre-build checks +pre-build: system-check #Tag images -tag-image: +tag-image: @echo 'Tagging image' @docker tag $(IMAGE_REPO) $(IMAGE_REPO):$(TAG) @@ -51,4 +65,4 @@ publish: @echo "Pushing docker image to repository" @docker login @docker push $(IMAGE_REPO):$(TAG) - @docker push $(IMAGE_REPO):latest + @docker push $(IMAGE_REPO):latest diff --git a/hack/unit-test.sh b/hack/unit-test.sh new file mode 100755 index 000000000..3146a95a9 --- /dev/null +++ b/hack/unit-test.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +PACKAGES=$(go list ./... | grep -v '/vendor/') + +for package in $PACKAGES; do + go test ${@} "$package" +done