From e4022442c3be062c1eb40b883df6c131f07f4833 Mon Sep 17 00:00:00 2001 From: Mathis Engelbart Date: Fri, 28 Aug 2026 17:32:25 +0200 Subject: [PATCH] Add Makefile and add coverage check to CI --- .github/workflows/go.yml | 9 ++++++++ .gitignore | 4 +++- Makefile | 44 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 Makefile diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6940968..b6627de 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -35,3 +35,12 @@ jobs: run: go build -v ./... - name: Test run: go test -v -race ./... + - name: Coverage + if: matrix.go == '1.27.x' + run: make cover-check + - name: Upload coverage profile + if: matrix.go == '1.27.x' + uses: actions/upload-artifact@v4 + with: + name: coverage + path: cover.lib.out diff --git a/.gitignore b/.gitignore index 02cbdae..0229618 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ *.h264 .idea/ examples/playfromdisk/playfromdisk -examples/savetodisk/savetodisk \ No newline at end of file +examples/savetodisk/savetodisk +cover.out +cover.lib.out diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dfadb42 --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +COVERPROFILE ?= cover.out +COVERPROFILE_LIB ?= cover.lib.out +COVER_THRESHOLD ?= 90 + +.PHONY: all build test lint fmt vet coverprofile cover cover-html cover-check clean + +all: build test lint + +build: + go build ./... + +test: + go test -race ./... + +lint: + golangci-lint run + +fmt: + go fmt ./... + +vet: + go vet ./... + +# Run the full test suite with coverage. -coverpkg=./... is required so that the +# integrationtests package is credited with the library code it exercises. The +# examples are main packages with no tests so they are stripped from the profile +# the reports are built from. +coverprofile: + go test -covermode=atomic -coverpkg=./... -coverprofile=$(COVERPROFILE) ./... + grep -v '/examples/' $(COVERPROFILE) > $(COVERPROFILE_LIB) + +cover: coverprofile + @go tool cover -func=$(COVERPROFILE_LIB) + +cover-html: coverprofile + go tool cover -html=$(COVERPROFILE_LIB) + +cover-check: coverprofile + @total=$$(go tool cover -func=$(COVERPROFILE_LIB) | awk '/^total:/ {print $$NF}' | tr -d '%'); \ + echo "total coverage: $$total% (threshold: $(COVER_THRESHOLD)%)"; \ + awk -v t="$$total" -v min=$(COVER_THRESHOLD) 'BEGIN { if (t+0 < min+0) { printf "coverage %s%% is below threshold %s%%\n", t, min; exit 1 } }' + +clean: + rm -f $(COVERPROFILE) $(COVERPROFILE_LIB)