forked from modelcontextprotocol/rust-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
437 lines (355 loc) · 13 KB
/
Copy pathci.yml
File metadata and controls
437 lines (355 loc) · 13 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
name: CI
on:
push:
branches: [ main, release ]
tags:
- 'release-*'
pull_request:
branches: [ main, release ]
env:
CARGO_TERM_COLOR: always
ARTIFACT_DIR: release-artifacts
jobs:
commit-lint:
name: Lint Commit Messages
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: '22'
- name: Install commitlint
run: |
npm install --save-dev @commitlint/cli @commitlint/config-conventional
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
- name: Lint commit messages
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
fmt:
name: Code Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install Rust fmt
run: rustup toolchain install nightly --component rustfmt
- name: Check formatting
run: cargo +nightly fmt --all -- --check
clippy:
name: Lint with Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
semver:
name: SemVer Check
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install cargo-semver-checks
uses: taiki-e/install-action@v2
with:
tool: cargo-semver-checks
- name: Determine semver release type
run: |
if git log --format=%B \
${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} \
| grep -Eq '(^[A-Za-z0-9_-]+(\([^)]*\))?!:|^BREAKING[ -]CHANGE:)'; then
echo "SEMVER_RELEASE_TYPE=major" >> "$GITHUB_ENV"
else
echo "SEMVER_RELEASE_TYPE=minor" >> "$GITHUB_ENV"
fi
- name: Check rmcp (default features)
run: |
cargo semver-checks \
--package rmcp \
--baseline-rev ${{ github.event.pull_request.base.sha }} \
--release-type "$SEMVER_RELEASE_TYPE" \
--only-explicit-features \
--features default
- name: Check rmcp (all features except local)
run: |
FEATURES=$(cargo metadata --no-deps --format-version 1 \
| jq -r '[.packages[] | select(.name == "rmcp") | .features | keys[]
| select(startswith("__") | not)
| select(. != "local")] | join(",")')
cargo semver-checks \
--package rmcp \
--baseline-rev ${{ github.event.pull_request.base.sha }} \
--release-type "$SEMVER_RELEASE_TYPE" \
--only-explicit-features \
--features "$FEATURES"
public-api:
name: Public API Check
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
# cargo-public-api builds rustdoc JSON, which requires a nightly toolchain
# to be installed (it does not need to be the default; the tool invokes it
# via `cargo +nightly`).
- name: Install Rust
uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
- name: Install cargo-public-api
uses: taiki-e/install-action@v2
with:
tool: cargo-public-api
# Mirror the SemVer Check job's release-type detection: a breaking-change
# commit marker (`!:` or `BREAKING CHANGE:`) means a major release (any API
# change is allowed); otherwise a minor release (additions allowed, but
# changed/removed public items are denied). This catches breaking changes
# that cargo-semver-checks cannot yet detect, such as a change to a
# function's return type or a field's type.
# See https://github.com/obi1kenobi/cargo-semver-checks/issues/5
- name: Determine release type and deny flags
run: |
if git log --format=%B \
${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} \
| grep -Eq '(^[A-Za-z0-9_-]+(\([^)]*\))?!:|^BREAKING[ -]CHANGE:)'; then
SEMVER_RELEASE_TYPE=major
else
SEMVER_RELEASE_TYPE=minor
fi
case "$SEMVER_RELEASE_TYPE" in
major) DENY="" ;;
patch) DENY="--deny added --deny changed --deny removed" ;;
*) DENY="--deny changed --deny removed" ;;
esac
echo "SEMVER_RELEASE_TYPE=$SEMVER_RELEASE_TYPE" >> "$GITHUB_ENV"
echo "DENY=$DENY" >> "$GITHUB_ENV"
- name: Check rmcp (default features)
run: |
cargo public-api \
--package rmcp \
-ss \
diff \
$DENY \
--force \
${{ github.event.pull_request.base.sha }}..${{ github.sha }}
- name: Check rmcp (all features except local)
run: |
BASE_SHA=${{ github.event.pull_request.base.sha }}
# `cargo public-api diff` builds both revisions with the same feature
# set, so a feature that exists on only one side (e.g. a feature added
# or removed by this PR) would fail to build the other revision. Diff
# only the features present in BOTH the base and the head; features
# unique to one side are necessarily pure additions/removals, which the
# release-type deny flags already govern.
list_features() {
cargo metadata --no-deps --format-version 1 --manifest-path "$1/Cargo.toml" \
| jq -r '.packages[] | select(.name == "rmcp") | .features | keys[]
| select(startswith("__") | not)
| select(. != "local")'
}
list_features "." | sort -u > "$RUNNER_TEMP/head_features"
git worktree add --detach "$RUNNER_TEMP/rmcp-base" "$BASE_SHA"
list_features "$RUNNER_TEMP/rmcp-base" | sort -u > "$RUNNER_TEMP/base_features"
git worktree remove --force "$RUNNER_TEMP/rmcp-base"
FEATURES=$(comm -12 "$RUNNER_TEMP/head_features" "$RUNNER_TEMP/base_features" | paste -sd, -)
cargo public-api \
--package rmcp \
--features "$FEATURES" \
-ss \
diff \
$DENY \
--force \
"$BASE_SHA"..${{ github.sha }}
spelling:
name: spell check with typos
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Spell Check Repo
uses: crate-ci/typos@master
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# install nodejs
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: '22'
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Set up Python
run: uv python install
- name: Create venv for python
run: uv venv
- uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo test --all-features
test-no-local:
name: Run Tests (no local feature)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# install nodejs
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: '22'
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Set up Python
run: uv python install
- name: Create venv for python
run: uv venv
- uses: Swatinem/rust-cache@v2
- name: Run tests without local feature
run: |
FEATURES=$(cargo metadata --no-deps --format-version 1 \
| jq -r '[.packages[] | select(.name == "rmcp") | .features | keys[]
| select(startswith("__") | not)
| select(. != "local")] | join(",")')
cargo test -p rmcp --features "$FEATURES"
coverage:
name: Code Coverage
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
# install nodejs
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: '22'
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Set up Python
run: uv python install
- name: Create venv for python
run: uv venv
- uses: Swatinem/rust-cache@v2
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
- name: Install llvm-tools-preview
run: rustup component add llvm-tools-preview
- name: Run tests with coverage
run: cargo llvm-cov --all-features
example-test:
name: Example test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# install nodejs
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: '22'
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Set up Python
run: uv python install
- name: Create venv for python
run: uv venv
- uses: Swatinem/rust-cache@v2
- name: Add target WASI preview 2
run: |
rustup target add wasm32-wasip2
- name: Build examples
run: |
for dir in examples/*/ ; do
if [ -f "$dir/Cargo.toml" ]; then
echo "Building $dir"
if [[ "$dir" == *"wasi"* ]]; then
cargo build --manifest-path "$dir/Cargo.toml" --target wasm32-wasip2
else
cargo build --manifest-path "$dir/Cargo.toml" --all-features --tests
fi
fi
done
- name: Run tests in examples
run: |
# Tests are run for each subdirectory in the example directory.
for dir in examples/*/ ; do
if [ -f "$dir/Cargo.toml" ]; then
if [[ "$dir" != *"wasi"* ]]; then
echo "Testing $dir"
cargo test --manifest-path "$dir/Cargo.toml" --all-features --all-targets
fi
fi
done
security_audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Run cargo-audit
run: cargo audit
doc:
name: Generate Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install Rust
uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
- name: Generate documentation
run: |
cargo +nightly doc --no-deps -p rmcp -p rmcp-macros --all-features
env:
RUSTDOCFLAGS: --cfg docsrs -Dwarnings
release:
name: Release crates
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/release' || startsWith(github.ref, 'refs/tags/release')
needs: [fmt, clippy, test]
steps:
# Since this job has access to the `CRATES_TOKEN`, it's probably a good
# idea to be extra careful about what Actions are being called. The reason
# is that if an attacker gains access to other actions such as
# `Swatinem/rust-cache`, they could use that to steal the `CRATES_TOKEN`.
# This happened recently in the attack on `tj-actions/changed-files`, but
# has happened many times before as well.
- uses: actions/checkout@v7
- name: Update Rust
run: |
rustup update stable
rustup default stable
- name: Cargo login
run: cargo login ${{ secrets.CRATES_TOKEN }}
- name: Publish macros dry run
run: cargo publish -p rmcp-macros --dry-run
continue-on-error: true
- name: Publish rmcp dry run
run: cargo publish -p rmcp --dry-run
continue-on-error: true
- name: Publish macro
if: ${{ startsWith(github.ref, 'refs/tags/release') }}
continue-on-error: true
run: cargo publish -p rmcp-macros
- name: Publish rmcp
if: ${{ startsWith(github.ref, 'refs/tags/release') }}
continue-on-error: true
run: cargo publish -p rmcp