inetmock/Taskfile.yml

189 lines
4.8 KiB
YAML

version: "3"
vars:
OUT_DIR: ./out
INETMOCK_PKG: gitlab.com/inetmock/inetmock/cmd/inetmock
IMCTL_PKG: gitlab.com/inetmock/inetmock/cmd/imctl
DOCKER_ENDPOINT:
sh: echo "${DOCKER_ENDPOINT:-localhost}"
env:
GOOS: linux
GOARCH: amd64
CGO_ENABLED: 0
tasks:
default:
desc: By default run tests and build all binaries
cmds:
- task: test
- task: build
clean:
desc: clean all generated files
cmds:
- find . -type f \( -name "*.pb.go" -or -name "*.mock.go" -or -name "*_enum.go" \) -exec rm -f {} \;
- rm -rf ./main {{ .OUT_DIR }}
format:
desc: Format all changed source files
cmds:
- goimports -local gitlab.com/inetmock/inetmock -w $(go list -f \{\{.Dir\}\} ./... | grep -v /vendor/)
- gofumpt -l -w ./
dep-graph:
desc: generate dependency graph
sources:
- go.mod
- go.sum
cmds:
- mkdir -p {{ .OUT_DIR }}
- gomod graph "**" | dot -Gdpi=0 -T svg -o {{ .OUT_DIR }}/dependency_graph.svg
golangci-lint:
desc: run Go linter
deps:
- format
cmds:
- golangci-lint run --timeout 5m
protobuf-lint:
desc: run protobuf linter
sources:
- "api/proto/**/*.proto"
cmds:
- buf lint
lint:
desc: run all linters
deps:
- golangci-lint
- protobuf-lint
protoc:
desc: generate Go files from protobuf files
deps:
- protobuf-lint
sources:
- "api/proto/**/*.proto"
generates:
- "**/*.pb.go"
cmds:
- buf generate
go-generate:
desc: run all go:generate directives
sources:
- "**/*.go"
generates:
- "**/*.mock.go"
cmds:
- go generate -x ./...
generate:
desc: run all code generation steps
deps:
- go-generate
- protoc
cmds:
- task: format
test:
desc: run short running unit tests that do not need sudo
sources:
- "**/*.go"
env:
CGO_ENABLED: 1
cmds:
- mkdir -p {{ .OUT_DIR }}
- go test -race -shuffle=on -coverprofile={{ .OUT_DIR }}/cov-raw.out -covermode atomic ./...
- grep -Ev "gitlab.com/inetmock/inetmock/pkg/logging" {{ .OUT_DIR }}/cov-raw.out > {{ .OUT_DIR }}/cov.out
- go tool cover -func={{ .OUT_DIR }}/cov.out
test-all:
desc: run all unit tests
sources:
- "**/*.go"
env:
CGO_ENABLED: 1
cmds:
- mkdir -p {{ .OUT_DIR }}
- gotestsum --junitfile={{ .OUT_DIR }}/report.xml -- --tags sudo -race -shuffle=on -coverprofile={{ .OUT_DIR }}/cov-raw.out -covermode atomic ./...
- grep -Ev "gitlab.com/inetmock/inetmock/pkg/logging|_enum.go" {{ .OUT_DIR }}/cov-raw.out > {{ .OUT_DIR }}/cov.out
- gocover-cobertura < {{ .OUT_DIR }}/cov.out > {{ .OUT_DIR }}/coverage.xml
- rm -f {{ .OUT_DIR }}/cov-raw.out
integration-test:
desc: run all benchmarks/integration tests
cmds:
- cat testdata/integration.imcs | go run ./cmd/imctl check run --insecure --target {{ .DOCKER_ENDPOINT }} --log-level debug
debug-integration-test:
desc: run all benchmarks/integration tests
deps:
- generate
cmds:
- cat testdata/integration.imcs | dlv debug --headless --listen=:2345 --api-version=2 --accept-multiclient ./cmd/imctl -- check run --insecure --target {{ .DOCKER_ENDPOINT }} --log-level debug
cli-cover-report:
desc: generate a coverage report on the CLI
deps:
- test-all
cmds:
- go tool cover -func={{ .OUT_DIR }}/cov.out
html-cover-report:
desc: generate a coverage report as HTML page
deps:
- test-all
cmds:
- go tool cover -html={{ .OUT_DIR }}/cov.out -o {{ .OUT_DIR }}/coverage.html
build-inetmock:
desc: build the INetMock server part
cmds:
- task: build
vars:
TARGET_ID: inetmock
debug-inetmock:
desc: run INetMock server with delve for remote debugging
cmds:
- dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient --output {{ .OUT_DIR }}/__debug_bin debug {{ .INETMOCK_PKG }} -- serve
build-imctl:
desc: build the imctl INetMock client CLI
cmds:
- task: build
vars:
TARGET_ID: imctl
build:
desc: build all binaries
deps:
- generate
vars:
TARGET_ID: '{{ default "" .TARGET_ID }}'
cmds:
- goreleaser build --single-target --skip-validate --rm-dist {{ if .TARGET_ID }}--id {{ .TARGET_ID }}{{end}}
- mkdir -p {{ .OUT_DIR }}
- cp ./dist/*_linux_amd64/* {{ .OUT_DIR }}
snapshot-release:
desc: create a snapshot/test release without publishing any artifacts
deps:
- generate
cmds:
- goreleaser release --snapshot --skip-publish --rm-dist
release:
desc: create a release - includes artifact publishing
deps:
- generate
cmds:
- goreleaser release --rm-dist
docs:
desc: generate docs
cmds:
- mdbook build -d ./../public ./docs