-
Notifications
You must be signed in to change notification settings - Fork 1
197 lines (181 loc) · 8.88 KB
/
ci.yml
File metadata and controls
197 lines (181 loc) · 8.88 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: CI
on:
push:
branches: [main, master]
pull_request:
branches: [main]
permissions:
contents: read
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.10
args: --timeout=5m
test:
name: Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run tests with race detector
shell: bash
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Check coverage on critical packages
continue-on-error: true
if: matrix.os == 'ubuntu-latest'
run: |
# Extract coverage for critical packages and enforce 80% threshold
CRITICAL_PKGS=(
"github.com/Sentinel-Gate/Sentinelgate/internal/adapter/outbound/state"
"github.com/Sentinel-Gate/Sentinelgate/internal/domain/proxy"
"github.com/Sentinel-Gate/Sentinelgate/internal/service"
"github.com/Sentinel-Gate/Sentinelgate/internal/adapter/inbound/admin"
"github.com/Sentinel-Gate/Sentinelgate/internal/adapter/outbound/cel"
)
FAIL=0
for pkg in "${CRITICAL_PKGS[@]}"; do
COV=$(go tool cover -func=coverage.out | grep "^${pkg}/" | tail -1 | awk '{print $NF}' | tr -d '%')
if [ -z "$COV" ]; then
echo "WARNING: No coverage data for $pkg"
continue
fi
echo "$pkg: ${COV}%"
COV_INT=${COV%.*}
if [ "$COV_INT" -lt 50 ]; then
echo "FAIL: $pkg coverage ${COV}% is below 50% threshold"
FAIL=1
fi
done
echo ""
echo "Overall coverage:"
go tool cover -func=coverage.out | tail -1
if [ "$FAIL" -eq 1 ]; then
echo "::error::Coverage below 50% on one or more critical packages"
exit 1
fi
- name: Upload coverage report
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.out
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
go build -ldflags="-s -w" -o sentinel-gate-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/sentinel-gate
- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: sentinel-gate-${{ matrix.goos }}-${{ matrix.goarch }}
path: sentinel-gate-${{ matrix.goos }}-${{ matrix.goarch }}
smoke:
name: Smoke Test
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y jq
- name: Run smoke tests
continue-on-error: true
run: bash scripts/smoke.sh
security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # gitleaks needs full history
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
# Dependency vulnerability scanning
- name: Install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest
- name: govulncheck — dependency CVEs
run: govulncheck ./...
# SAST — security bugs in Go code
- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest
- name: gosec — Go security analysis
run: gosec -exclude-generated -exclude=G115,G118,G124,G204,G301,G304,G703 -severity medium ./...
# Secret scanning — leaked credentials in git history
- name: gitleaks — secret detection
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
fuzz:
name: Fuzz Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Fuzz MCP message parser (30s)
run: go test -fuzz=FuzzDecodeMessage -fuzztime=30s -timeout=90s ./pkg/mcp/
- name: Fuzz JSON-RPC validation (30s)
run: go test -fuzz=FuzzMessageValidator -fuzztime=30s -timeout=90s ./internal/domain/validation/
docker-build:
name: Docker Build (${{ matrix.name }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: main
dockerfile: Dockerfile
- name: demo
dockerfile: examples/docker-demo/Dockerfile.demo
- name: claude-code
dockerfile: examples/claude-code/Dockerfile.sentinel
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Build image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.dockerfile }}
push: false
tags: sentinel-gate:ci-${{ matrix.name }}