forked from unbound-force/replicator
-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (89 loc) · 3.28 KB
/
Copy pathci.yml
File metadata and controls
107 lines (89 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# CI
# --
# Continuous integration pipeline. Runs on push to main and
# pull requests. Validates code quality (vet, govulncheck),
# runs tests with race detection, enforces per-package
# coverage ratchets, and verifies the binary builds.
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
- name: Vet
run: go vet ./...
- name: Govulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@3e6f44f962742443c11ae2261f02e0c917aeb2bc # v1.5.0
govulncheck ./...
- name: Test Homebrew cask integrity patching
run: .github/scripts/patch-homebrew-cask_test.sh
- name: Test
run: go test ./... -count=1 -race -coverprofile=coverage.out
- name: Enforce Coverage Ratchets
run: |
# Guard: coverage profile must exist and be non-empty
if [ ! -s coverage.out ]; then
echo "::error::No coverage profile found — cannot enforce ratchets"
exit 1
fi
FAILED=0
# --- Global coverage floor ---
GLOBAL_COV=$(go tool cover -func=coverage.out | grep '^total:' | awk '{print substr($3, 1, length($3)-1)}')
if [ -z "$GLOBAL_COV" ]; then
echo "::error::Could not parse global coverage from coverage.out"
exit 1
fi
echo "Global coverage: ${GLOBAL_COV}%"
if (( $(echo "$GLOBAL_COV < 55.0" | bc -l) )); then
echo "::error::Global coverage ${GLOBAL_COV}% is below the 55% threshold."
exit 1
fi
# --- Per-package coverage ratchets ---
declare -A THRESHOLDS=(
["internal/memory"]=85
["internal/query"]=80
["internal/doctor"]=80
["internal/forge"]=80
["internal/stats"]=80
["internal/comms"]=80
["internal/org"]=80
["internal/agentkit"]=80
["internal/gitutil"]=80
["internal/ui"]=75
["internal/mcp"]=70
["internal/mcpclient"]=80
)
for PKG in "${!THRESHOLDS[@]}"; do
THRESHOLD=${THRESHOLDS[$PKG]}
PKG_COV=$(go tool cover -func=coverage.out \
| grep "github.com/unbound-force/replicator/${PKG}" \
| awk '{print substr($3, 1, length($3)-1)}' \
| awk '{t+=$1; c++} END {if(c>0) printf "%.1f", t/c; else print "0.0"}')
if (( $(echo "$PKG_COV < $THRESHOLD" | bc -l) )); then
echo "::error::${PKG} coverage ${PKG_COV}% is below the ${THRESHOLD}% threshold."
FAILED=1
else
echo "${PKG}: ${PKG_COV}% >= ${THRESHOLD}% ✓"
fi
done
if [ "$FAILED" -eq 1 ]; then
exit 1
fi
echo "All coverage ratchets passed."
- name: Build
run: go build -o bin/replicator ./cmd/replicator