Skip to content

test: add unit tests for column-aware tag matcher parsing and SQL ren… #111

test: add unit tests for column-aware tag matcher parsing and SQL ren…

test: add unit tests for column-aware tag matcher parsing and SQL ren… #111

Workflow file for this run

name: Coverage
on:
workflow_dispatch: {}
push:
branches: [ main ]
permissions:
contents: read
jobs:
coverage:
name: Run coverage and generate badge
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: '1.25'
- name: Run tests and collect coverage
run: |
set -eux
# Produce a unified coverage profile across packages
go test -coverpkg=./... ./... -coverprofile=coverage.out || true
# Some shells / platforms may produce a file named 'coverage' without extension.
if [ -f coverage ] && [ ! -f coverage.out ]; then
mv coverage coverage.out || true
fi
if [ -f coverage.out ]; then
# Exclude test utility packages from coverage metrics (not part of product surface).
# Keep the first 'mode:' line, filter out entries for internal/testutil, then regenerate coverage report.
head -n1 coverage.out > coverage.filtered.out || true
# Remove coverage entries for test helpers and testdata directories
tail -n +2 coverage.out | grep -v -E '(^github.com/toeirei/keymaster/internal/testutil|testdata)' >> coverage.filtered.out || true
mv coverage.filtered.out coverage.out || true
go tool cover -func=coverage.out > coverage.txt || true
else
echo "no coverage file produced" > coverage.txt
fi
- name: Generate SVG badge
run: |
set -eux
percent=$(awk '/total:/ {print $3}' coverage.txt | sed 's/%//') || true
if [ -z "$percent" ]; then percent=0; fi
width=$(awk -v p="$percent" 'BEGIN{printf("%d", 200*p/100)}')
cat > coverage.svg <<'EOF'
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20">
<rect width="200" height="20" fill="#555"/>
<rect width="WIDTH" height="20" x="0" y="0" fill="#4c1"/>
<text x="100" y="14" font-family="Verdana" font-size="11" fill="#fff" text-anchor="middle">coverage PERCENT%</text>
</svg>
EOF
sed -i "s/WIDTH/${width}/g" coverage.svg
sed -i "s/PERCENT/${percent}/g" coverage.svg
- name: Upload coverage artifacts
uses: actions/upload-artifact@v6
with:
name: coverage
path: |
coverage.svg
coverage.txt
coverage.out