Skip to content

Instantly share code, notes, and snippets.

@030
Forked from sbp-bvanb/TaskfileCommon.yml
Last active May 12, 2024 13:52
Show Gist options
  • Save 030/0a4a5ff7940229d3734d43f3046d1f96 to your computer and use it in GitHub Desktop.
Save 030/0a4a5ff7940229d3734d43f3046d1f96 to your computer and use it in GitHub Desktop.
#
# do not make any modifications to this file as this resides on github gist
#
# https://taskfile.dev
#
# go install github.com/go-task/task/v3/cmd/[email protected]
# ~/go/bin/task --list-all
#
# 0.2.1
#
---
version: 3
vars:
TASK_COVERAGE_DIR: build/coverage
TASK_GCI_VERSION: 0.13.4
TASK_GOLANGCI_LINT_VERSION: 1.58.1
TASK_SWAG_VERSION: v1.16.2
TASK_VEKTRA_MOCKERY_VERSION: v2.42.0
tasks:
#
# build
#
build:
# deps: tasks that will be run in parallel
deps:
- task: build-golang
- task: build-docker
desc: builds both a docker image and golang library
build-docker:
# cmd: steps that will be run sequentially
cmds:
- |
docker build --no-cache -t {{.TASK_PROJECT_NAME}}:{{.TASK_PROJECT_VERSION}} .
desc: builds a docker image
build-golang:
cmds:
- task: build-golang-download-modules
- |
go build -C cmd/{{.TASK_PROJECT_NAME}}
desc: builds a golang binary
build-golang-download-modules:
cmds:
- |
go mod tidy
desc: download go modules
#
# coverage
#
coverage:
cmds:
- |
mkdir -p {{.TASK_COVERAGE_DIR}}
go test -coverprofile={{.TASK_COVERAGE_DIR}}/coverage.cov ./... -cover -race -p=4 -v --tags=integration
go tool cover -func={{.TASK_COVERAGE_DIR}}/coverage.cov > {{.TASK_COVERAGE_DIR}}/functioncoverage.out
go tool cover -html={{.TASK_COVERAGE_DIR}}/coverage.cov -o {{.TASK_COVERAGE_DIR}}/coverage.html
open ./{{.TASK_COVERAGE_DIR}}/coverage.html
#
# docker
#
docker-run:
cmds:
- task: build-docker
- |
docker run \
--rm \
{{.DOCKER_RUN_EXTRA_PARAMETERS}} \
-d \
--name {{.TASK_PROJECT_NAME}} {{.TASK_PROJECT_NAME}}:{{.TASK_PROJECT_VERSION}}
sleep 3
docker ps
echo "Issue: 'docker logs {{.TASK_PROJECT_NAME}} -f' to inspect the logging"
docker-stop:
cmds:
- |
docker stop {{.TASK_PROJECT_NAME}}
#
# formatting
#
gci:
cmds:
- |
if ! ~/go/bin/gci --version | grep "gci version {{.TASK_GCI_VERSION}}"; then
go install github.com/daixiang0/gci@v{{.TASK_GCI_VERSION}}
fi
~/go/bin/gci write --skip-generated -s standard -s default .
golangci-lint:
cmds:
- |
if ! golangci-lint --version | grep "has version {{.TASK_GOLANGCI_LINT_VERSION}}"; then
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v{{.TASK_GOLANGCI_LINT_VERSION}}
fi
golangci-lint run -v --timeout 2m30s --config .golangci.yml
#
# mocks
#
mock-generate:
cmds:
- |
if ! ~/go/bin/mockery --version | grep "{{.TASK_VEKTRA_MOCKERY_VERSION}}"; then
go install github.com/vektra/mockery/v2@{{.TASK_VEKTRA_MOCKERY_VERSION}}
fi
echo "{{.MOCK_GENERATE_DIR}} {{.MOCK_GENERATE_INTERFACE_NAME}}"
~/go/bin/mockery --dir {{.MOCK_GENERATE_DIR}} --name {{.MOCK_GENERATE_INTERFACE_NAME}} --output {{.MOCK_GENERATE_DIR}}/mocks
prefix: 'print-{{.TEXT}}'
#
# test
#
test-integration:
cmds:
- |
go test ./... -v --tags=integration
test-unit:
cmds:
- |
go test ./... -v
#
# swagger
#
swagger:
cmds:
- |
if ! ~/go/bin/swag --version | grep "swag version {{.TASK_SWAG_VERSION}}"; then
go install github.com/swaggo/swag/cmd/swag@{{.TASK_SWAG_VERSION}}
fi
~/go/bin/swag init -g cmd/{{.TASK_PROJECT_NAME}}/main.go --parseDependency
~/go/bin/swag fmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment