Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/main-golint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,14 @@ jobs:

- name: Check build of nexusd
run: make service

- name: Run coverage and refresh README badge
if: matrix.os == 'ubuntu-latest'
run: make coverage

- name: Report coverage drift in README badge
if: matrix.os == 'ubuntu-latest'
run: |
if ! git diff --exit-code -- README.md; then
echo "::warning::README.md coverage badge differs from committed version. Run 'make coverage' locally and commit the result if you want the badge refreshed."
fi
30 changes: 29 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SERVICE_DIR = nexusd

.PHONY: all vet test service clean install uninstall
.PHONY: all vet test service clean install uninstall test-coverage coverage-badge coverage

all: vet test service

Expand All @@ -27,6 +27,34 @@ benchmark:
go test ./test -run=XXX -bench=. -scheme=tcps
go test ./test -run=XXX -bench=. -scheme=ws -compress

# Run the full suite once with coverage instrumentation. The transport-matrix
# variants in `test` are not re-run here — they exercise transport edge cases,
# not different code paths in the router/wamp/client packages we measure.
test-coverage:
go test -race -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -func=coverage.out | tail -1 | awk '{print $$3}' > coverage.txt
@printf 'total coverage: %s\n' "$$(cat coverage.txt)"

# Rewrite the README coverage badge line to a shields.io URL with the
# current percentage and a color picked from the same thresholds shields.io
# uses for its built-in coverage badges. shields.io renders the badge on
# the fly, so no SVG file is committed. Idempotent: same percentage → no
# diff. Cross-platform sed -i (works under BSD and GNU sed).
coverage-badge: test-coverage
@PCT=$$(tr -d '%' < coverage.txt); \
COLOR=$$(awk -v p="$$PCT" 'BEGIN { \
if (p<50) print "red"; \
else if (p<70) print "orange"; \
else if (p<80) print "yellow"; \
else if (p<90) print "yellowgreen"; \
else print "brightgreen" }'); \
sed -i.bak -E "s|coverage-[0-9.]+%25-[a-z]+|coverage-$${PCT}%25-$${COLOR}|" README.md; \
rm -f README.md.bak; \
printf 'coverage badge: %s%% (%s)\n' "$$PCT" "$$COLOR"

# Top-level: tests with coverage + badge regen. Run before pushing.
coverage: coverage-badge

service: $(SERVICE_DIR)/nexusd

$(SERVICE_DIR)/nexusd:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# WAMP v2 router library, client library and router service

[![Build Status](https://travis-ci.org/gammazero/nexus.svg)](https://travis-ci.org/gammazero/nexus)
[![Main CI](https://github.com/gammazero/nexus/actions/workflows/main-golint.yml/badge.svg)](https://github.com/gammazero/nexus/actions/workflows/main-golint.yml)
[![Coverage](https://img.shields.io/badge/coverage-56.1%25-orange)](https://github.com/gammazero/nexus/actions/workflows/main-golint.yml)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![GoDoc](https://godoc.org/github.com/gammazero/nexus?status.svg)](https://godoc.org/github.com/gammazero/nexus)

Expand Down