-
Notifications
You must be signed in to change notification settings - Fork 6
306 lines (251 loc) · 10.3 KB
/
ci.yml
File metadata and controls
306 lines (251 loc) · 10.3 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
name: CI
on:
push:
branches: ["main", "master", "dev"]
pull_request:
branches: ["main", "master", "dev"]
# Cancel redundant runs on the same branch/PR
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
source:
name: Prepare Source Tree
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Package source tree
run: tar --exclude='.git' -czf /tmp/source-tree.tar.gz .
- name: Upload source tree
uses: actions/upload-artifact@v4
with:
name: source-tree
path: /tmp/source-tree.tar.gz
retention-days: 1
# ── 1. Test ────────────────────────────────────────────────────────────────
test:
name: Test (Go ${{ matrix.go }})
runs-on: ubuntu-latest
needs: [source]
permissions:
id-token: write
contents: read
strategy:
matrix:
go: ["1.26"]
steps:
- name: Download source tree
uses: actions/download-artifact@v4
with:
name: source-tree
path: /tmp/source
- name: Extract source tree
run: tar -xzf /tmp/source/source-tree.tar.gz -C "$GITHUB_WORKSPACE"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
cache: true
- name: Download modules
run: go mod download
- name: Verify modules
run: go mod verify
- name: Run all tests with race detector
run: go test -race -count=1 -timeout=120s ./...
- name: Run coverage (pkg/ + internal/ only)
# cmd/ packages are integration wiring with no unit tests; excluding
# them keeps the coverage metric representative of business logic.
run: go test -race -count=1 -coverprofile=coverage.out ./pkg/... ./internal/...
- name: Check test coverage threshold (≥60%)
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | tr -d '%')
echo "Total coverage: ${COVERAGE}%"
if (( $(echo "$COVERAGE < 60" | bc -l) )); then
echo "Coverage ${COVERAGE}% is below minimum threshold of 60%"
exit 1
fi
- name: Upload coverage to GitHub summary
run: |
go tool cover -func=coverage.out >> $GITHUB_STEP_SUMMARY
- name: Upload coverage to Codecov
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: codecov/codecov-action@v4
with:
use_oidc: true
files: coverage.out
flags: unittests
fail_ci_if_error: false # don't break CI if Codecov is unreachable
- name: Skip Codecov on fork pull requests
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
run: echo "Skipping Codecov upload for fork PR because GitHub does not expose the OIDC token in this context."
- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.out
retention-days: 7
# ── 2. Lint ────────────────────────────────────────────────────────────────
lint:
name: Lint
runs-on: ubuntu-latest
needs: [source]
steps:
- name: Download source tree
uses: actions/download-artifact@v4
with:
name: source-tree
path: /tmp/source
- name: Extract source tree
run: tar -xzf /tmp/source/source-tree.tar.gz -C "$GITHUB_WORKSPACE"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.26"
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.10.1
args: --timeout=5m
# ── 3. Build ───────────────────────────────────────────────────────────────
build:
name: Build
runs-on: ubuntu-latest
needs: [source, test]
steps:
- name: Download source tree
uses: actions/download-artifact@v4
with:
name: source-tree
path: /tmp/source
- name: Extract source tree
run: tar -xzf /tmp/source/source-tree.tar.gz -C "$GITHUB_WORKSPACE"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.26"
cache: true
- name: Build CLI (tooltrust-scanner)
run: go build -v ./cmd/tooltrust-scanner/...
- name: Build MCP Server
run: go build -v ./cmd/tooltrust-mcp/...
# ── 4. ToolTrust Scanner scans itself (self-scan) ────────────────────────
self-scan:
name: ToolTrust Self-Scan
runs-on: ubuntu-latest
needs: [source, build]
steps:
- name: Download source tree
uses: actions/download-artifact@v4
with:
name: source-tree
path: /tmp/source
- name: Extract source tree
run: tar -xzf /tmp/source/source-tree.tar.gz -C "$GITHUB_WORKSPACE"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.26"
cache: true
- name: Build tooltrust-scanner binary
run: go build -o /tmp/tooltrust-scanner ./cmd/tooltrust-scanner/
- name: Run ToolTrust Scanner self-scan (testdata fixture)
run: |
/tmp/tooltrust-scanner scan \
--protocol mcp \
--input testdata/tools.json \
--output json --file /tmp/scan_report.json
cat /tmp/scan_report.json
- name: Validate --fail-on flag (must not BLOCK safe tools)
run: |
/tmp/tooltrust-scanner scan \
--protocol mcp \
--input testdata/tools.json \
--fail-on block || {
echo "::error::ToolTrust Scanner self-scan found BLOCKED tool(s) in testdata/tools.json"
exit 1
}
- name: Upload scan report
uses: actions/upload-artifact@v4
with:
name: tooltrust-scanner-scan-report
path: /tmp/scan_report.json
retention-days: 30
# ── 5. Verify install guide (go install + binary) ───────────────────────────
verify-install:
name: Verify Install Guide
runs-on: ubuntu-latest
needs: [source]
steps:
- name: Download source tree
uses: actions/download-artifact@v4
with:
name: source-tree
path: /tmp/source
- name: Extract source tree
run: tar -xzf /tmp/source/source-tree.tar.gz -C "$GITHUB_WORKSPACE"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.26"
cache: true
- name: Verify go install (README primary method)
run: |
# Use @main: v0.1.2 lacks cmd/tooltrust-scanner; main has correct structure
go install github.com/AgentSafe-AI/tooltrust-scanner/cmd/tooltrust-scanner@main
BIN="$(go env GOPATH)/bin/tooltrust-scanner"
$BIN version
$BIN scan --protocol mcp --input testdata/tools.json --output text
echo "✓ go install works"
- name: Verify pre-built binary download (requires v0.1.3+)
continue-on-error: true
run: |
OS=linux
ARCH=amd64
URL="https://github.com/AgentSafe-AI/tooltrust-scanner/releases/latest/download/tooltrust-scanner_${OS}_${ARCH}"
if curl -sfSL -o /tmp/tooltrust-scanner_bin "$URL"; then
chmod +x /tmp/tooltrust-scanner_bin
/tmp/tooltrust-scanner_bin version
/tmp/tooltrust-scanner_bin scan --protocol mcp --input testdata/tools.json --output text
echo "✓ pre-built binary works"
else
echo "::notice::Pre-built binary not found (expected until v0.1.3 release)"
fi
# ── 6. Verify Homebrew install (macOS) ──────────────────────────────────────
verify-install-homebrew:
name: Verify Install (Homebrew)
runs-on: macos-latest
needs: [source]
steps:
- name: Download source tree
uses: actions/download-artifact@v4
with:
name: source-tree
path: /tmp/source
- name: Extract source tree
run: tar -xzf /tmp/source/source-tree.tar.gz -C "$GITHUB_WORKSPACE"
- name: Install via Homebrew Formula
run: |
# Homebrew rejects direct URL install; create a local tap and install from it
brew tap-new --no-git AgentSafe-AI/tooltrust-scanner
TAP_DIR="$(brew --prefix)/Library/Taps/agentsafe-ai/homebrew-tooltrust-scanner"
mkdir -p "$TAP_DIR/Formula"
cp "$GITHUB_WORKSPACE/Formula/tooltrust-scanner.rb" "$TAP_DIR/Formula/"
# Get version from formula
VERSION=$(awk '/version "/ {print $2}' "$TAP_DIR/Formula/tooltrust-scanner.rb" | tr -d '"')
# Homebrew expects the unpacked folder to be named <formula>-<version>
TEST_DIR="/tmp/brew-test/tooltrust-scanner-${VERSION}"
mkdir -p "$TEST_DIR"
rsync -a "$GITHUB_WORKSPACE/" "$TEST_DIR/" --exclude ".git"
tar -czf /tmp/ci_source.tar.gz -C /tmp/brew-test "tooltrust-scanner-${VERSION}"
URL="file:///tmp/ci_source.tar.gz"
SHA256=$(shasum -a 256 /tmp/ci_source.tar.gz | awk '{print $1}')
sed -i '' "s|url \".*\"|url \"$URL\"|" "$TAP_DIR/Formula/tooltrust-scanner.rb"
sed -i '' "s|sha256 \".*\"|sha256 \"$SHA256\"|" "$TAP_DIR/Formula/tooltrust-scanner.rb"
brew install AgentSafe-AI/tooltrust-scanner/tooltrust-scanner
tooltrust-scanner version
tooltrust-scanner scan --protocol mcp --input testdata/tools.json --output text
echo "✓ Homebrew install works"
- name: Uninstall
if: always()
run: brew uninstall tooltrust-scanner 2>/dev/null || true