mottaquikarim/esquerydsl

View on GitHub
Makefile

Summary

Maintainability
Test Coverage
# Definitions
ROOT                    := $(PWD)
GO_HTML_COV             := ./coverage.html
GO_TEST_OUTFILE         := ./c.out
GOLANG_DOCKER_IMAGE     := golang:1.15
GOLANG_DOCKER_CONTAINER := goesquerydsl-container
CC_TEST_REPORTER_ID        := ${CC_TEST_REPORTER_ID}
CC_PREFIX                := github.com/mottaquikarim/esquerydsl

#   Format according to gofmt: https://github.com/cytopia/docker-gofmt
#   Usage:
#       make fmt
#       make fmt path=src/elastic/index_setup.go
fmt:
ifdef path
    docker run --rm -v ${ROOT}:/data cytopia/gofmt -s -w ${path}
else
    docker run --rm -v ${ROOT}:/data cytopia/gofmt -s -w .
endif

#   Deletes container if exists
#   Usage:
#       make clean
clean:
    docker rm -f ${GOLANG_DOCKER_CONTAINER} || true

#   Usage:
#       make test
test:
    docker run -w /app -v ${ROOT}:/app ${GOLANG_DOCKER_IMAGE} go test ./... -coverprofile=${GO_TEST_OUTFILE}
    docker run -w /app -v ${ROOT}:/app ${GOLANG_DOCKER_IMAGE} go tool cover -html=${GO_TEST_OUTFILE} -o ${GO_HTML_COV}

# custom logic for code climate, gross but necessary
_before-cc:
    # download CC test reported
    docker run -w /app -v ${ROOT}:/app ${GOLANG_DOCKER_IMAGE} \
        /bin/bash -c \
        "curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter"
    
    # update perms
    docker run -w /app -v ${ROOT}:/app ${GOLANG_DOCKER_IMAGE} chmod +x ./cc-test-reporter

    # run before build
    docker run -w /app -v ${ROOT}:/app \
         -e CC_TEST_REPORTER_ID=${CC_TEST_REPORTER_ID} \
        ${GOLANG_DOCKER_IMAGE} ./cc-test-reporter before-build

_after-cc:
    # handle custom prefix
    $(eval PREFIX=${CC_PREFIX})
ifdef prefix
    $(eval PREFIX=${prefix})
endif
    # upload data to CC
    docker run -w /app -v ${ROOT}:/app \
        -e CC_TEST_REPORTER_ID=${CC_TEST_REPORTER_ID} \
        ${GOLANG_DOCKER_IMAGE} ./cc-test-reporter after-build --prefix ${PREFIX}

# this runs tests with cc reporting built in
test-ci: _before-cc test _after-cc

#   Usage:
#       make lint
lint:
    docker run --rm -v ${ROOT}:/data cytopia/golint .