Taskfile.yml
---
version: '2'
vars:
CMD_LIST_PACKAGES: go list ./... | grep -v /vendor/
GOOS:
sh: uname | tr '[:upper:]' '[:lower:]'
VERSION_DEP: "v0.5.0"
tasks:
build:
cmds:
- go mod download
deps: [require-dep]
# Usage without prompt: `BINARY_PATH=path-to-bin task compile`
compile:
deps: [build]
cmds:
- if [ -z ${BINARY_PATH+x} ]; then
echo "Where to compile?" &&
read COMPILE_PATH &&
echo "Going to compile to ${COMPILE_PATH}" &&
export BINARY_PATH=${COMPILE_PATH};
fi;
go build -a -ldflags "-s -w -extldflags '-static'" -o ${BINARY_PATH}-{{ .GOOS }}
sources:
- "**/*.go"
generates:
- ${BINARY_PATH}
format:
desc: "Format go files with `go fmt`"
cmds:
- go fmt $({{ .CMD_LIST_PACKAGES }})
# Quick tests such as fmt and vet
lint:
cmds:
- go mod verify
- if [ ! -z $(gofmt -e -l **/*.go) ]; then
echo "Files with formatting errors:";
gofmt -e -l **/*.go;
exit 1;
fi
- go vet $({{ .CMD_LIST_PACKAGES }})
# - # Using $CMD_LIST_PACKAGES here breaks yaml
# go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
deps: [build, require-golint]
qa:
cmds:
- docker run
--interactive --tty --rm
--env CODECLIMATE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
--volume /tmp/cc:/tmp/cc
codeclimate/codeclimate analyze
require-cobra:
cmds:
- go get -u github.com/spf13/cobra/cobra
status:
- test -f "$(command -v cobra)"
require-dep:
cmds:
- curl https://raw.githubusercontent.com/golang/dep/{{ .VERSION_DEP }}/install.sh | sh
status:
- test -f "$(command -v dep)"
require-golint:
cmds:
- go get -u golang.org/x/lint/golint
status:
- test -f "$(command -v cobra)"
test:
desc: "Test application"
cmds:
- go test -race -coverprofile=c.out $({{ .CMD_LIST_PACKAGES }})
deps: [lint]