--- # https://taskfile.dev version: "3" vars: COVERAGE_FILE: "{{.OUT_DIR}}/coverage.out" INTERNAL: "./internal/..." API: "./api/..." PKG: "./pkg/..." CMD: "./cmd/..." # yamllint disable-line rule:line-length EXCLUDED_FILES: ".gen.go|internal/serviceconfig/observability/prometheus/generator/main.go" includes: docker: dir: "{{.CONTEXT}}" taskfile: docker.yml internal: true tasks: mocks:generate: run: once cmds: - rm -rf mocks/* - go tool mockery unit:cmd: internal: true vars: SKIP_GENERATE: false cmds: - task: mocks:generate - mkdir -p {{.OUT_DIR}} - go test {{.INTERNAL}} {{.API}} {{.CLI_ARGS}} unit:short: cmds: - task: unit:cmd vars: CLI_ARGS: -short SKIP_GENERATE: true unit:aws: cmds: - | find ./internal -name "*.aws_test.go" -exec dirname {} \; | sort -u \ | xargs go test -short -tags aws unit: vars: TMP_FILE: "{{.OUT_DIR}}/coverage.tmp" FILTER_COVERAGE_FILE: "{{.OUT_DIR}}/filtered_coverage.out" cmds: - task: unit:cmd vars: CLI_ARGS: | -coverpkg={{.INTERNAL}},{{.API}} \ -coverprofile={{.COVERAGE_FILE}} - | grep -v -E "{{.EXCLUDED_FILES}}" {{.COVERAGE_FILE}} \ > {{.FILTER_COVERAGE_FILE}} - go tool cover -func={{.FILTER_COVERAGE_FILE}} > {{.TMP_FILE}} - | COVERAGE=$(grep total: {{.TMP_FILE}} \ | awk '{print $3}' | sed 's/%//' | bc) echo "Coverage Threshold: {{.COVERAGE_THRESHOLD}}%" echo "Total Coverage: $COVERAGE%" if (( $(echo "$COVERAGE < {{.COVERAGE_THRESHOLD}}" | bc -l) )); then echo "❌ Error: Total Coverage below Coverage Threshold" FAIL=true fi echo "Function Coverage Threshold: {{.FUNCTION_COVERAGE_THRESHOLD}}%" FAIL_FUNC=false grep -v total: {{.TMP_FILE}} | while read -r line; do FUNC_COV=$(echo "$line" | awk '{print $3}' | sed 's/%//' | bc) if (( $(echo "$FUNC_COV < \ {{.FUNCTION_COVERAGE_THRESHOLD}}" | bc -l) )); then if [ "$FAIL_FUNC" = false ]; then echo "❌ Error: The following functions have coverage below "\ "{{.FUNCTION_COVERAGE_THRESHOLD}}%:" FAIL_FUNC=true FAIL=true fi echo "$line" fi done if [ "$FAIL" = true ]; then exit 1 fi echo "✅ All coverage checks passed!" silent: true endtoend: deps: - docker:build cmds: - go test -count=1 -v ./test/...