Last active
June 4, 2024 07:20
-
-
Save sbp-bvanb/a5622dd986aff11af47a96918b7c960b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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.3 | |
# | |
# disable yamllint check as it is managed in another location | |
# yamllint disable-file | |
--- | |
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 | |
# disable yamllint | |
sed -i '' '1s/^/\# yamllint disable-file\n/' docs/swagger.yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment