From 2106658442286c392638e495f0cad480e41146e4 Mon Sep 17 00:00:00 2001 From: eleith Date: Thu, 24 Jul 2025 14:18:38 +0000 Subject: [PATCH] refactor(coverage): centralize test coverage logic - Excluded packages are now hardcoded in list-packages.sh. - check-coverage.sh now uses list-packages.sh. - The Makefile now calls check-coverage.sh. This unifies the test coverage process for local and CI environments. --- Makefile | 7 +++---- scripts/check-coverage.sh | 8 ++++++-- scripts/list-packages.sh | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100755 scripts/list-packages.sh diff --git a/Makefile b/Makefile index deabbbc..11f0d55 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ build: - go build -mod=vendor -o miniflux-digest . + go build -mod=vendor -o miniflux-digest ./cmd/miniflux-digest preview-html: go run -mod=vendor ./scripts/preview-html/main.go @@ -9,11 +9,10 @@ preview-miniflux-email: go run -mod=vendor ./scripts/preview-miniflux-email/main.go test: - go test -mod=vendor ./... + go test -mod=vendor ./... ./cmd/miniflux-digest test-coverage: - go test -mod=vendor -coverprofile=coverage.out ./... - @go tool cover -func=coverage.out + ./scripts/check-coverage.sh 60 lint: golangci-lint run diff --git a/scripts/check-coverage.sh b/scripts/check-coverage.sh index be4a812..b62ff1a 100755 --- a/scripts/check-coverage.sh +++ b/scripts/check-coverage.sh @@ -9,7 +9,11 @@ fi COVERAGE_THRESHOLD=$1 -go test -mod=vendor -coverprofile=coverage.out ./... +EXCLUDED_PACKAGES="miniflux-digest/internal/testutil miniflux-digest/scripts" + +COVERAGE_PACKAGES=$(./scripts/list-packages.sh $EXCLUDED_PACKAGES) + +go test -mod=vendor -coverprofile=coverage.out -coverpkg=$COVERAGE_PACKAGES ./... ./cmd/miniflux-digest COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//') @@ -25,4 +29,4 @@ if awk -v cov="$COVERAGE" -v min="$COVERAGE_THRESHOLD" 'BEGIN {exit (cov < min)} else echo "Error: Test coverage is below the ${COVERAGE_THRESHOLD}% threshold." exit 1 -fi \ No newline at end of file +fi diff --git a/scripts/list-packages.sh b/scripts/list-packages.sh new file mode 100755 index 0000000..19d3f53 --- /dev/null +++ b/scripts/list-packages.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# This script generates a comma-separated list of Go packages to include in coverage. +# It excludes packages matching patterns provided as arguments. + +EXCLUDE_PATTERNS="" + +# Add any additional exclusion patterns from arguments +for arg in "$@"; do + EXCLUDE_PATTERNS="${EXCLUDE_PATTERNS} ${arg}" +done + +PACKAGE_LIST=$(go list ./...) + +for pattern in ${EXCLUDE_PATTERNS}; do + PACKAGE_LIST=$(echo "${PACKAGE_LIST}" | grep -v "${pattern}") +done + +echo "${PACKAGE_LIST}" | paste -sd, - \ No newline at end of file -- 2.54.0